Handle strings containing command substitutions

This commit is contained in:
Max Brunsfeld 2017-07-15 22:41:56 -07:00
parent e9afbb4381
commit 3abfbbd7bd
4 changed files with 29754 additions and 24759 deletions

View File

@ -120,3 +120,19 @@ echo "a ${b} c" "d $e"
(command (command_name) (command (command_name)
(string (expansion (variable_name))) (string (expansion (variable_name)))
(string (simple_expansion (variable_name))))) (string (simple_expansion (variable_name)))))
=========================================
Strings containing command substitutions
=========================================
find "`dirname $file`" -name "$base"'*'
---
(program
(command
(command_name)
(string (command_substitution (command (command_name) (simple_expansion (variable_name)))))
(word)
(string (simple_expansion (variable_name)))
(raw_string)))

View File

@ -131,7 +131,7 @@ module.exports = grammar({
$._statement $._statement
)), )),
list: $ => prec.left(seq( list: $ => prec.left(-1, seq(
$._statement, $._statement,
choice('&&', '||'), choice('&&', '||'),
$._statement $._statement
@ -204,6 +204,7 @@ module.exports = grammar({
_expression: $ => choice( _expression: $ => choice(
$.word, $.word,
$.string, $.string,
$.array,
$.raw_string, $.raw_string,
$.expansion, $.expansion,
$.simple_expansion, $.simple_expansion,
@ -214,7 +215,7 @@ module.exports = grammar({
string: $ => seq( string: $ => seq(
'"', '"',
repeat(choice( repeat(choice(
/[^"$]+/, /[^"`$]+/,
$.expansion, $.expansion,
$.simple_expansion, $.simple_expansion,
$.command_substitution $.command_substitution
@ -222,6 +223,12 @@ module.exports = grammar({
'"' '"'
), ),
array: $ => seq(
'(',
repeat($.word),
')'
),
raw_string: $ => /'[^']*'/, raw_string: $ => /'[^']*'/,
simple_expansion: $ => seq( simple_expansion: $ => seq(
@ -248,8 +255,8 @@ module.exports = grammar({
), ),
command_substitution: $ => choice( command_substitution: $ => choice(
seq('$(', $.command, ')'), seq('$(', $._statement, ')'),
seq('`', $.command, '`') prec(1, seq('`', $._statement, '`'))
), ),
process_substitution: $ => seq( process_substitution: $ => seq(

64
src/grammar.json vendored
View File

@ -396,7 +396,7 @@
}, },
"list": { "list": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": -1,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -727,6 +727,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "string" "name": "string"
}, },
{
"type": "SYMBOL",
"name": "array"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "raw_string" "name": "raw_string"
@ -763,7 +767,7 @@
"members": [ "members": [
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "[^\"$]+" "value": "[^\"`$]+"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -786,6 +790,26 @@
} }
] ]
}, },
"array": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "word"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"raw_string": { "raw_string": {
"type": "PATTERN", "type": "PATTERN",
"value": "'[^']*'" "value": "'[^']*'"
@ -900,7 +924,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "command" "name": "_statement"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -909,21 +933,25 @@
] ]
}, },
{ {
"type": "SEQ", "type": "PREC",
"members": [ "value": 1,
{ "content": {
"type": "STRING", "type": "SEQ",
"value": "`" "members": [
}, {
{ "type": "STRING",
"type": "SYMBOL", "value": "`"
"name": "command" },
}, {
{ "type": "SYMBOL",
"type": "STRING", "name": "_statement"
"value": "`" },
} {
] "type": "STRING",
"value": "`"
}
]
}
} }
] ]
}, },

54418
src/parser.c vendored

File diff suppressed because it is too large Load Diff