aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bashast/bashast.g8
-rw-r--r--bashast/libbashWalker.g10
-rw-r--r--scripts/compound_command.bash12
3 files changed, 23 insertions, 7 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f7ce358..e2702d0 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -530,11 +530,11 @@ semiel
for_expr
: FOR BLANK?
(
- name wspace
+ name
(
- IN for_each_value* BLANK? (SEMIC|EOL) wspace?
- |SEMIC wspace?
- |
+ wspace IN for_each_value* BLANK? (SEMIC|EOL) wspace?
+ | wspace? SEMIC wspace?
+ | wspace
) DO wspace command_list semiel DONE -> ^(FOR name for_each_value* command_list)
| LLPAREN EOL?
// initilization
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 0c21ccd..648dd53 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -842,11 +842,11 @@ for_expr
@declarations {
ANTLR3_MARKER commands_index;
std::vector<std::string> splitted_values;
+ bool in_array = false;
ANTLR3_MARKER condition_index;
}
:^(FOR libbash_string=name_base
- // Empty value as $@ is not supported currently
(string_expr
{
// Word splitting happens here
@@ -854,10 +854,11 @@ for_expr
splitted_values.push_back($string_expr.libbash_value);
else
walker->split_word($string_expr.libbash_value, splitted_values);
+ in_array = true;
}
- )+
+ )*
{
- if(splitted_values.empty())
+ if(splitted_values.empty() && in_array)
{
//skip the body
seek_to_next_tree(ctx);
@@ -865,6 +866,9 @@ for_expr
}
else
{
+ if(!in_array)
+ walker->resolve_array<std::string>("*", splitted_values);
+
commands_index = INDEX();
for(auto iter = splitted_values.begin(); iter != splitted_values.end(); ++iter)
{
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 36161fe..fe3eac4 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -84,6 +84,18 @@ do
done
done
+function positional_for()
+{
+ for arg; do
+ echo $arg
+ done
+
+ for arg do
+ echo $arg
+ done
+}
+positional_for foo bar
+
i=0;
while [ $i != 4 ]
do