Add support for case fallthrough (#85)

Fixes https://github.com/tree-sitter/tree-sitter-bash/issues/40
This commit is contained in:
Kenneth Skovhus 2020-05-29 22:09:38 +02:00 committed by GitHub
parent f226a4b55a
commit 8ece09ca4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 108986 additions and 85456 deletions

View File

@ -217,7 +217,11 @@ case "opt" in
;;
b)
echo b;;
echo b
;&
c)
echo c;;
esac
case "$Z" in
@ -234,6 +238,8 @@ esac
(program
(case_statement (string)
(case_item (word)
(command (command_name (word)) (word)))
(case_item (word)
(command (command_name (word)) (word)))
(case_item (word)

View File

@ -190,7 +190,10 @@ module.exports = grammar({
repeat(seq('|', field('value', $._literal))),
')',
optional($._statements),
prec(1, ';;')
prec(1, choice(
field('termination', ';;'),
field('fallthrough', choice(';&', ';;&'))
))
),
last_case_item: $ => seq(

30
src/grammar.json vendored
View File

@ -697,8 +697,34 @@
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": ";;"
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "termination",
"content": {
"type": "STRING",
"value": ";;"
}
},
{
"type": "FIELD",
"name": "fallthrough",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";&"
},
{
"type": "STRING",
"value": ";;&"
}
]
}
}
]
}
}
]

32
src/node-types.json vendored
View File

@ -322,6 +322,30 @@
"type": "case_item",
"named": true,
"fields": {
"fallthrough": {
"multiple": false,
"required": false,
"types": [
{
"type": ";&",
"named": false
},
{
"type": ";;&",
"named": false
}
]
},
"termination": {
"multiple": false,
"required": false,
"types": [
{
"type": ";;",
"named": false
}
]
},
"value": {
"multiple": true,
"required": true,
@ -1403,10 +1427,18 @@
"type": ";",
"named": false
},
{
"type": ";&",
"named": false
},
{
"type": ";;",
"named": false
},
{
"type": ";;&",
"named": false
},
{
"type": "<",
"named": false

194367
src/parser.c vendored

File diff suppressed because it is too large Load Diff