Require a terminator at the ends of some compound statements

Fixes #44
This commit is contained in:
Max Brunsfeld 2019-04-18 15:38:34 -07:00
parent 53446e0e81
commit e9748c132b
4 changed files with 60021 additions and 118279 deletions

View File

@ -322,7 +322,7 @@ do_something() {
}
function do_something_else() {
echo ok
a | xargs -I{} find xml/{} -type f
}
function do_yet_another_thing {
@ -337,7 +337,16 @@ function do_yet_another_thing {
(compound_statement (command (command_name (word)) (word))))
(function_definition
(word)
(compound_statement (command (command_name (word)) (word))))
(compound_statement
(pipeline
(command (command_name (word)))
(command
(command_name (word))
(concatenation (word))
(word)
(concatenation (word))
(word)
(word)))))
(redirected_statement (function_definition
(word)
(compound_statement (command (command_name (word)) (word))))

View File

@ -18,6 +18,7 @@ module.exports = grammar({
$._statement,
$._terminator,
$._literal,
$._statements2,
$._primary_expression,
$._simple_variable_name,
$._special_variable_name,
@ -62,6 +63,12 @@ module.exports = grammar({
optional($._terminator)
)),
_statements2: $ => repeat1(seq(
$._statement,
optional(seq('\n', $.heredoc_body)),
$._terminator
)),
_terminated_statement: $ => seq(
$._statement,
$._terminator
@ -133,7 +140,7 @@ module.exports = grammar({
do_group: $ => seq(
'do',
optional($._statements),
optional($._statements2),
'done'
),
@ -141,7 +148,7 @@ module.exports = grammar({
'if',
$._terminated_statement,
'then',
optional($._statements),
optional($._statements2),
repeat($.elif_clause),
optional($.else_clause),
'fi'
@ -151,12 +158,12 @@ module.exports = grammar({
'elif',
$._terminated_statement,
'then',
optional($._statements)
optional($._statements2)
),
else_clause: $ => seq(
'else',
optional($._statements)
optional($._statements2)
),
case_statement: $ => seq(
@ -198,7 +205,11 @@ module.exports = grammar({
compound_statement: $ => seq(
'{',
optional($._statements),
repeat(seq(
$._statement,
optional(seq('\n', $.heredoc_body)),
$._terminator
)),
'}'
),

91
src/grammar.json vendored
View File

@ -97,6 +97,43 @@
]
}
},
"_statements2": {
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_terminator"
}
]
}
},
"_terminated_statement": {
"type": "SEQ",
"members": [
@ -376,7 +413,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_statements"
"name": "_statements2"
},
{
"type": "BLANK"
@ -409,7 +446,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_statements"
"name": "_statements2"
},
{
"type": "BLANK"
@ -461,7 +498,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_statements"
"name": "_statements2"
},
{
"type": "BLANK"
@ -482,7 +519,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_statements"
"name": "_statements2"
},
{
"type": "BLANK"
@ -736,16 +773,41 @@
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_statements"
},
{
"type": "BLANK"
}
]
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_terminator"
}
]
}
},
{
"type": "STRING",
@ -2310,6 +2372,7 @@
"_statement",
"_terminator",
"_literal",
"_statements2",
"_primary_expression",
"_simple_variable_name",
"_special_variable_name"

178175
src/parser.c vendored

File diff suppressed because it is too large Load Diff