Add quoted command names, subshells

This commit is contained in:
Max Brunsfeld 2017-07-14 17:32:55 -07:00
parent a0406c8906
commit 5446533c20
5 changed files with 14012 additions and 10479 deletions

View File

@ -37,6 +37,17 @@ echo 'hi'
(command_substitution (command (command_name)))))
(command (command_name) (single_quoted_argument)))
===============================
Quoted command names
===============================
"$a/$b" c
---
(program
(command (quoted_argument (expansion (variable_name)) (expansion (variable_name))) (argument)))
===============================
Commands with numeric arguments
===============================

View File

@ -84,3 +84,16 @@ esac
(command (command_name) (argument)))
(case_item (argument)
(command (command_name) (argument)))))
===============================
Subshells
===============================
(
./start-server --port=80
) &
---
(program
(subshell (command (command_name) (argument))))

View File

@ -32,7 +32,8 @@ module.exports = grammar({
$.if_statement,
$.case_statement,
$.pipeline,
$.list
$.list,
$.subshell
),
while_statement: $ => seq(
@ -83,7 +84,7 @@ module.exports = grammar({
$.value,
')',
repeat($._terminated_statement),
optional(';;')
';;'
),
bracket_command: $ => choice(
@ -96,7 +97,12 @@ module.exports = grammar({
$.environment_variable_assignment,
$.file_redirect
)),
rename($.leading_word, 'command_name'),
choice(
rename(choice($.leading_word), 'command_name'),
':',
$.quoted_argument,
$.single_quoted_argument
),
optional(seq(
/\s+/,
repeat($.value)
@ -119,6 +125,12 @@ module.exports = grammar({
$.statement
)),
subshell: $ => seq(
'(',
repeat($._terminated_statement),
')'
),
environment_variable_assignment: $ => seq(
rename($.leading_word, 'variable_name'),
'=',
@ -151,14 +163,17 @@ module.exports = grammar({
expansion: $ => seq(
'$',
rename($.word, 'variable_name')
choice(
rename($.word, 'variable_name'),
'$'
)
),
operator_expansion: $ => seq(
'${',
rename($.leading_word, 'variable_name'),
optional(seq(
choice(':', ':?', '='),
choice(':', ':?', '=', ':-'),
$.value
)),
'}'
@ -200,6 +215,6 @@ module.exports = grammar({
comment: $ => /#.*/,
terminator: $ => choice(';', ';;', '\n'),
terminator: $ => choice(';', ';;', '\n', '&'),
}
});

View File

@ -55,6 +55,10 @@
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "subshell"
}
]
},
@ -244,17 +248,9 @@
"name": "_terminated_statement"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";;"
},
{
"type": "BLANK"
}
]
}
]
},
@ -322,14 +318,36 @@
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "RENAME",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "leading_word"
}
]
},
"value": "command_name"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "quoted_argument"
},
{
"type": "SYMBOL",
"name": "single_quoted_argument"
}
]
},
{
"type": "CHOICE",
"members": [
@ -432,6 +450,26 @@
]
}
},
"subshell": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"environment_variable_assignment": {
"type": "SEQ",
"members": [
@ -538,6 +576,9 @@
"type": "STRING",
"value": "$"
},
{
"type": "CHOICE",
"members": [
{
"type": "RENAME",
"content": {
@ -545,6 +586,12 @@
"name": "word"
},
"value": "variable_name"
},
{
"type": "STRING",
"value": "$"
}
]
}
]
},
@ -583,6 +630,10 @@
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": ":-"
}
]
},
@ -764,6 +815,10 @@
{
"type": "STRING",
"value": "\n"
},
{
"type": "STRING",
"value": "&"
}
]
}

24341
src/parser.c

File diff suppressed because it is too large Load Diff