Handle strings containing command substitutions
This commit is contained in:
parent
e9afbb4381
commit
3abfbbd7bd
|
@ -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)))
|
||||||
|
|
15
grammar.js
15
grammar.js
|
@ -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(
|
||||||
|
|
|
@ -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,6 +933,9 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"type": "PREC",
|
||||||
|
"value": 1,
|
||||||
|
"content": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
@ -917,7 +944,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "command"
|
"name": "_statement"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -925,6 +952,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"process_substitution": {
|
"process_substitution": {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue