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() { function do_something_else() {
echo ok a | xargs -I{} find xml/{} -type f
} }
function do_yet_another_thing { function do_yet_another_thing {
@ -337,7 +337,16 @@ function do_yet_another_thing {
(compound_statement (command (command_name (word)) (word)))) (compound_statement (command (command_name (word)) (word))))
(function_definition (function_definition
(word) (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 (redirected_statement (function_definition
(word) (word)
(compound_statement (command (command_name (word)) (word)))) (compound_statement (command (command_name (word)) (word))))

View File

@ -18,6 +18,7 @@ module.exports = grammar({
$._statement, $._statement,
$._terminator, $._terminator,
$._literal, $._literal,
$._statements2,
$._primary_expression, $._primary_expression,
$._simple_variable_name, $._simple_variable_name,
$._special_variable_name, $._special_variable_name,
@ -62,6 +63,12 @@ module.exports = grammar({
optional($._terminator) optional($._terminator)
)), )),
_statements2: $ => repeat1(seq(
$._statement,
optional(seq('\n', $.heredoc_body)),
$._terminator
)),
_terminated_statement: $ => seq( _terminated_statement: $ => seq(
$._statement, $._statement,
$._terminator $._terminator
@ -133,7 +140,7 @@ module.exports = grammar({
do_group: $ => seq( do_group: $ => seq(
'do', 'do',
optional($._statements), optional($._statements2),
'done' 'done'
), ),
@ -141,7 +148,7 @@ module.exports = grammar({
'if', 'if',
$._terminated_statement, $._terminated_statement,
'then', 'then',
optional($._statements), optional($._statements2),
repeat($.elif_clause), repeat($.elif_clause),
optional($.else_clause), optional($.else_clause),
'fi' 'fi'
@ -151,12 +158,12 @@ module.exports = grammar({
'elif', 'elif',
$._terminated_statement, $._terminated_statement,
'then', 'then',
optional($._statements) optional($._statements2)
), ),
else_clause: $ => seq( else_clause: $ => seq(
'else', 'else',
optional($._statements) optional($._statements2)
), ),
case_statement: $ => seq( case_statement: $ => seq(
@ -198,7 +205,11 @@ module.exports = grammar({
compound_statement: $ => seq( 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": { "_terminated_statement": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -376,7 +413,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statements" "name": "_statements2"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -409,7 +446,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statements" "name": "_statements2"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -461,7 +498,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statements" "name": "_statements2"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -482,7 +519,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statements" "name": "_statements2"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -736,16 +773,41 @@
"value": "{" "value": "{"
}, },
{ {
"type": "CHOICE", "type": "REPEAT",
"members": [ "content": {
{ "type": "SEQ",
"type": "SYMBOL", "members": [
"name": "_statements" {
}, "type": "SYMBOL",
{ "name": "_statement"
"type": "BLANK" },
} {
] "type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "SYMBOL",
"name": "heredoc_body"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_terminator"
}
]
}
}, },
{ {
"type": "STRING", "type": "STRING",
@ -2310,6 +2372,7 @@
"_statement", "_statement",
"_terminator", "_terminator",
"_literal", "_literal",
"_statements2",
"_primary_expression", "_primary_expression",
"_simple_variable_name", "_simple_variable_name",
"_special_variable_name" "_special_variable_name"

178175
src/parser.c vendored

File diff suppressed because it is too large Load Diff