From c5a116f1794e061ea10335b12c6889676d92136b Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Thu, 21 Jul 2011 17:08:33 +0800 Subject: Parser: allow empty value for sub-array expansion Expansion like ${var::3} is allowed now. --- bashast/bashast.g | 9 +++++++-- bashast/gunit/param_main.gunit | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index 14d7d10..7bb8a8b 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -724,8 +724,13 @@ parameter_expansion ( (parameter_value_operator) => parameter_value_operator parameter_expansion_value -> ^(parameter_value_operator variable_name parameter_expansion_value) - | COLON BLANK? os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)? - -> ^(OFFSET variable_name $os ^($len)?) + | COLON BLANK? + ( + os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)? + -> ^(OFFSET variable_name $os ^($len)?) + | COLON BLANK? len=explicit_arithmetic + -> ^(OFFSET variable_name NUMBER["0"] ^($len)?) + ) | parameter_delete_operator parameter_delete_pattern -> ^(parameter_delete_operator variable_name parameter_delete_pattern) | parameter_replace_operator parameter_replace_pattern (SLASH parameter_expansion_value)? diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit index 677b566..306d3c6 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -29,6 +29,7 @@ variable_reference: "${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10))) "${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5))) "${foo:5:2}" -> (VAR_REF (OFFSET foo 5 2)) +"${foo::2}" -> (VAR_REF (OFFSET foo 0 2)) "${foo:$((5)):$((2))}" -> (VAR_REF (OFFSET foo 5 2)) "${!asdf*}" -> (VAR_REF (! asdf *)) "${!asdf@}" -> (VAR_REF (! asdf @)) -- cgit v1.2.3-65-gdbad