Add empty environment variable values

This commit is contained in:
Max Brunsfeld 2017-07-14 17:41:14 -07:00
parent 6d341b8314
commit 66693d7575
5 changed files with 8357 additions and 8294 deletions

View File

@ -79,6 +79,19 @@ VAR1=a VAR2="ok" git diff --word-diff=color
(argument)
(argument)))
===================================
Empty environment variables
===================================
VAR1=
VAR2= echo
---
(program
(environment_variable_assignment (variable_name))
(command (environment_variable_assignment (variable_name)) (command_name)))
===================================
Pipelines
===================================

View File

@ -8,7 +8,8 @@ module.exports = grammar({
$._heredoc_beginning,
$._heredoc_middle,
$._heredoc_end,
$.file_descriptor
$.file_descriptor,
$._empty_value
],
extras: $ => [
@ -149,7 +150,10 @@ module.exports = grammar({
environment_variable_assignment: $ => seq(
rename($.leading_word, 'variable_name'),
'=',
$.value
choice(
$.value,
$._empty_value
)
),
value: $ => choice(

View File

@ -546,9 +546,18 @@
"type": "STRING",
"value": "="
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "_empty_value"
}
]
}
]
},
@ -927,6 +936,10 @@
{
"type": "SYMBOL",
"name": "file_descriptor"
},
{
"type": "SYMBOL",
"name": "_empty_value"
}
],
"inline": [

16597
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ enum TokenType {
HEREDOC_MIDDLE,
HEREDOC_END,
FILE_DESCRIPTOR,
EMPTY_VALUE,
};
struct Scanner {
@ -75,7 +76,9 @@ struct Scanner {
bool scan(TSLexer *lexer, const bool *valid_symbols) {
if (valid_symbols[HEREDOC_MIDDLE]) {
return scan_heredoc_content(lexer, HEREDOC_MIDDLE, HEREDOC_END);
} else if (valid_symbols[HEREDOC_BEGINNING]) {
}
if (valid_symbols[HEREDOC_BEGINNING]) {
heredoc_identifier.clear();
while (iswalpha(lexer->lookahead)) {
heredoc_identifier += lexer->lookahead;
@ -91,7 +94,9 @@ struct Scanner {
}
return scan_heredoc_content(lexer, HEREDOC_BEGINNING, SIMPLE_HEREDOC);
} else if (valid_symbols[FILE_DESCRIPTOR]) {
}
if (valid_symbols[FILE_DESCRIPTOR]) {
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') skip(lexer);
if (iswdigit(lexer->lookahead)) {
advance(lexer);
@ -103,6 +108,13 @@ struct Scanner {
}
}
if (valid_symbols[EMPTY_VALUE]) {
if (iswspace(lexer->lookahead)) {
lexer->result_symbol = EMPTY_VALUE;
return true;
}
}
return false;
}