Handle lists of statements more consistently

This commit is contained in:
Max Brunsfeld 2018-10-18 15:29:07 -07:00
parent 4fb4e2960d
commit 48f7e22475
4 changed files with 122406 additions and 88290 deletions

View File

@ -16,7 +16,6 @@ module.exports = grammar({
inline: $ => [
$._statement,
$._statements,
$._terminator,
$._literal,
$._primary_expression,
@ -50,10 +49,20 @@ module.exports = grammar({
rules: {
program: $ => optional($._statements),
_terminated_statement: $ => seq(
_statements: $ => prec(1, seq(
repeat(seq(
$._statement,
optional($.heredoc_body),
$._terminator
)),
$._statement,
optional($.heredoc_body),
optional($._terminator)
)),
_terminated_statement: $ => seq(
$._statement,
$._terminator
),
// Statements
@ -78,13 +87,6 @@ module.exports = grammar({
$.function_definition
),
_statements: $ => seq(
repeat($._terminated_statement),
$._statement,
optional($.heredoc_body),
optional($._terminator)
),
redirected_statement: $ => prec(-1, seq(
$._statement,
repeat1(choice(
@ -129,7 +131,7 @@ module.exports = grammar({
do_group: $ => seq(
'do',
repeat($._terminated_statement),
optional($._statements),
'done'
),
@ -137,7 +139,7 @@ module.exports = grammar({
'if',
$._terminated_statement,
'then',
repeat($._terminated_statement),
optional($._statements),
repeat($.elif_clause),
optional($.else_clause),
'fi'
@ -147,12 +149,12 @@ module.exports = grammar({
'elif',
$._terminated_statement,
'then',
repeat($._terminated_statement)
optional($._statements)
),
else_clause: $ => seq(
'else',
repeat($._terminated_statement)
optional($._statements)
),
case_statement: $ => seq(
@ -172,10 +174,7 @@ module.exports = grammar({
$._literal,
repeat(seq('|', $._literal)),
')',
optional(seq(
repeat($._terminated_statement),
optional($._statement)
)),
optional($._statements),
prec(1, ';;')
),
@ -183,10 +182,7 @@ module.exports = grammar({
$._literal,
repeat(seq('|', $._literal)),
')',
optional(seq(
repeat($._terminated_statement),
optional($._statement)
)),
optional($._statements),
optional(prec(1, ';;'))
),
@ -200,7 +196,7 @@ module.exports = grammar({
compound_statement: $ => seq(
'{',
repeat($._terminated_statement),
optional($._statements),
'}'
),

View File

@ -9,12 +9,8 @@ examples/bash-it/completion/available/git.completion.bash
examples/bash-it/completion/available/defaults.completion.bash
examples/bash-it/completion/available/docker.completion.bash
examples/bash-it/completion/available/tmux.completion.bash
examples/bash-it/lib/preexec.bash
examples/bash-it/themes/hawaii50/hawaii50.theme.bash
examples/bash-it/themes/colors.theme.bash
examples/bash-it/themes/morris/morris.theme.bash
examples/bash-it/themes/powerline/powerline.base.bash
examples/bash-it/themes/brainy/brainy.theme.bash
examples/bash-it/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash
examples/bash-it/themes/kitsune/kitsune.theme.bash
examples/bash-it/themes/doubletime/doubletime.theme.bash

197
src/grammar.json vendored
View File

@ -14,7 +14,15 @@
}
]
},
"_terminated_statement": {
"_statements": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
@ -38,6 +46,51 @@
"name": "_terminator"
}
]
}
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "heredoc_body"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
}
]
}
},
"_terminated_statement": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "SYMBOL",
"name": "_terminator"
}
]
},
"_statement": {
"type": "CHOICE",
@ -112,46 +165,6 @@
}
]
},
"_statements": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "heredoc_body"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
}
]
},
"redirected_statement": {
"type": "PREC",
"value": -1,
@ -341,11 +354,16 @@
"value": "do"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminated_statement"
"name": "_statements"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -369,11 +387,16 @@
"value": "then"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminated_statement"
"name": "_statements"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -416,11 +439,16 @@
"value": "then"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminated_statement"
"name": "_statements"
},
{
"type": "BLANK"
}
]
}
]
},
@ -432,11 +460,16 @@
"value": "else"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminated_statement"
"name": "_statements"
},
{
"type": "BLANK"
}
]
}
]
},
@ -537,28 +570,8 @@
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "BLANK"
}
]
}
]
"name": "_statements"
},
{
"type": "BLANK"
@ -606,28 +619,8 @@
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "BLANK"
}
]
}
]
"name": "_statements"
},
{
"type": "BLANK"
@ -725,11 +718,16 @@
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminated_statement"
"name": "_statements"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -1739,7 +1737,7 @@
"value": -1,
"content": {
"type": "PATTERN",
"value": "([^\"`$]|\\\\.)+"
"value": "([^\"`$\\\\]|\\\\(.|\\n))+"
}
}
},
@ -2246,7 +2244,6 @@
],
"inline": [
"_statement",
"_statements",
"_terminator",
"_literal",
"_primary_expression",

210409
src/parser.c vendored

File diff suppressed because it is too large Load Diff