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
(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
=============================
@ -286,6 +301,23 @@ export FOOBAR PATH="$PATH:/usr/foobar/bin"
(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
=========================================

View File

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

19
src/grammar.json vendored
View File

@ -676,6 +676,9 @@
]
},
"declaration_command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
@ -710,7 +713,7 @@
"members": [
{
"type": "SYMBOL",
"name": "word"
"name": "_expression"
},
{
"type": "SYMBOL",
@ -724,6 +727,7 @@
}
}
]
}
},
"_assignment": {
"type": "SEQ",
@ -1180,6 +1184,19 @@
{
"type": "SYMBOL",
"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