aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2012-03-01 11:32:09 +0800
committerMu Qiao <qiaomuf@gentoo.org>2012-03-01 11:32:09 +0800
commitc444c4bb2952b3b95269a9f7e05d730c2df50670 (patch)
tree8f095b7fee121330eee26815ea08a4c656d16639 /bashast
parentParser: allow double quotes in arithmetic expression (diff)
downloadlibbash-c444c4bb2952b3b95269a9f7e05d730c2df50670.tar.gz
libbash-c444c4bb2952b3b95269a9f7e05d730c2df50670.tar.bz2
libbash-c444c4bb2952b3b95269a9f7e05d730c2df50670.zip
Parser: support indirect ref in parameter expansion
Diffstat (limited to 'bashast')
-rw-r--r--bashast/gunit/param_main.gunit3
-rw-r--r--bashast/libbashWalker.g15
2 files changed, 18 insertions, 0 deletions
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 4e30458..01ec853 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -87,6 +87,9 @@ variable_reference:
"${#$}" -> (VAR_REF (# $))
"${a/=}" -> (VAR_REF (REPLACE_FIRST a (STRING =)))
"${a%=}" -> (VAR_REF (LAZY_REMOVE_AT_END a (STRING =)))
+"${!#/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF #) (STRING a) (STRING bc)))
+"${!abc/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF abc) (STRING a) (STRING bc)))
+"${!123/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF 123) (STRING a) (STRING bc)))
variable_definition_atom:
"MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 9b2281d..67a39fc 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -447,10 +447,25 @@ var_name returns[std::string libbash_value, unsigned index]
$libbash_value = $name.libbash_value;
$index = $name.index;
}
+ |^(VAR_REF libbash_string=var_name_for_bang) {
+ $libbash_value = walker->resolve<std::string>(libbash_string);
+ }
+ |^(VAR_REF POUND) { // for ${!#}
+ int index = walker->get_array_length("*");
+ $libbash_value = (index != 0 ? "*" : "0");
+ }
|MINUS {
$libbash_value = "-";
};
+var_name_for_bang returns[std::string libbash_value]
+ :libbash_string=num {
+ $libbash_value = libbash_string;
+ }
+ |name {
+ $libbash_value = $name.libbash_value;
+ };
+
array_name returns[std::string libbash_value]
:^(ARRAY name (AT|TIMES)) { $libbash_value = $name.libbash_value; }
// We do not care the difference between TIMES and AT for now