Merge pull request #2 from mads-hartmann/support-local-variable-declarations
Support local variable declarations
This commit is contained in:
commit
1efe2e6f7a
|
@ -143,6 +143,24 @@ find "`dirname $file`" -name "$base"'*'
|
||||||
(string (simple_expansion (variable_name)))
|
(string (simple_expansion (variable_name)))
|
||||||
(raw_string))))
|
(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
|
Arrays and array expansions
|
||||||
=========================================
|
=========================================
|
||||||
|
|
13
grammar.js
13
grammar.js
|
@ -48,6 +48,9 @@ module.exports = grammar({
|
||||||
|
|
||||||
_statement: $ => choice(
|
_statement: $ => choice(
|
||||||
$.environment_variable_assignment,
|
$.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,
|
$.command,
|
||||||
$.bracket_command,
|
$.bracket_command,
|
||||||
$.for_statement,
|
$.for_statement,
|
||||||
|
@ -182,6 +185,16 @@ module.exports = grammar({
|
||||||
$.variable_name,
|
$.variable_name,
|
||||||
$.subscript
|
$.subscript
|
||||||
),
|
),
|
||||||
|
$._assignment
|
||||||
|
),
|
||||||
|
|
||||||
|
local_variable_declaration: $ => seq(
|
||||||
|
'local',
|
||||||
|
$.simple_variable_name,
|
||||||
|
optional($._assignment)
|
||||||
|
),
|
||||||
|
|
||||||
|
_assignment: $ => seq(
|
||||||
choice(
|
choice(
|
||||||
'=',
|
'=',
|
||||||
'+='
|
'+='
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "environment_variable_assignment"
|
"name": "environment_variable_assignment"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "local_variable_declaration"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "command"
|
"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",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue