Add special variable @, expressions in declarations
This commit is contained in:
parent
b13862adec
commit
4920373ca4
|
@ -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
|
||||
=========================================
|
||||
|
|
13
grammar.js
13
grammar.js
|
@ -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(
|
||||
|
|
|
@ -676,54 +676,58 @@
|
|||
]
|
||||
},
|
||||
"declaration_command": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"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": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "word"
|
||||
"type": "STRING",
|
||||
"value": "declare"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_simple_variable_name"
|
||||
"type": "STRING",
|
||||
"value": "typeset"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable_assignment"
|
||||
"type": "STRING",
|
||||
"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": {
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue