Add support for empty expansions (#82)

Fixes https://github.com/tree-sitter/tree-sitter-bash/issues/57
This commit is contained in:
Kenneth Skovhus 2020-05-15 21:32:47 +02:00 committed by GitHub
parent 38e8ba4a3d
commit f226a4b55a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81107 additions and 80141 deletions

View File

@ -57,6 +57,8 @@ echo $# $* $@ $!
Variable expansions Variable expansions
============================= =============================
echo ${}
echo ${#}
echo ${var1#*#} echo ${var1#*#}
echo ${!abc} echo ${!abc}
echo ${abc} echo ${abc}
@ -68,6 +70,8 @@ echo ${abc:
--- ---
(program (program
(command (command_name (word)) (expansion))
(command (command_name (word)) (expansion))
(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)))
(command (command_name (word)) (expansion (variable_name))) (command (command_name (word)) (expansion (variable_name)))

View File

@ -489,7 +489,7 @@ module.exports = grammar({
expansion: $ => seq( expansion: $ => seq(
'${', '${',
optional(choice('#', '!')), optional(choice('#', '!')),
choice( optional(choice(
seq( seq(
$.variable_name, $.variable_name,
'=', '=',
@ -510,7 +510,7 @@ module.exports = grammar({
':', ':?', '=', ':-', '%', '-', '#' ':', ':?', '=', ':-', '%', '-', '#'
)) ))
), ),
), )),
'}' '}'
), ),

8
src/grammar.json vendored
View File

@ -2137,6 +2137,9 @@
} }
] ]
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -2265,6 +2268,11 @@
} }
] ]
}, },
{
"type": "BLANK"
}
]
},
{ {
"type": "STRING", "type": "STRING",
"value": "}" "value": "}"

2
src/node-types.json vendored
View File

@ -604,7 +604,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "_primary_expression", "type": "_primary_expression",

161014
src/parser.c vendored

File diff suppressed because it is too large Load Diff