Add missing array syntax

This commit is contained in:
Max Brunsfeld 2017-12-26 14:55:37 -08:00
parent 2a034b5252
commit 145d4e86a4
5 changed files with 14378 additions and 13302 deletions

View File

@ -149,6 +149,7 @@ echo ${a[@]}
echo ${#b[@]}
a[$i]=50
a+=(foo "bar" $(baz))
---
@ -159,4 +160,10 @@ a[$i]=50
(command (command_name (word)) (expansion (variable_name)))
(environment_variable_assignment
(subscript (variable_name) (simple_expansion (variable_name)))
(word)))
(word))
(environment_variable_assignment
(variable_name)
(array
(word)
(string)
(command_substitution (command (command_name (word)))))))

View File

@ -182,7 +182,10 @@ module.exports = grammar({
$.variable_name,
$.subscript
),
'=',
choice(
'=',
'+='
),
choice(
$._expression,
$.array,
@ -271,7 +274,7 @@ module.exports = grammar({
array: $ => seq(
'(',
repeat($.word),
repeat($._expression),
')'
),

15
src/grammar.json vendored
View File

@ -602,8 +602,17 @@
]
},
{
"type": "STRING",
"value": "="
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "+="
}
]
},
{
"type": "CHOICE",
@ -939,7 +948,7 @@
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "word"
"name": "_expression"
}
},
{

27628
src/parser.c vendored

File diff suppressed because it is too large Load Diff

21
src/scanner.cc vendored
View File

@ -170,14 +170,27 @@ struct Scanner {
}
}
if (is_number && valid_symbols[FILE_DESCRIPTOR] && (lexer->lookahead == '>' || lexer->lookahead == '<')) {
if (is_number &&
valid_symbols[FILE_DESCRIPTOR] &&
(lexer->lookahead == '>' || lexer->lookahead == '<')) {
lexer->result_symbol = FILE_DESCRIPTOR;
return true;
}
if (valid_symbols[VARIABLE_NAME] && (lexer->lookahead == '=' || lexer->lookahead == '[')) {
lexer->result_symbol = VARIABLE_NAME;
return true;
if (valid_symbols[VARIABLE_NAME]) {
if (lexer->lookahead == '+') {
lexer->mark_end(lexer);
advance(lexer);
if (lexer->lookahead == '=') {
lexer->result_symbol = VARIABLE_NAME;
return true;
} else {
return false;
}
} else if (lexer->lookahead == '=' || lexer->lookahead == '[') {
lexer->result_symbol = VARIABLE_NAME;
return true;
}
}
return false;