diff options
author | Mu Qiao <qiaomuf@gentoo.org> | 2012-02-23 11:24:05 +0800 |
---|---|---|
committer | Mu Qiao <qiaomuf@gentoo.org> | 2012-02-23 11:27:12 +0800 |
commit | b921511820ee4116b4f1f2746bb90e6b859ae1c8 (patch) | |
tree | 28a5cf7bbccd7f93c8e9b1888e6e7bd3bc2a830b /bashast | |
parent | Build: add more information to libbash.pc.in (diff) | |
download | libbash-b921511820ee4116b4f1f2746bb90e6b859ae1c8.tar.gz libbash-b921511820ee4116b4f1f2746bb90e6b859ae1c8.tar.bz2 libbash-b921511820ee4116b4f1f2746bb90e6b859ae1c8.zip |
Parser: respect operator precedence in keyword test
Diffstat (limited to 'bashast')
-rw-r--r-- | bashast/bashast.g | 5 | ||||
-rw-r--r-- | bashast/gunit/cond_main.gunit | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index b7e0d32..b383219 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -597,12 +597,15 @@ condition_expr | {LA(1) == NAME && LA(2) == BLANK && "test".equals(get_string(LT(1)))}? => NAME wspace? builtin_condition-> ^(BUILTIN_TEST builtin_condition); #endif +keyword_condition_and + : keyword_condition_primary (BLANK!? LOGICAND^ BLANK!? keyword_condition_primary)?; keyword_condition - : ((BANG) => keyword_negation_primary|keyword_condition_primary) (BLANK!? (LOGICOR^|LOGICAND^) BLANK!? keyword_condition)?; + : keyword_condition_and (BLANK!? LOGICOR^ BLANK!? keyword_condition_and)?; keyword_negation_primary : BANG BLANK keyword_condition_primary -> ^(NEGATION keyword_condition_primary); keyword_condition_primary : LPAREN! BLANK!? keyword_condition BLANK!? RPAREN! + | (BANG) => keyword_negation_primary | (unary_operator) => keyword_condition_unary | keyword_condition_binary; keyword_condition_unary diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit index fbf785e..5ecd024 100644 --- a/bashast/gunit/cond_main.gunit +++ b/bashast/gunit/cond_main.gunit @@ -37,3 +37,5 @@ condition_expr: "[[ a<b ]]" -> (KEYWORD_TEST (< (STRING a) (STRING b))) "[[ a>b ]]" -> (KEYWORD_TEST (> (STRING a) (STRING b))) "[[ ${VIRTUALX_REQUIRED} == always || ${VIRTUALX_REQUIRED} == test ]]" -> (KEYWORD_TEST (|| (MATCH_PATTERN (STRING (VAR_REF VIRTUALX_REQUIRED)) (STRING always)) (MATCH_PATTERN (STRING (VAR_REF VIRTUALX_REQUIRED)) (STRING test)))) +"[[ a == b || c == d && e == f ]]" -> (KEYWORD_TEST (|| (MATCH_PATTERN (STRING a) (STRING b)) (&& (MATCH_PATTERN (STRING c) (STRING d)) (MATCH_PATTERN (STRING e) (STRING f))))) +"[[ a == b && c == d || e == f ]]" -> (KEYWORD_TEST (|| (&& (MATCH_PATTERN (STRING a) (STRING b)) (MATCH_PATTERN (STRING c) (STRING d))) (MATCH_PATTERN (STRING e) (STRING f)))) |