1 |
commit: ea40bc721b3926876dcde99289865c5f023ee0e2 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 6 06:50:49 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri May 6 06:54:52 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ea40bc72 |
7 |
|
8 |
Walker: support logical command list |
9 |
|
10 |
&& and || operators are supported for command list. |
11 |
|
12 |
--- |
13 |
bashast/libbashWalker.g | 11 +++++++++-- |
14 |
scripts/command_execution.bash | 5 +++++ |
15 |
scripts/command_execution.bash.result | 3 +++ |
16 |
3 files changed, 17 insertions(+), 2 deletions(-) |
17 |
|
18 |
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g |
19 |
index 203cd28..064556a 100644 |
20 |
--- a/bashast/libbashWalker.g |
21 |
+++ b/bashast/libbashWalker.g |
22 |
@@ -310,9 +310,16 @@ argument[std::vector<std::string>& args] |
23 |
}; |
24 |
|
25 |
logic_command_list |
26 |
+@declarations { |
27 |
+ bool logic_and; |
28 |
+} |
29 |
:command |
30 |
- |^(LOGICAND command command) |
31 |
- |^(LOGICOR command command); |
32 |
+ |^((LOGICAND { logic_and = true; } | LOGICOR { logic_and = false; }) command { |
33 |
+ if(logic_and ? !walker->get_status() : walker->get_status()) |
34 |
+ command(ctx); |
35 |
+ else |
36 |
+ seek_to_next_tree(ctx); |
37 |
+ }); |
38 |
|
39 |
command_list: ^(LIST logic_command_list+); |
40 |
|
41 |
|
42 |
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash |
43 |
index 0f7cd03..3664356 100644 |
44 |
--- a/scripts/command_execution.bash |
45 |
+++ b/scripts/command_execution.bash |
46 |
@@ -8,3 +8,8 @@ true |
47 |
false |
48 |
FOO001=$(echo hello) |
49 |
FOO002=$(hi) |
50 |
+true && echo "right" |
51 |
+false && echo "wrong" |
52 |
+false || echo "right" |
53 |
+true || echo "wrong" |
54 |
+echo "end" |
55 |
|
56 |
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result |
57 |
index 4330a65..d9f3021 100644 |
58 |
--- a/scripts/command_execution.bash.result |
59 |
+++ b/scripts/command_execution.bash.result |
60 |
@@ -1,4 +1,7 @@ |
61 |
Hello World |
62 |
hello world |
63 |
+right |
64 |
+right |
65 |
+end |
66 |
FOO001=hello |
67 |
FOO002=Hello World |