Add for statements

This commit is contained in:
Max Brunsfeld 2017-07-14 17:51:06 -07:00
parent 38d22aa8c3
commit f73de068e7
4 changed files with 14310 additions and 13367 deletions

View File

@ -16,6 +16,23 @@ done
(command (command_name) (argument)) (command (command_name) (argument))
(command (command_name) (argument))))) (command (command_name) (argument)))))
====================================
For statements
====================================
for a in $(seq 1 10); do
echo $a
done
---
(program
(for_statement
(argument)
(command (command_substitution (command (command_name) (argument) (argument))))
(do_group
(command (command_name) (expansion (variable_name))))))
==================================== ====================================
If statements If statements
==================================== ====================================

View File

@ -29,6 +29,7 @@ module.exports = grammar({
$.environment_variable_assignment, $.environment_variable_assignment,
$.command, $.command,
$.bracket_command, $.bracket_command,
$.for_statement,
$.while_statement, $.while_statement,
$.if_statement, $.if_statement,
$.case_statement, $.case_statement,
@ -38,6 +39,14 @@ module.exports = grammar({
$.function_definition $.function_definition
), ),
for_statement: $ => seq(
'for',
rename($.word, 'argument'),
'in',
$._terminated_statement,
$.do_group
),
while_statement: $ => seq( while_statement: $ => seq(
'while', 'while',
$._terminated_statement, $._terminated_statement,
@ -117,7 +126,8 @@ module.exports = grammar({
rename(choice($.leading_word), 'command_name'), rename(choice($.leading_word), 'command_name'),
':', ':',
$.quoted_argument, $.quoted_argument,
$.single_quoted_argument $.single_quoted_argument,
$.command_substitution
), ),
optional(seq( optional(seq(
/\s+/, /\s+/,

37
src/grammar.json vendored
View File

@ -36,6 +36,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "bracket_command" "name": "bracket_command"
}, },
{
"type": "SYMBOL",
"name": "for_statement"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "while_statement" "name": "while_statement"
@ -66,6 +70,35 @@
} }
] ]
}, },
"for_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "for"
},
{
"type": "RENAME",
"content": {
"type": "SYMBOL",
"name": "word"
},
"value": "argument"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "_terminated_statement"
},
{
"type": "SYMBOL",
"name": "do_group"
}
]
},
"while_statement": { "while_statement": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -406,6 +439,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "single_quoted_argument" "name": "single_quoted_argument"
},
{
"type": "SYMBOL",
"name": "command_substitution"
} }
] ]
}, },

27611
src/parser.c vendored

File diff suppressed because it is too large Load Diff