diff options
author | 2011-07-22 16:33:30 +0800 | |
---|---|---|
committer | 2011-08-02 15:46:29 +0800 | |
commit | 49d89ad38496785260af3e27a7d984550b8348c5 (patch) | |
tree | e076cb3a1094ba0822717f6a5cf74c0207528d0e | |
parent | Parser: fix array size expansion (diff) | |
download | libbash-49d89ad38496785260af3e27a7d984550b8348c5.tar.gz libbash-49d89ad38496785260af3e27a7d984550b8348c5.tar.bz2 libbash-49d89ad38496785260af3e27a7d984550b8348c5.zip |
Parser: remove tokens for assignment
These tokens would prevent the parser doing parameter expansions. Now
this is fixed.
-rw-r--r-- | bashast/bashast.g | 36 | ||||
-rw-r--r-- | bashast/gunit/arith_main.gunit | 20 | ||||
-rw-r--r-- | bashast/gunit/param_main.gunit | 2 |
3 files changed, 29 insertions, 29 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index c4ab527..7351a56 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -113,6 +113,14 @@ tokens{ MINUS_SIGN; PLUS_ASSIGN; MINUS_ASSIGN; + DIVIDE_ASSIGN; + MUL_ASSIGN; + MOD_ASSIGN; + LSHIFT_ASSIGN; + RSHIFT_ASSIGN; + AND_ASSIGN; + XOR_ASSIGN; + OR_ASSIGN; NOT_EQUALS; EQUALS_TO; @@ -676,9 +684,7 @@ string_part ns_string_part : num|name|escaped_character |OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR - |TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN - |LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|LSQUARE|RSQUARE - |OR_ASSIGN|CARET|POUND|COMMA|EXPORT|LOCAL|AT + |TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT // The following is for filename expansion |TIMES|QMARK; @@ -895,16 +901,16 @@ arithmetic arithmetic_assignment_operator : {LA(1) == EQUALS && LA(2) != EQUALS}? => EQUALS - | MUL_ASSIGN - | DIVIDE_ASSIGN - | MOD_ASSIGN + | TIMES EQUALS -> MUL_ASSIGN + | SLASH EQUALS -> DIVIDE_ASSIGN + | PCT EQUALS -> MOD_ASSIGN | PLUS EQUALS -> PLUS_ASSIGN | MINUS EQUALS -> MINUS_ASSIGN - | LSHIFT_ASSIGN - | RSHIFT_ASSIGN - | AND_ASSIGN - | XOR_ASSIGN - | OR_ASSIGN; + | LSHIFT EQUALS -> LSHIFT_ASSIGN + | RSHIFT EQUALS -> RSHIFT_ASSIGN + | AMP EQUALS -> AND_ASSIGN + | CARET EQUALS -> XOR_ASSIGN + | PIPE EQUALS -> OR_ASSIGN; arithmetic_variable_reference : variable_reference -> ^(VAR_REF variable_reference); @@ -1010,14 +1016,6 @@ LESS_THAN : '<'; GREATER_THAN : '>'; LSHIFT : '<<'; RSHIFT : '>>'; -MUL_ASSIGN : '*='; -DIVIDE_ASSIGN : '/='; -MOD_ASSIGN : '%='; -LSHIFT_ASSIGN : '<<='; -RSHIFT_ASSIGN : '>>='; -AND_ASSIGN : '&='; -XOR_ASSIGN : '^='; -OR_ASSIGN : '|='; SEMIC : ';'; DOUBLE_SEMIC : ';;'; diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit index c32ff21..7620fd7 100644 --- a/bashast/gunit/arith_main.gunit +++ b/bashast/gunit/arith_main.gunit @@ -106,18 +106,18 @@ arithmetics_test: "foo=5+3" -> (= foo (+ 5 3)) "foo[5]=5+3" -> (= (foo 5) (+ 5 3)) "${foo[5]}=3" -> (= (VAR_REF (VAR_REF (foo 5))) 3) -"${foo[5]}*=3" -> (*= (VAR_REF (VAR_REF (foo 5))) 3) -"${foo[5]}^=3" -> (^= (VAR_REF (VAR_REF (foo 5))) 3) -"var *= 5" -> (*= var 5) -"var /= 5" -> (/= var 5) -"var %= 5" -> (%= var 5) +"${foo[5]}*=3" -> (MUL_ASSIGN (VAR_REF (VAR_REF (foo 5))) 3) +"${foo[5]}^=3" -> (XOR_ASSIGN (VAR_REF (VAR_REF (foo 5))) 3) +"var *= 5" -> (MUL_ASSIGN var 5) +"var /= 5" -> (DIVIDE_ASSIGN var 5) +"var %= 5" -> (MOD_ASSIGN var 5) "asdf += 5" -> (PLUS_ASSIGN asdf 5) "var -= 5" -> (MINUS_ASSIGN var 5) -"var <<= 5" -> (<<= var 5) -"var >>= 5" -> (>>= var 5) -"var &= 5" -> (&= var 5) -"var ^= 5" -> (^= var 5) -"var |= 5" -> (|= var 5) +"var <<= 5" -> (LSHIFT_ASSIGN var 5) +"var >>= 5" -> (RSHIFT_ASSIGN var 5) +"var &= 5" -> (AND_ASSIGN var 5) +"var ^= 5" -> (XOR_ASSIGN var 5) +"var |= 5" -> (OR_ASSIGN var 5) "3=7" FAIL "13"->"13" diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit index 27fc273..e73caf3 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -83,6 +83,8 @@ variable_reference: "${#*}" -> (VAR_REF (# *)) "${##}" -> (VAR_REF (# #)) "${#$}" -> (VAR_REF (# $)) +"${a/=}" -> (VAR_REF (REPLACE_FIRST a (STRING =))) +"${a%=}" -> (VAR_REF (LAZY_REMOVE_AT_END a (STRING =))) variable_definition_atom: "MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -))))) |