1 |
commit: 49facd905dadf5bae1b33362686d1d02be80a5fe |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Feb 23 03:26:29 2012 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Feb 23 03:27:18 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=49facd90 |
7 |
|
8 |
Walker: support shortcut in keyword test |
9 |
|
10 |
--- |
11 |
bashast/libbashWalker.g | 16 ++++++++++++++-- |
12 |
scripts/test_expr.bash | 6 ++++++ |
13 |
2 files changed, 20 insertions(+), 2 deletions(-) |
14 |
|
15 |
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g |
16 |
index bfcb73b..e357642 100644 |
17 |
--- a/bashast/libbashWalker.g |
18 |
+++ b/bashast/libbashWalker.g |
19 |
@@ -763,8 +763,20 @@ common_condition returns[bool status] |
20 |
|string_expr { $status = (!$string_expr.libbash_value.empty()); }; |
21 |
|
22 |
keyword_condition returns[bool status] |
23 |
- :^(LOGICOR l=keyword_condition r=keyword_condition) { $status= l || r; } |
24 |
- |^(LOGICAND l=keyword_condition r=keyword_condition) { $status= l && r; } |
25 |
+ :^(LOGICOR l=keyword_condition { |
26 |
+ if(l){ |
27 |
+ seek_to_next_tree(ctx); |
28 |
+ SEEK(INDEX() + 1); |
29 |
+ return true; |
30 |
+ } |
31 |
+ } r=keyword_condition) { $status= l || r; } |
32 |
+ |^(LOGICAND l=keyword_condition { |
33 |
+ if(!l){ |
34 |
+ seek_to_next_tree(ctx); |
35 |
+ SEEK(INDEX() + 1); |
36 |
+ return false; |
37 |
+ } |
38 |
+ } r=keyword_condition) { $status= l && r; } |
39 |
|^(NEGATION l=keyword_condition) { $status = !l; } |
40 |
|^(MATCH_REGULAR_EXPRESSION left_str=string_expr right_str=string_expr) { |
41 |
boost::xpressive::sregex re = boost::xpressive::sregex::compile(right_str.libbash_value); |
42 |
|
43 |
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash |
44 |
index ccedb76..6ae7246 100644 |
45 |
--- a/scripts/test_expr.bash |
46 |
+++ b/scripts/test_expr.bash |
47 |
@@ -55,3 +55,9 @@ unset i |
48 |
[[ =a <=b ]] |
49 |
[[ =a >=b ]] |
50 |
[[ a == a || c == b && a == b ]] && echo true |
51 |
+i=1 |
52 |
+[[ a == b || $((i=0)) ]] && echo $i # i should be 0 now |
53 |
+[[ a == a || $((i=1)) ]] && echo $i # i should still be 0 |
54 |
+[[ a == b && $((i=1)) ]] || echo $i # i should still be 0 |
55 |
+i=1 |
56 |
+[[ a == a && $((i=0)) ]] && echo $i # i should still be 0 |