Parse for loop identifier as a variable name
Also remove some duplication in expression and concatenation
This commit is contained in:
parent
7e73a575e9
commit
8a0a4a8501
|
@ -28,7 +28,7 @@ done
|
|||
|
||||
(program
|
||||
(for_statement
|
||||
(word)
|
||||
(variable_name)
|
||||
(word)
|
||||
(word)
|
||||
(command_substitution (command (command_name (word)) (word) (word)))
|
||||
|
|
40
grammar.js
40
grammar.js
|
@ -16,6 +16,7 @@ module.exports = grammar({
|
|||
$._statement,
|
||||
$._terminator,
|
||||
$._expression,
|
||||
$._primary_expression,
|
||||
$._variable_name,
|
||||
],
|
||||
|
||||
|
@ -27,7 +28,7 @@ module.exports = grammar({
|
|||
$.file_descriptor,
|
||||
$._empty_value,
|
||||
$._concat,
|
||||
$.variable_name,
|
||||
$.variable_name, // Variable name followed by an operator like '=' or '+='
|
||||
'\n',
|
||||
],
|
||||
|
||||
|
@ -63,7 +64,7 @@ module.exports = grammar({
|
|||
|
||||
for_statement: $ => seq(
|
||||
'for',
|
||||
$.word,
|
||||
$._variable_name,
|
||||
'in',
|
||||
repeat1($._expression),
|
||||
$._terminator,
|
||||
|
@ -242,44 +243,29 @@ module.exports = grammar({
|
|||
// Expressions
|
||||
|
||||
_expression: $ => choice(
|
||||
$.concatenation,
|
||||
$._primary_expression
|
||||
),
|
||||
|
||||
_primary_expression: $ => choice(
|
||||
$.word,
|
||||
$.string,
|
||||
$.raw_string,
|
||||
$.expansion,
|
||||
$.simple_expansion,
|
||||
$.command_substitution,
|
||||
$.process_substitution,
|
||||
$.concatenation
|
||||
$.process_substitution
|
||||
),
|
||||
|
||||
concatenation: $ => prec(-1, seq(
|
||||
choice(
|
||||
$.word,
|
||||
$.string,
|
||||
$.raw_string,
|
||||
$.expansion,
|
||||
$.simple_expansion,
|
||||
$.command_substitution,
|
||||
$.process_substitution
|
||||
),
|
||||
repeat1(seq(
|
||||
$._concat,
|
||||
choice(
|
||||
$.word,
|
||||
$.string,
|
||||
$.raw_string,
|
||||
$.expansion,
|
||||
$.simple_expansion,
|
||||
$.command_substitution,
|
||||
$.process_substitution
|
||||
)
|
||||
))
|
||||
$._primary_expression,
|
||||
repeat1(seq($._concat, $._primary_expression))
|
||||
)),
|
||||
|
||||
string: $ => seq(
|
||||
'"',
|
||||
repeat(choice(
|
||||
/[^"`$]+/,
|
||||
$._string_content,
|
||||
$.expansion,
|
||||
$.simple_expansion,
|
||||
$.command_substitution
|
||||
|
@ -287,6 +273,8 @@ module.exports = grammar({
|
|||
'"'
|
||||
),
|
||||
|
||||
_string_content: $ => /[^"`$]+/,
|
||||
|
||||
array: $ => seq(
|
||||
'(',
|
||||
repeat($._expression),
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "word"
|
||||
"name": "_variable_name"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
|
@ -319,16 +319,14 @@
|
|||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "function"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "word"
|
||||
|
@ -353,6 +351,27 @@
|
|||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "word"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
|
@ -859,47 +878,17 @@
|
|||
"_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "word"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "raw_string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expansion"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "simple_expansion"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "command_substitution"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "process_substitution"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "concatenation"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_primary_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
"concatenation": {
|
||||
"type": "PREC",
|
||||
"value": -1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"_primary_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
|
@ -932,6 +921,16 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"concatenation": {
|
||||
"type": "PREC",
|
||||
"value": -1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_primary_expression"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
|
@ -941,38 +940,9 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "_concat"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "word"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "raw_string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expansion"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "simple_expansion"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "command_substitution"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "process_substitution"
|
||||
}
|
||||
]
|
||||
"name": "_primary_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -993,8 +963,8 @@
|
|||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\"`$]+"
|
||||
"type": "SYMBOL",
|
||||
"name": "_string_content"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
|
@ -1017,6 +987,10 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"_string_content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[^\"`$]+"
|
||||
},
|
||||
"array": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -1443,6 +1417,7 @@
|
|||
"_statement",
|
||||
"_terminator",
|
||||
"_expression",
|
||||
"_primary_expression",
|
||||
"_variable_name"
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue