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"
}
]
},
@ -245,16 +249,8 @@
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";;"
},
{
"type": "BLANK"
}
]
"type": "STRING",
"value": ";;"
}
]
},
@ -323,12 +319,34 @@
}
},
{
"type": "RENAME",
"content": {
"type": "SYMBOL",
"name": "leading_word"
},
"value": "command_name"
"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",
@ -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": [
@ -539,12 +577,21 @@
"value": "$"
},
{
"type": "RENAME",
"content": {
"type": "SYMBOL",
"name": "word"
},
"value": "variable_name"
"type": "CHOICE",
"members": [
{
"type": "RENAME",
"content": {
"type": "SYMBOL",
"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