1 |
commit: 4f4eff53b4ad98e386010f7d9717c3192954a0dc |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 27 14:22:01 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun May 29 11:44:52 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4f4eff53 |
7 |
|
8 |
Walker: support continue in while and until loop |
9 |
|
10 |
--- |
11 |
bashast/libbashWalker.g | 11 ++++++- |
12 |
scripts/compound_command.bash | 52 ++++++++++++++++++++++++++++++++++ |
13 |
scripts/compound_command.bash.result | 9 ++++++ |
14 |
3 files changed, 71 insertions(+), 1 deletions(-) |
15 |
|
16 |
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g |
17 |
index f2fba4a..5c8c371 100644 |
18 |
--- a/bashast/libbashWalker.g |
19 |
+++ b/bashast/libbashWalker.g |
20 |
@@ -703,7 +703,16 @@ while_expr |
21 |
command_list(ctx); |
22 |
if(walker->get_status() == (negate? 0 : 1)) |
23 |
break; |
24 |
- command_list(ctx); |
25 |
+ try |
26 |
+ { |
27 |
+ command_list(ctx); |
28 |
+ } |
29 |
+ catch(continue_exception& e) |
30 |
+ { |
31 |
+ e.rethrow_unless_correct_frame(); |
32 |
+ SEEK(condition_index); |
33 |
+ continue; |
34 |
+ } |
35 |
SEEK(condition_index); |
36 |
} |
37 |
// Skip the body and get out |
38 |
|
39 |
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash |
40 |
index bb7961c..a81e395 100644 |
41 |
--- a/scripts/compound_command.bash |
42 |
+++ b/scripts/compound_command.bash |
43 |
@@ -54,6 +54,32 @@ do |
44 |
echo "Shouldn't print this" |
45 |
done |
46 |
|
47 |
+i=0 |
48 |
+while [ $i != 4 ] |
49 |
+do |
50 |
+ i=$(( i + 1 )) |
51 |
+ if [[ $i == 1 ]]; then |
52 |
+ continue |
53 |
+ fi |
54 |
+ echo $i |
55 |
+done |
56 |
+ |
57 |
+i=0 |
58 |
+j=1 |
59 |
+while [ $i != 4 ] |
60 |
+do |
61 |
+ i=$(( i + 1 )) |
62 |
+ |
63 |
+ while [ $j == 1 ] |
64 |
+ do |
65 |
+ if [[ $i == 1 ]]; then |
66 |
+ continue 2 |
67 |
+ fi |
68 |
+ echo $i |
69 |
+ let ++j |
70 |
+ done |
71 |
+done |
72 |
+ |
73 |
i=0; |
74 |
until [ $i == 4 ] |
75 |
do |
76 |
@@ -66,6 +92,32 @@ do |
77 |
echo "Shouldn't print this" |
78 |
done |
79 |
|
80 |
+i=0 |
81 |
+until [ $i == 4 ] |
82 |
+do |
83 |
+ i=$(( i + 1 )) |
84 |
+ if [[ $i == 1 ]]; then |
85 |
+ continue |
86 |
+ fi |
87 |
+ echo $i |
88 |
+done |
89 |
+ |
90 |
+i=0 |
91 |
+j=1 |
92 |
+until [ $i == 4 ] |
93 |
+do |
94 |
+ i=$(( i + 1 )) |
95 |
+ |
96 |
+ while [ $j == 1 ] |
97 |
+ do |
98 |
+ if [[ $i == 1 ]]; then |
99 |
+ continue 2 |
100 |
+ fi |
101 |
+ echo $i |
102 |
+ let ++j |
103 |
+ done |
104 |
+done |
105 |
+ |
106 |
a=1 |
107 |
b=2 |
108 |
if [ $a == $b ] |
109 |
|
110 |
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result |
111 |
index 6014421..0450c8f 100644 |
112 |
--- a/scripts/compound_command.bash.result |
113 |
+++ b/scripts/compound_command.bash.result |
114 |
@@ -20,10 +20,18 @@ bar |
115 |
2 |
116 |
3 |
117 |
4 |
118 |
+2 |
119 |
+3 |
120 |
+4 |
121 |
+2 |
122 |
1 |
123 |
2 |
124 |
3 |
125 |
4 |
126 |
+2 |
127 |
+3 |
128 |
+4 |
129 |
+2 |
130 |
1 |
131 |
2 |
132 |
1 |
133 |
@@ -45,5 +53,6 @@ b=2 |
134 |
file=bar |
135 |
foo=ghi |
136 |
i=4 |
137 |
+j=2 |
138 |
outer=3 |
139 |
target=_ |