diff options
author | André Aparício <aparicio99@gmail.com> | 2012-07-03 00:20:05 +0100 |
---|---|---|
committer | Petteri Räty <petsku@petteriraty.eu> | 2012-07-08 12:38:47 +0300 |
commit | 3d70950f61980d0268356124b9cc4753dfd6265e (patch) | |
tree | 2b7dc82f3614ebc183c74ae1d0e0519c3a070ce7 | |
parent | Utils: Upgrade instruo to work with paludis 0.74.1 (diff) | |
download | libbash-3d70950f61980d0268356124b9cc4753dfd6265e.tar.gz libbash-3d70950f61980d0268356124b9cc4753dfd6265e.tar.bz2 libbash-3d70950f61980d0268356124b9cc4753dfd6265e.zip |
Parser&Walker: Support for loop without list
-rw-r--r-- | bashast/bashast.g | 8 | ||||
-rw-r--r-- | bashast/libbashWalker.g | 10 | ||||
-rw-r--r-- | 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<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 |