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

64
src/grammar.json vendored
View File

@ -396,7 +396,7 @@
},
"list": {
"type": "PREC_LEFT",
"value": 0,
"value": -1,
"content": {
"type": "SEQ",
"members": [
@ -727,6 +727,10 @@
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "array"
},
{
"type": "SYMBOL",
"name": "raw_string"
@ -763,7 +767,7 @@
"members": [
{
"type": "PATTERN",
"value": "[^\"$]+"
"value": "[^\"`$]+"
},
{
"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": {
"type": "PATTERN",
"value": "'[^']*'"
@ -900,7 +924,7 @@
},
{
"type": "SYMBOL",
"name": "command"
"name": "_statement"
},
{
"type": "STRING",
@ -909,21 +933,25 @@
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "`"
},
{
"type": "SYMBOL",
"name": "command"
},
{
"type": "STRING",
"value": "`"
}
]
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "`"
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "STRING",
"value": "`"
}
]
}
}
]
},

54418
src/parser.c vendored

File diff suppressed because it is too large Load Diff