Support local variable declarations
This commit is contained in:
parent
741cfce4b4
commit
0ed39445d3
|
@ -143,6 +143,24 @@ find "`dirname $file`" -name "$base"'*'
|
|||
(string (simple_expansion (variable_name)))
|
||||
(raw_string))))
|
||||
|
||||
=========================================
|
||||
Local Variable Declaration
|
||||
=========================================
|
||||
|
||||
function a {
|
||||
local a=42
|
||||
local b
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(function_definition
|
||||
(word)
|
||||
(compound_statement
|
||||
(local_variable_declaration (simple_variable_name) (word))
|
||||
(local_variable_declaration (simple_variable_name)))))
|
||||
|
||||
=========================================
|
||||
Arrays and array expansions
|
||||
=========================================
|
||||
|
|
13
grammar.js
13
grammar.js
|
@ -48,6 +48,9 @@ module.exports = grammar({
|
|||
|
||||
_statement: $ => choice(
|
||||
$.environment_variable_assignment,
|
||||
// Local variable are only allowed inside the body of a function, but to
|
||||
// keep the grammar simple we'll ignore that requirements.
|
||||
$.local_variable_declaration,
|
||||
$.command,
|
||||
$.bracket_command,
|
||||
$.for_statement,
|
||||
|
@ -182,6 +185,16 @@ module.exports = grammar({
|
|||
$.variable_name,
|
||||
$.subscript
|
||||
),
|
||||
$._assignment
|
||||
),
|
||||
|
||||
local_variable_declaration: $ => seq(
|
||||
'local',
|
||||
$.simple_variable_name,
|
||||
optional($._assignment)
|
||||
),
|
||||
|
||||
_assignment: $ => seq(
|
||||
choice(
|
||||
'=',
|
||||
'+='
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "environment_variable_assignment"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "local_variable_declaration"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "command"
|
||||
|
@ -601,6 +605,40 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_assignment"
|
||||
}
|
||||
]
|
||||
},
|
||||
"local_variable_declaration": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "local"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "simple_variable_name"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_assignment"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"_assignment": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue