Add special variable @, expressions in declarations

This commit is contained in:
Max Brunsfeld 2018-02-28 17:32:48 -08:00
parent b13862adec
commit 4920373ca4
4 changed files with 52438 additions and 50123 deletions

View File

@ -48,6 +48,21 @@ echo $abc
(program (program
(command (command_name (word)) (simple_expansion (variable_name)))) (command (command_name (word)) (simple_expansion (variable_name))))
=============================
Special variable expansions
=============================
echo $# $* $@
---
(program
(command
(command_name (word))
(simple_expansion (special_variable_name))
(simple_expansion (special_variable_name))
(simple_expansion (special_variable_name))))
============================= =============================
Variable expansions Variable expansions
============================= =============================
@ -286,6 +301,23 @@ export FOOBAR PATH="$PATH:/usr/foobar/bin"
(variable_name) (variable_name)
(variable_assignment (variable_name) (string (simple_expansion (variable_name)))))) (variable_assignment (variable_name) (string (simple_expansion (variable_name))))))
===========================================
Expressions passed to declaration commands
===========================================
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
---
(program
(declaration_command
(string
(command_substitution
(pipeline
(command (command_name (word)) (expansion (variable_name)))
(command (command_name (word)) (concatenation (word)) (concatenation (word)))))
(expansion (variable_name) (word)))))
========================================= =========================================
Arrays and array expansions Arrays and array expansions
========================================= =========================================

View File

@ -204,14 +204,14 @@ module.exports = grammar({
$._assignment $._assignment
), ),
declaration_command: $ => seq( declaration_command: $ => prec.left(seq(
choice('declare', 'typeset', 'export', 'readonly', 'local'), choice('declare', 'typeset', 'export', 'readonly', 'local'),
repeat(choice( repeat(choice(
$.word, $._expression,
$._simple_variable_name, $._simple_variable_name,
$.variable_assignment $.variable_assignment
)) ))
), )),
_assignment: $ => seq( _assignment: $ => seq(
choice( choice(
@ -323,7 +323,12 @@ module.exports = grammar({
simple_expansion: $ => seq( simple_expansion: $ => seq(
'$', '$',
choice($._simple_variable_name, $._special_variable_name) choice(
$._simple_variable_name,
$._special_variable_name,
alias('#', $.special_variable_name),
$.string
)
), ),
expansion: $ => seq( expansion: $ => seq(

93
src/grammar.json vendored
View File

@ -676,54 +676,58 @@
] ]
}, },
"declaration_command": { "declaration_command": {
"type": "SEQ", "type": "PREC_LEFT",
"members": [ "value": 0,
{ "content": {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING",
"value": "declare"
},
{
"type": "STRING",
"value": "typeset"
},
{
"type": "STRING",
"value": "export"
},
{
"type": "STRING",
"value": "readonly"
},
{
"type": "STRING",
"value": "local"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "STRING",
"name": "word" "value": "declare"
}, },
{ {
"type": "SYMBOL", "type": "STRING",
"name": "_simple_variable_name" "value": "typeset"
}, },
{ {
"type": "SYMBOL", "type": "STRING",
"name": "variable_assignment" "value": "export"
},
{
"type": "STRING",
"value": "readonly"
},
{
"type": "STRING",
"value": "local"
} }
] ]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "_simple_variable_name"
},
{
"type": "SYMBOL",
"name": "variable_assignment"
}
]
}
} }
} ]
] }
}, },
"_assignment": { "_assignment": {
"type": "SEQ", "type": "SEQ",
@ -1180,6 +1184,19 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_special_variable_name" "name": "_special_variable_name"
},
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "#"
},
"named": true,
"value": "special_variable_name"
},
{
"type": "SYMBOL",
"name": "string"
} }
] ]
} }

102423
src/parser.c vendored

File diff suppressed because it is too large Load Diff