aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-07-22 20:32:50 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-08-02 15:52:18 +0800
commitb162a7bd8490e4224ce42c417ae12ba120d681ad (patch)
treeca8f7068229ceb95a37b28f071dff666cf7767f5
parentParser: allow command name that starts with 'test' (diff)
downloadlibbash-b162a7bd8490e4224ce42c417ae12ba120d681ad.tar.gz
libbash-b162a7bd8490e4224ce42c417ae12ba120d681ad.tar.bz2
libbash-b162a7bd8490e4224ce42c417ae12ba120d681ad.zip
Parser&Walker: support nested arithmetic expansion
-rw-r--r--bashast/bashast.g3
-rw-r--r--bashast/gunit/arith_main.gunit1
-rw-r--r--bashast/libbashWalker.g1
-rw-r--r--scripts/binary_arithmetic.bash1
4 files changed, 5 insertions, 1 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g
index dd14f24..9c34478 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -874,7 +874,7 @@ commasep
: brace_expansion_part (COMMA! brace_expansion_part)+;
explicit_arithmetic
- : arithmetic_part
+ : (DOLLAR (LLPAREN|LSQUARE)) => arithmetic_part // (the predicate resolves the conflict with the primary rule)
| arithmetics;
arithmetic_expansion
@@ -921,6 +921,7 @@ primary
| command_substitution
| variable_name_no_digit -> ^(VAR_REF variable_name_no_digit)
| variable_reference
+ | arithmetic_expansion
| LPAREN! (arithmetics) RPAREN!;
pre_post_primary
: primary;
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 7620fd7..7e04dc3 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -130,6 +130,7 @@ arithmetics_test:
arithmetic_expansion:
"$((5+4, 3+2, a*b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)))
"$[1]" -> (ARITHMETIC_EXPRESSION 1)
+"$(($((1))))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC_EXPRESSION 1))
start:
"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f4ebaaf..d1bbe93 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -1201,5 +1201,6 @@ arithmetics returns[long value]
}
| NUMBER { $value = parse_integer($NUMBER);}
| DIGIT { $value = parse_integer($DIGIT);}
+ |^(ARITHMETIC_EXPRESSION l=arithmetics) { $value = l; }
| ^(VAR_REF libbash_string = var_expansion) { $value = boost::lexical_cast<long>(libbash_string); }
;
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index cac471f..c5f018c 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -69,3 +69,4 @@ echo "$((FOO059||FOO059++))"
echo "$((0&&FOO059++))"
echo "$(( 1 == 2))"
echo "$(( 1 == 1))"
+echo $(($((1))))