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({
':', ':?', '=', ':-', '%', '-', '#' ':', ':?', '=', ':-', '%', '-', '#'
)) ))
), ),
), )),
'}' '}'
), ),

224
src/grammar.json vendored
View File

@ -2141,127 +2141,135 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SEQ", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "variable_name"
},
{
"type": "STRING",
"value": "="
},
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_literal" "name": "variable_name"
}, },
{ {
"type": "BLANK" "type": "STRING",
"value": "="
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "subscript"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
},
{
"type": "SYMBOL",
"name": "_special_variable_name"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "/"
}
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "STRING",
"value": ":?"
},
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": ":-"
},
{
"type": "STRING",
"value": "%"
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "#"
}
]
}
} }
] ]
} }
] ]
}, },
{ {
"type": "SEQ", "type": "BLANK"
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "subscript"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
},
{
"type": "SYMBOL",
"name": "_special_variable_name"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "/"
}
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "STRING",
"value": ":?"
},
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": ":-"
},
{
"type": "STRING",
"value": "%"
},
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"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