1 |
commit: 3d70950f61980d0268356124b9cc4753dfd6265e |
2 |
Author: André Aparício <aparicio99 <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Jul 2 23:20:05 2012 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jul 8 09:38:47 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3d70950f |
7 |
|
8 |
Parser&Walker: Support for loop without list |
9 |
|
10 |
--- |
11 |
bashast/bashast.g | 8 ++++---- |
12 |
bashast/libbashWalker.g | 10 +++++++--- |
13 |
scripts/compound_command.bash | 12 ++++++++++++ |
14 |
3 files changed, 23 insertions(+), 7 deletions(-) |
15 |
|
16 |
diff --git a/bashast/bashast.g b/bashast/bashast.g |
17 |
index f7ce358..e2702d0 100644 |
18 |
--- a/bashast/bashast.g |
19 |
+++ b/bashast/bashast.g |
20 |
@@ -530,11 +530,11 @@ semiel |
21 |
for_expr |
22 |
: FOR BLANK? |
23 |
( |
24 |
- name wspace |
25 |
+ name |
26 |
( |
27 |
- IN for_each_value* BLANK? (SEMIC|EOL) wspace? |
28 |
- |SEMIC wspace? |
29 |
- | |
30 |
+ wspace IN for_each_value* BLANK? (SEMIC|EOL) wspace? |
31 |
+ | wspace? SEMIC wspace? |
32 |
+ | wspace |
33 |
) DO wspace command_list semiel DONE -> ^(FOR name for_each_value* command_list) |
34 |
| LLPAREN EOL? |
35 |
// initilization |
36 |
|
37 |
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g |
38 |
index 0c21ccd..648dd53 100644 |
39 |
--- a/bashast/libbashWalker.g |
40 |
+++ b/bashast/libbashWalker.g |
41 |
@@ -842,11 +842,11 @@ for_expr |
42 |
@declarations { |
43 |
ANTLR3_MARKER commands_index; |
44 |
std::vector<std::string> splitted_values; |
45 |
+ bool in_array = false; |
46 |
|
47 |
ANTLR3_MARKER condition_index; |
48 |
} |
49 |
:^(FOR libbash_string=name_base |
50 |
- // Empty value as $@ is not supported currently |
51 |
(string_expr |
52 |
{ |
53 |
// Word splitting happens here |
54 |
@@ -854,10 +854,11 @@ for_expr |
55 |
splitted_values.push_back($string_expr.libbash_value); |
56 |
else |
57 |
walker->split_word($string_expr.libbash_value, splitted_values); |
58 |
+ in_array = true; |
59 |
} |
60 |
- )+ |
61 |
+ )* |
62 |
{ |
63 |
- if(splitted_values.empty()) |
64 |
+ if(splitted_values.empty() && in_array) |
65 |
{ |
66 |
//skip the body |
67 |
seek_to_next_tree(ctx); |
68 |
@@ -865,6 +866,9 @@ for_expr |
69 |
} |
70 |
else |
71 |
{ |
72 |
+ if(!in_array) |
73 |
+ walker->resolve_array<std::string>("*", splitted_values); |
74 |
+ |
75 |
commands_index = INDEX(); |
76 |
for(auto iter = splitted_values.begin(); iter != splitted_values.end(); ++iter) |
77 |
{ |
78 |
|
79 |
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash |
80 |
index 36161fe..fe3eac4 100644 |
81 |
--- a/scripts/compound_command.bash |
82 |
+++ b/scripts/compound_command.bash |
83 |
@@ -84,6 +84,18 @@ do |
84 |
done |
85 |
done |
86 |
|
87 |
+function positional_for() |
88 |
+{ |
89 |
+ for arg; do |
90 |
+ echo $arg |
91 |
+ done |
92 |
+ |
93 |
+ for arg do |
94 |
+ echo $arg |
95 |
+ done |
96 |
+} |
97 |
+positional_for foo bar |
98 |
+ |
99 |
i=0; |
100 |
while [ $i != 4 ] |
101 |
do |