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: $ => [ inline: $ => [
$._statement, $._statement,
$._statements,
$._terminator, $._terminator,
$._literal, $._literal,
$._primary_expression, $._primary_expression,
@ -50,9 +49,19 @@ module.exports = grammar({
rules: { rules: {
program: $ => optional($._statements), program: $ => optional($._statements),
_terminated_statement: $ => seq( _statements: $ => prec(1, seq(
repeat(seq(
$._statement,
optional($.heredoc_body),
$._terminator
)),
$._statement, $._statement,
optional($.heredoc_body), optional($.heredoc_body),
optional($._terminator)
)),
_terminated_statement: $ => seq(
$._statement,
$._terminator $._terminator
), ),
@ -78,13 +87,6 @@ module.exports = grammar({
$.function_definition $.function_definition
), ),
_statements: $ => seq(
repeat($._terminated_statement),
$._statement,
optional($.heredoc_body),
optional($._terminator)
),
redirected_statement: $ => prec(-1, seq( redirected_statement: $ => prec(-1, seq(
$._statement, $._statement,
repeat1(choice( repeat1(choice(
@ -129,7 +131,7 @@ module.exports = grammar({
do_group: $ => seq( do_group: $ => seq(
'do', 'do',
repeat($._terminated_statement), optional($._statements),
'done' 'done'
), ),
@ -137,7 +139,7 @@ module.exports = grammar({
'if', 'if',
$._terminated_statement, $._terminated_statement,
'then', 'then',
repeat($._terminated_statement), optional($._statements),
repeat($.elif_clause), repeat($.elif_clause),
optional($.else_clause), optional($.else_clause),
'fi' 'fi'
@ -147,12 +149,12 @@ module.exports = grammar({
'elif', 'elif',
$._terminated_statement, $._terminated_statement,
'then', 'then',
repeat($._terminated_statement) optional($._statements)
), ),
else_clause: $ => seq( else_clause: $ => seq(
'else', 'else',
repeat($._terminated_statement) optional($._statements)
), ),
case_statement: $ => seq( case_statement: $ => seq(
@ -172,10 +174,7 @@ module.exports = grammar({
$._literal, $._literal,
repeat(seq('|', $._literal)), repeat(seq('|', $._literal)),
')', ')',
optional(seq( optional($._statements),
repeat($._terminated_statement),
optional($._statement)
)),
prec(1, ';;') prec(1, ';;')
), ),
@ -183,10 +182,7 @@ module.exports = grammar({
$._literal, $._literal,
repeat(seq('|', $._literal)), repeat(seq('|', $._literal)),
')', ')',
optional(seq( optional($._statements),
repeat($._terminated_statement),
optional($._statement)
)),
optional(prec(1, ';;')) optional(prec(1, ';;'))
), ),
@ -200,7 +196,7 @@ module.exports = grammar({
compound_statement: $ => seq( 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/defaults.completion.bash
examples/bash-it/completion/available/docker.completion.bash examples/bash-it/completion/available/docker.completion.bash
examples/bash-it/completion/available/tmux.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/hawaii50/hawaii50.theme.bash
examples/bash-it/themes/colors.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/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/nwinkler_random_colors/nwinkler_random_colors.theme.bash
examples/bash-it/themes/kitsune/kitsune.theme.bash
examples/bash-it/themes/doubletime/doubletime.theme.bash examples/bash-it/themes/doubletime/doubletime.theme.bash

243
src/grammar.json vendored
View File

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

210409
src/parser.c vendored

File diff suppressed because it is too large Load Diff