Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
Date: Sun, 29 May 2011 11:20:15
Message-Id: 4fbd4e219d4c36de28036e02ba616d7faa43e066.betelgeuse@gentoo
1 commit: 4fbd4e219d4c36de28036e02ba616d7faa43e066
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 27 13:44:07 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=4fbd4e21
7
8 Walker: support continue in for loop
9
10 A bug in seek_to_next_tree is fixed. This bug can only be reproduced
11 by c-style for loop. It prevents the c-style for loop from working
12 properly when a modification statement is specified.
13
14 ---
15 bashast/libbashWalker.g | 53 ++++++++++++++++++++++++++++------
16 scripts/compound_command.bash | 19 ++++++++++++
17 scripts/compound_command.bash.result | 8 ++++-
18 3 files changed, 70 insertions(+), 10 deletions(-)
19
20 diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
21 index d5522fc..39b84c5 100644
22 --- a/bashast/libbashWalker.g
23 +++ b/bashast/libbashWalker.g
24 @@ -71,12 +71,13 @@ options
25 // seek to LT(2) and consume
26 static void seek_to_next_tree(plibbashWalker ctx)
27 {
28 - // We start from LA(1)
29 - int index = 1;
30 // Current depth of the tree we are traversing
31 int depth = 1;
32
33 - for(index = 1; depth != 0; ++index)
34 + // The beginning should always be ROOT DOWN ANY_TOKEN
35 + // So we start from LA(4)
36 + int index = 4;
37 + for(; depth != 0; ++index)
38 {
39 // Go one level done if we encounter DOWN
40 if(LA(index) == DOWN)
41 @@ -87,7 +88,7 @@ options
42 }
43
44 // Seek to the correct offset and consume.
45 - SEEK(INDEX() + index - 3);
46 + SEEK(INDEX() + index - 2);
47 CONSUME();
48 }
49
50 @@ -614,7 +615,15 @@ for_expr
51 {
52 SEEK(commands_index);
53 walker->set_value(libbash_string, *iter);
54 - command_list(ctx);
55 + try
56 + {
57 + command_list(ctx);
58 + }
59 + catch(continue_exception& e)
60 + {
61 + e.rethrow_unless_correct_frame();
62 + continue;
63 + }
64 }
65 })
66 |^(CFOR {
67 @@ -625,11 +634,37 @@ for_expr
68 for_initilization(ctx);
69
70 condition_index = INDEX();
71 - bool has_condition = (LA(1) != FOR_COND);
72 - while(has_condition || for_condition(ctx))
73 + bool has_condition = (LA(1) == FOR_COND);
74 +
75 + if(has_condition)
76 + seek_to_next_tree(ctx);
77 + // before the body
78 + seek_to_next_tree(ctx);
79 + bool has_modification = (LA(1) == FOR_MOD);
80 + ANTLR3_MARKER modification_index = INDEX();
81 +
82 + SEEK(condition_index);
83 +
84 + while(!has_condition || for_condition(ctx))
85 {
86 - command_list(ctx);
87 - if(LA(1) == FOR_MOD)
88 + try
89 + {
90 + command_list(ctx);
91 + }
92 + catch(continue_exception& e)
93 + {
94 + e.rethrow_unless_correct_frame();
95 +
96 + if(has_modification)
97 + {
98 + SEEK(modification_index);
99 + for_modification(ctx);
100 + }
101 +
102 + SEEK(condition_index);
103 + continue;
104 + }
105 + if(has_modification)
106 for_modification(ctx);
107 SEEK(condition_index);
108 }
109
110 diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
111 index daeef24..bb7961c 100644
112 --- a/scripts/compound_command.bash
113 +++ b/scripts/compound_command.bash
114 @@ -23,6 +23,25 @@ do
115 echo "Shouldn't print this"
116 done
117
118 +for file in foo bar
119 +do
120 + if [[ $file == "foo" ]]; then
121 + continue
122 + fi
123 + echo $file
124 +done
125 +
126 +for outer in 1 2 3
127 +do
128 + for file in foo bar
129 + do
130 + if [[ $file == "foo" && $outer == 1 ]]; then
131 + continue 2
132 + fi
133 + echo "$outer $file"
134 + done
135 +done
136 +
137 i=0;
138 while [ $i != 4 ]
139 do
140
141 diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
142 index 2a23d0c..6014421 100644
143 --- a/scripts/compound_command.bash.result
144 +++ b/scripts/compound_command.bash.result
145 @@ -11,6 +11,11 @@ ghi
146 8
147 9
148 10
149 +bar
150 +2 foo
151 +2 bar
152 +3 foo
153 +3 bar
154 1
155 2
156 3
157 @@ -37,7 +42,8 @@ yep
158 case end
159 a=1
160 b=2
161 -file= foo bar
162 +file=bar
163 foo=ghi
164 i=4
165 +outer=3
166 target=_