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[@]} echo ${#b[@]}
a[$i]=50 a[$i]=50
a+=(foo "bar" $(baz))
--- ---
@ -159,4 +160,10 @@ a[$i]=50
(command (command_name (word)) (expansion (variable_name))) (command (command_name (word)) (expansion (variable_name)))
(environment_variable_assignment (environment_variable_assignment
(subscript (variable_name) (simple_expansion (variable_name))) (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, $.variable_name,
$.subscript $.subscript
), ),
choice(
'=', '=',
'+='
),
choice( choice(
$._expression, $._expression,
$.array, $.array,
@ -271,7 +274,7 @@ module.exports = grammar({
array: $ => seq( array: $ => seq(
'(', '(',
repeat($.word), repeat($._expression),
')' ')'
), ),

11
src/grammar.json vendored
View File

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

27628
src/parser.c vendored

File diff suppressed because it is too large Load Diff

17
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; lexer->result_symbol = FILE_DESCRIPTOR;
return true; return true;
} }
if (valid_symbols[VARIABLE_NAME] && (lexer->lookahead == '=' || lexer->lookahead == '[')) { if (valid_symbols[VARIABLE_NAME]) {
if (lexer->lookahead == '+') {
lexer->mark_end(lexer);
advance(lexer);
if (lexer->lookahead == '=') {
lexer->result_symbol = VARIABLE_NAME; lexer->result_symbol = VARIABLE_NAME;
return true; return true;
} else {
return false;
}
} else if (lexer->lookahead == '=' || lexer->lookahead == '[') {
lexer->result_symbol = VARIABLE_NAME;
return true;
}
} }
return false; return false;