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) b)
echo b;; echo b
;&
c)
echo c;;
esac esac
case "$Z" in case "$Z" in
@ -234,6 +238,8 @@ esac
(program (program
(case_statement (string) (case_statement (string)
(case_item (word)
(command (command_name (word)) (word)))
(case_item (word) (case_item (word)
(command (command_name (word)) (word))) (command (command_name (word)) (word)))
(case_item (word) (case_item (word)

View File

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

26
src/grammar.json vendored
View File

@ -696,10 +696,36 @@
{ {
"type": "PREC", "type": "PREC",
"value": 1, "value": 1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "termination",
"content": { "content": {
"type": "STRING", "type": "STRING",
"value": ";;" "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", "type": "case_item",
"named": true, "named": true,
"fields": { "fields": {
"fallthrough": {
"multiple": false,
"required": false,
"types": [
{
"type": ";&",
"named": false
},
{
"type": ";;&",
"named": false
}
]
},
"termination": {
"multiple": false,
"required": false,
"types": [
{
"type": ";;",
"named": false
}
]
},
"value": { "value": {
"multiple": true, "multiple": true,
"required": true, "required": true,
@ -1403,10 +1427,18 @@
"type": ";", "type": ";",
"named": false "named": false
}, },
{
"type": ";&",
"named": false
},
{ {
"type": ";;", "type": ";;",
"named": false "named": false
}, },
{
"type": ";;&",
"named": false
},
{ {
"type": "<", "type": "<",
"named": false "named": false

194367
src/parser.c vendored

File diff suppressed because it is too large Load Diff