1 |
commit: b921511820ee4116b4f1f2746bb90e6b859ae1c8 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Feb 23 03:24:05 2012 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Feb 23 03:27:12 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b9215118 |
7 |
|
8 |
Parser: respect operator precedence in keyword test |
9 |
|
10 |
--- |
11 |
bashast/bashast.g | 5 ++++- |
12 |
bashast/gunit/cond_main.gunit | 2 ++ |
13 |
scripts/test_expr.bash | 1 + |
14 |
3 files changed, 7 insertions(+), 1 deletions(-) |
15 |
|
16 |
diff --git a/bashast/bashast.g b/bashast/bashast.g |
17 |
index b7e0d32..b383219 100644 |
18 |
--- a/bashast/bashast.g |
19 |
+++ b/bashast/bashast.g |
20 |
@@ -597,12 +597,15 @@ condition_expr |
21 |
| {LA(1) == NAME && LA(2) == BLANK && "test".equals(get_string(LT(1)))}? => NAME wspace? builtin_condition-> ^(BUILTIN_TEST builtin_condition); |
22 |
#endif |
23 |
|
24 |
+keyword_condition_and |
25 |
+ : keyword_condition_primary (BLANK!? LOGICAND^ BLANK!? keyword_condition_primary)?; |
26 |
keyword_condition |
27 |
- : ((BANG) => keyword_negation_primary|keyword_condition_primary) (BLANK!? (LOGICOR^|LOGICAND^) BLANK!? keyword_condition)?; |
28 |
+ : keyword_condition_and (BLANK!? LOGICOR^ BLANK!? keyword_condition_and)?; |
29 |
keyword_negation_primary |
30 |
: BANG BLANK keyword_condition_primary -> ^(NEGATION keyword_condition_primary); |
31 |
keyword_condition_primary |
32 |
: LPAREN! BLANK!? keyword_condition BLANK!? RPAREN! |
33 |
+ | (BANG) => keyword_negation_primary |
34 |
| (unary_operator) => keyword_condition_unary |
35 |
| keyword_condition_binary; |
36 |
keyword_condition_unary |
37 |
|
38 |
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit |
39 |
index fbf785e..5ecd024 100644 |
40 |
--- a/bashast/gunit/cond_main.gunit |
41 |
+++ b/bashast/gunit/cond_main.gunit |
42 |
@@ -37,3 +37,5 @@ condition_expr: |
43 |
"[[ a<b ]]" -> (KEYWORD_TEST (< (STRING a) (STRING b))) |
44 |
"[[ a>b ]]" -> (KEYWORD_TEST (> (STRING a) (STRING b))) |
45 |
"[[ ${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)))) |
46 |
+"[[ 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))))) |
47 |
+"[[ 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)))) |
48 |
|
49 |
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash |
50 |
index 66ab24a..ccedb76 100644 |
51 |
--- a/scripts/test_expr.bash |
52 |
+++ b/scripts/test_expr.bash |
53 |
@@ -54,3 +54,4 @@ unset i |
54 |
[ abc = bcd -a abc = abc ] || echo true19 |
55 |
[[ =a <=b ]] |
56 |
[[ =a >=b ]] |
57 |
+[[ a == a || c == b && a == b ]] && echo true |