[WIP] Support multiple statements (#26)

* Rename prebuild target clashing with build target

* Add test:watch target and documentation

* Support multiple statements in substitutions

* Inline the _statements rule

This removes a reduction step by the `_statements -> _statement` rule,
which avoids a reduce/reduce conflict between `_statements` and
`command`.
This commit is contained in:
Kenneth Skovhus 2018-08-06 19:39:05 +02:00 committed by Max Brunsfeld
parent 70d94eb826
commit 08cf72b615
5 changed files with 66258 additions and 70346 deletions

View File

@ -153,6 +153,7 @@ Command substitutions
============================= =============================
echo `echo hi` echo `echo hi`
echo `echo hi; echo there`
echo $(echo $(echo hi)) echo $(echo $(echo hi))
--- ---
@ -161,6 +162,9 @@ echo $(echo $(echo hi))
(command (command
(command_name (word)) (command_name (word))
(command_substitution (command (command_name (word)) (word)))) (command_substitution (command (command_name (word)) (word))))
(command
(command_name (word))
(command_substitution (command (command_name (word)) (word)) (command (command_name (word)) (word))))
(command (command
(command_name (word)) (command_name (word))
(command_substitution (command (command_substitution (command
@ -174,6 +178,7 @@ Process substitutions
============================= =============================
wc -c <(echo abc && echo def) wc -c <(echo abc && echo def)
wc -c <(echo abc; echo def)
echo abc > >(wc -c) echo abc > >(wc -c)
--- ---
@ -185,6 +190,12 @@ echo abc > >(wc -c)
(process_substitution (list (process_substitution (list
(command (command_name (word)) (word)) (command (command_name (word)) (word))
(command (command_name (word)) (word))))) (command (command_name (word)) (word)))))
(command
(command_name (word))
(word)
(process_substitution
(command (command_name (word)) (word))
(command (command_name (word)) (word))))
(command (command
(command_name (word)) (command_name (word))
(word) (word)

View File

@ -377,6 +377,27 @@ export FOOBAR PATH="$PATH:/usr/foobar/bin"
(variable_name) (variable_name)
(variable_assignment (variable_name) (string (simple_expansion (variable_name)))))) (variable_assignment (variable_name) (string (simple_expansion (variable_name))))))
===========================================================
Variable declaration: command substitution with semi-colon
===========================================================
_path=$(
while statement; do
cd ".."
done;
echo $PWD
)
---
(program
(variable_assignment (variable_name)
(command_substitution
(while_statement
(command (command_name (word)))
(do_group (command (command_name (word)) (string))))
(command (command_name (word)) (simple_expansion (variable_name))))))
=========================================== ===========================================
Expressions passed to declaration commands Expressions passed to declaration commands
=========================================== ===========================================

View File

@ -16,6 +16,7 @@ module.exports = grammar({
inline: $ => [ inline: $ => [
$._statement, $._statement,
$._statements,
$._terminator, $._terminator,
$._literal, $._literal,
$._primary_expression, $._primary_expression,
@ -73,6 +74,12 @@ module.exports = grammar({
$.function_definition $.function_definition
), ),
_statements: $ => seq(
repeat($._terminated_statement),
$._statement,
optional($._terminator)
),
for_statement: $ => seq( for_statement: $ => seq(
'for', 'for',
$._simple_variable_name, $._simple_variable_name,
@ -191,9 +198,7 @@ module.exports = grammar({
subshell: $ => seq( subshell: $ => seq(
'(', '(',
repeat($._terminated_statement), $._statements,
$._statement,
optional($._terminator),
')' ')'
), ),
@ -459,13 +464,13 @@ module.exports = grammar({
), ),
command_substitution: $ => choice( command_substitution: $ => choice(
seq('$(', $._statement, ')'), seq('$(', $._statements, ')'),
prec(1, seq('`', $._statement, '`')) prec(1, seq('`', $._statements, '`'))
), ),
process_substitution: $ => seq( process_substitution: $ => seq(
choice('<(', '>('), choice('<(', '>('),
$._statement, $._statements,
')' ')'
), ),

56
src/grammar.json vendored
View File

@ -87,6 +87,34 @@
} }
] ]
}, },
"_statements": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
}
]
},
"for_statement": { "for_statement": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -678,28 +706,9 @@
"type": "STRING", "type": "STRING",
"value": "(" "value": "("
}, },
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_terminated_statement"
}
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement" "name": "_statements"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1916,7 +1925,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement" "name": "_statements"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1936,7 +1945,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement" "name": "_statements"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -1965,7 +1974,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement" "name": "_statements"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -2184,6 +2193,7 @@
], ],
"inline": [ "inline": [
"_statement", "_statement",
"_statements",
"_terminator", "_terminator",
"_literal", "_literal",
"_primary_expression", "_primary_expression",

136499
src/parser.c vendored

File diff suppressed because it is too large Load Diff