Generalize parsing of expansion operators

This commit is contained in:
Max Brunsfeld 2018-02-28 16:28:55 -08:00
parent 86c5561ba8
commit 2a5b01b885
2 changed files with 25 additions and 8 deletions

View File

@ -66,6 +66,27 @@ echo ${abc:
(command (command_name (word)) (expansion (variable_name)))
(command (command_name (word)) (expansion (variable_name))))
===================================
Variable expansions with operators
===================================
A="${B[0]# }"
C="${D/#* -E /}"
F="${G%% *}"
---
(program
(variable_assignment
(variable_name)
(string (expansion (subscript (variable_name) (word)))))
(variable_assignment
(variable_name)
(string (expansion (variable_name) (word) (word))))
(variable_assignment
(variable_name)
(string (expansion (variable_name) (word) (word)))))
===================================
Variable expansions in strings
===================================

View File

@ -322,9 +322,7 @@ module.exports = grammar({
seq(
$.variable_name,
'=',
optional(seq(
$._expression
))
optional($._expression)
),
seq(
choice(
@ -332,11 +330,9 @@ module.exports = grammar({
$._simple_variable_name,
$._special_variable_name
),
optional(seq(
choice(':', ':?', '=', ':-', '%', '/', '-'),
optional(seq(
$._expression
))
repeat(choice(
$._expression,
':', ':?', '=', ':-', '%', '/', '-', '#'
))
),
),