Add function definitions
This commit is contained in:
parent
5446533c20
commit
6d341b8314
|
@ -97,3 +97,21 @@ Subshells
|
|||
|
||||
(program
|
||||
(subshell (command (command_name) (argument))))
|
||||
|
||||
===============================
|
||||
Function definitions
|
||||
===============================
|
||||
|
||||
do_something() {
|
||||
echo ok
|
||||
}
|
||||
|
||||
function do_something_else() {
|
||||
echo ok
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(function_definition (command_name) (compound_command (command (command_name) (argument))))
|
||||
(function_definition (command_name) (compound_command (command (command_name) (argument)))))
|
||||
|
|
17
grammar.js
17
grammar.js
|
@ -33,7 +33,8 @@ module.exports = grammar({
|
|||
$.case_statement,
|
||||
$.pipeline,
|
||||
$.list,
|
||||
$.subshell
|
||||
$.subshell,
|
||||
$.function_definition
|
||||
),
|
||||
|
||||
while_statement: $ => seq(
|
||||
|
@ -87,6 +88,20 @@ module.exports = grammar({
|
|||
';;'
|
||||
),
|
||||
|
||||
function_definition: $ => seq(
|
||||
optional('function'),
|
||||
rename($.leading_word, 'command_name'),
|
||||
'(',
|
||||
')',
|
||||
$.compound_command
|
||||
),
|
||||
|
||||
compound_command: $ => seq(
|
||||
'{',
|
||||
repeat($._terminated_statement),
|
||||
'}'
|
||||
),
|
||||
|
||||
bracket_command: $ => choice(
|
||||
seq('[', repeat1($.value), ']'),
|
||||
seq('[[', repeat1($.value), ']]')
|
||||
|
|
|
@ -59,6 +59,10 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "subshell"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_definition"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -254,6 +258,63 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"function_definition": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "function"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "RENAME",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "leading_word"
|
||||
},
|
||||
"value": "command_name"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "compound_command"
|
||||
}
|
||||
]
|
||||
},
|
||||
"compound_command": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_terminated_statement"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bracket_command": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
|
24801
src/parser.c
24801
src/parser.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue