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_substitution (command (command_name)))))
(command (command_name) (single_quoted_argument))) (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 Commands with numeric arguments
=============================== ===============================

View File

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

View File

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

24341
src/parser.c

File diff suppressed because it is too large Load Diff