Add support for C-style for statements (#23)
This commit is contained in:
parent
886a957d1e
commit
9bbd80dee1
|
@ -100,6 +100,43 @@ done
|
|||
(command (command_name (word)) (simple_expansion (variable_name)))
|
||||
(variable_assignment (variable_name) (raw_string)))))
|
||||
|
||||
====================================
|
||||
C-style for statements
|
||||
====================================
|
||||
|
||||
for (( c=1; c<=5; c++ ))
|
||||
do
|
||||
echo $c
|
||||
done
|
||||
|
||||
for (( c=1; c<=5; c++ )) {
|
||||
echo $c
|
||||
}
|
||||
|
||||
for (( ; ; ))
|
||||
do
|
||||
echo 'forever'
|
||||
done
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(c_style_for_statement
|
||||
(word)
|
||||
(binary_expression (word) (word))
|
||||
(word)
|
||||
(do_group
|
||||
(command (command_name (word)) (simple_expansion (variable_name)))))
|
||||
(c_style_for_statement
|
||||
(word)
|
||||
(binary_expression (word) (word))
|
||||
(word)
|
||||
(compound_statement
|
||||
(command (command_name (word)) (simple_expansion (variable_name)))))
|
||||
(c_style_for_statement
|
||||
(do_group
|
||||
(command (command_name (word)) (raw_string)))))
|
||||
|
||||
====================================
|
||||
If statements
|
||||
====================================
|
||||
|
|
16
grammar.js
16
grammar.js
|
@ -63,6 +63,7 @@ module.exports = grammar({
|
|||
$.test_command,
|
||||
$.negated_command,
|
||||
$.for_statement,
|
||||
$.c_style_for_statement,
|
||||
$.while_statement,
|
||||
$.if_statement,
|
||||
$.case_statement,
|
||||
|
@ -83,6 +84,21 @@ module.exports = grammar({
|
|||
$.do_group
|
||||
),
|
||||
|
||||
c_style_for_statement: $ => seq(
|
||||
'for',
|
||||
'((',
|
||||
optional($._expression),
|
||||
$._terminator,
|
||||
optional($._expression),
|
||||
$._terminator,
|
||||
optional($._expression),
|
||||
'))',
|
||||
choice(
|
||||
$.do_group,
|
||||
$.compound_statement
|
||||
)
|
||||
),
|
||||
|
||||
while_statement: $ => seq(
|
||||
'while',
|
||||
$._terminated_statement,
|
||||
|
|
|
@ -53,6 +53,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "for_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "c_style_for_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "while_statement"
|
||||
|
@ -128,6 +132,80 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"c_style_for_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "for"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "(("
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_terminator"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_terminator"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "))"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "do_group"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "compound_statement"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"while_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue