Merge pull request #2 from mads-hartmann/support-local-variable-declarations

Support local variable declarations
This commit is contained in:
Max Brunsfeld 2018-02-24 20:25:56 -08:00 committed by GitHub
commit 1efe2e6f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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))) (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
========================================= =========================================

View File

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

38
src/grammar.json vendored
View File

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

51344
src/parser.c vendored

File diff suppressed because it is too large Load Diff