Support local variable declarations

This commit is contained in:
Mads Hartmann 2018-02-25 00:02:24 +01:00
parent 741cfce4b4
commit 0ed39445d3
4 changed files with 26192 additions and 25221 deletions

View File

@ -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
=========================================

View File

@ -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(
'=',
'+='

38
src/grammar.json vendored
View File

@ -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": [

51344
src/parser.c vendored

File diff suppressed because it is too large Load Diff