Handle empty default value during variable expansion (#1)

* Handle empty default value during variable expansion

* Make expression after colon optional

As suggested by @maxbrunsfeld
This commit is contained in:
Mads Hartmann 2018-02-24 22:40:43 +01:00 committed by Max Brunsfeld
parent bda693990e
commit 741cfce4b4
4 changed files with 10016 additions and 9591 deletions

View File

@ -28,12 +28,17 @@ Variable expansions
echo ${abc} echo ${abc}
echo ${abc:-def} echo ${abc:-def}
echo ${abc:- }
echo ${abc:
}
--- ---
(program (program
(command (command_name (word)) (expansion (variable_name))) (command (command_name (word)) (expansion (variable_name)))
(command (command_name (word)) (expansion (variable_name) (word)))) (command (command_name (word)) (expansion (variable_name) (word)))
(command (command_name (word)) (expansion (variable_name)))
(command (command_name (word)) (expansion (variable_name))))
=================================== ===================================
Other variable expansion operators Other variable expansion operators

View File

@ -295,7 +295,7 @@ module.exports = grammar({
seq( seq(
$._variable_name, $._variable_name,
choice(':', ':?', '=', ':-', '%', '/'), choice(':', ':?', '=', ':-', '%', '/'),
$._expression optional($._expression)
) )
), ),
'}' '}'

12
src/grammar.json vendored
View File

@ -1084,8 +1084,16 @@
] ]
}, },
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "_expression" "members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
} }
] ]
} }

19586
src/parser.c vendored

File diff suppressed because it is too large Load Diff