Distinguish unset commands from regular commands
This commit is contained in:
parent
69d64558a3
commit
f33bf06de2
|
@ -265,83 +265,6 @@ echo "#"
|
||||||
(command (command_name (word)) (string))
|
(command (command_name (word)) (string))
|
||||||
(command (command_name (word)) (string)))
|
(command (command_name (word)) (string)))
|
||||||
|
|
||||||
=========================================
|
|
||||||
Variable declaration: declare & typeset
|
|
||||||
=========================================
|
|
||||||
|
|
||||||
declare var1
|
|
||||||
typeset -i -r var2=42 var3=10
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(program
|
|
||||||
(declaration_command (variable_name))
|
|
||||||
(declaration_command (word) (word)
|
|
||||||
(variable_assignment (variable_name) (word))
|
|
||||||
(variable_assignment (variable_name) (word))))
|
|
||||||
|
|
||||||
=========================================
|
|
||||||
Variable declaration: readonly
|
|
||||||
=========================================
|
|
||||||
|
|
||||||
readonly var1
|
|
||||||
readonly var2=42
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(program
|
|
||||||
(declaration_command (variable_name))
|
|
||||||
(declaration_command (variable_assignment (variable_name) (word))))
|
|
||||||
|
|
||||||
=========================================
|
|
||||||
Variable declaration: local
|
|
||||||
=========================================
|
|
||||||
|
|
||||||
local a=42 b
|
|
||||||
local -r c
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(program
|
|
||||||
(declaration_command
|
|
||||||
(variable_assignment (variable_name) (word))
|
|
||||||
(variable_name))
|
|
||||||
(declaration_command
|
|
||||||
(word)
|
|
||||||
(variable_name)))
|
|
||||||
|
|
||||||
=========================================
|
|
||||||
Variable declaration: export
|
|
||||||
=========================================
|
|
||||||
|
|
||||||
export PATH
|
|
||||||
export FOOBAR PATH="$PATH:/usr/foobar/bin"
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(program
|
|
||||||
(declaration_command (variable_name))
|
|
||||||
(declaration_command
|
|
||||||
(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
|
||||||
=========================================
|
=========================================
|
||||||
|
|
|
@ -171,3 +171,95 @@ function do_yet_another_thing {
|
||||||
(word)
|
(word)
|
||||||
(compound_statement (command (command_name (word)) (word)))
|
(compound_statement (command (command_name (word)) (word)))
|
||||||
(file_redirect (file_descriptor) (word))))
|
(file_redirect (file_descriptor) (word))))
|
||||||
|
|
||||||
|
=========================================
|
||||||
|
Variable declaration: declare & typeset
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
declare var1
|
||||||
|
typeset -i -r var2=42 var3=10
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(declaration_command (variable_name))
|
||||||
|
(declaration_command (word) (word)
|
||||||
|
(variable_assignment (variable_name) (word))
|
||||||
|
(variable_assignment (variable_name) (word))))
|
||||||
|
|
||||||
|
=========================================
|
||||||
|
Variable declaration: readonly
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
readonly var1
|
||||||
|
readonly var2=42
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(declaration_command (variable_name))
|
||||||
|
(declaration_command (variable_assignment (variable_name) (word))))
|
||||||
|
|
||||||
|
=========================================
|
||||||
|
Variable declaration: local
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
local a=42 b
|
||||||
|
local -r c
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(declaration_command
|
||||||
|
(variable_assignment (variable_name) (word))
|
||||||
|
(variable_name))
|
||||||
|
(declaration_command
|
||||||
|
(word)
|
||||||
|
(variable_name)))
|
||||||
|
|
||||||
|
=========================================
|
||||||
|
Variable declaration: export
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
export PATH
|
||||||
|
export FOOBAR PATH="$PATH:/usr/foobar/bin"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(declaration_command (variable_name))
|
||||||
|
(declaration_command
|
||||||
|
(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)))))
|
||||||
|
|
||||||
|
=========================================
|
||||||
|
Unset commands
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
unset A
|
||||||
|
unset "$variable_name"
|
||||||
|
unsetenv -f ONE TWO
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(unset_command (variable_name))
|
||||||
|
(unset_command (string (simple_expansion (variable_name))))
|
||||||
|
(unset_command (word) (variable_name) (variable_name)))
|
||||||
|
|
|
@ -56,6 +56,7 @@ module.exports = grammar({
|
||||||
$.variable_assignment,
|
$.variable_assignment,
|
||||||
$.command,
|
$.command,
|
||||||
$.declaration_command,
|
$.declaration_command,
|
||||||
|
$.unset_command,
|
||||||
$.bracket_command,
|
$.bracket_command,
|
||||||
$.for_statement,
|
$.for_statement,
|
||||||
$.while_statement,
|
$.while_statement,
|
||||||
|
@ -229,6 +230,14 @@ module.exports = grammar({
|
||||||
))
|
))
|
||||||
)),
|
)),
|
||||||
|
|
||||||
|
unset_command: $ => prec.left(seq(
|
||||||
|
choice('unset', 'unsetenv'),
|
||||||
|
repeat(choice(
|
||||||
|
$._expression,
|
||||||
|
$._simple_variable_name
|
||||||
|
))
|
||||||
|
)),
|
||||||
|
|
||||||
_assignment: $ => seq(
|
_assignment: $ => seq(
|
||||||
choice(
|
choice(
|
||||||
'=',
|
'=',
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "declaration_command"
|
"name": "declaration_command"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "unset_command"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "bracket_command"
|
"name": "bracket_command"
|
||||||
|
@ -832,6 +836,44 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"unset_command": {
|
||||||
|
"type": "PREC_LEFT",
|
||||||
|
"value": 0,
|
||||||
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "unset"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "unsetenv"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_simple_variable_name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"_assignment": {
|
"_assignment": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue