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)))
(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 Variable expansions in strings
=================================== ===================================

View File

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