From 3d70950f61980d0268356124b9cc4753dfd6265e Mon Sep 17 00:00:00 2001 From: André Aparício Date: Tue, 3 Jul 2012 00:20:05 +0100 Subject: Parser&Walker: Support for loop without list --- bashast/bashast.g | 8 ++++---- bashast/libbashWalker.g | 10 +++++++--- scripts/compound_command.bash | 12 ++++++++++++ 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 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("*", 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 -- cgit v1.2.3-65-gdbad