aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-07-21 17:08:33 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-08-02 15:46:29 +0800
commitc5a116f1794e061ea10335b12c6889676d92136b (patch)
treef4fa085fea6888429805ba2d9db1513b7ab73540
parentParser: allow braces in command arguments (diff)
downloadlibbash-c5a116f1794e061ea10335b12c6889676d92136b.tar.gz
libbash-c5a116f1794e061ea10335b12c6889676d92136b.tar.bz2
libbash-c5a116f1794e061ea10335b12c6889676d92136b.zip
Parser: allow empty value for sub-array expansion
Expansion like ${var::3} is allowed now.
-rw-r--r--bashast/bashast.g9
-rw-r--r--bashast/gunit/param_main.gunit1
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 @))