Distinguish unset commands from regular commands

This commit is contained in:
Max Brunsfeld 2018-03-01 10:12:10 -08:00
parent 69d64558a3
commit f33bf06de2
5 changed files with 67736 additions and 60472 deletions

View File

@ -265,83 +265,6 @@ echo "#"
(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
=========================================

View File

@ -171,3 +171,95 @@ function do_yet_another_thing {
(word)
(compound_statement (command (command_name (word)) (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)))

View File

@ -56,6 +56,7 @@ module.exports = grammar({
$.variable_assignment,
$.command,
$.declaration_command,
$.unset_command,
$.bracket_command,
$.for_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(
choice(
'=',

42
src/grammar.json vendored
View File

@ -36,6 +36,10 @@
"type": "SYMBOL",
"name": "declaration_command"
},
{
"type": "SYMBOL",
"name": "unset_command"
},
{
"type": "SYMBOL",
"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": {
"type": "SEQ",
"members": [

127988
src/parser.c vendored

File diff suppressed because it is too large Load Diff