From 49facd905dadf5bae1b33362686d1d02be80a5fe Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Thu, 23 Feb 2012 11:26:29 +0800 Subject: Walker: support shortcut in keyword test --- bashast/libbashWalker.g | 16 ++++++++++++++-- scripts/test_expr.bash | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index bfcb73b..e357642 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -763,8 +763,20 @@ common_condition returns[bool status] |string_expr { $status = (!$string_expr.libbash_value.empty()); }; keyword_condition returns[bool status] - :^(LOGICOR l=keyword_condition r=keyword_condition) { $status= l || r; } - |^(LOGICAND l=keyword_condition r=keyword_condition) { $status= l && r; } + :^(LOGICOR l=keyword_condition { + if(l){ + seek_to_next_tree(ctx); + SEEK(INDEX() + 1); + return true; + } + } r=keyword_condition) { $status= l || r; } + |^(LOGICAND l=keyword_condition { + if(!l){ + seek_to_next_tree(ctx); + SEEK(INDEX() + 1); + return false; + } + } r=keyword_condition) { $status= l && r; } |^(NEGATION l=keyword_condition) { $status = !l; } |^(MATCH_REGULAR_EXPRESSION left_str=string_expr right_str=string_expr) { boost::xpressive::sregex re = boost::xpressive::sregex::compile(right_str.libbash_value); diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash index ccedb76..6ae7246 100644 --- a/scripts/test_expr.bash +++ b/scripts/test_expr.bash @@ -55,3 +55,9 @@ unset i [[ =a <=b ]] [[ =a >=b ]] [[ a == a || c == b && a == b ]] && echo true +i=1 +[[ a == b || $((i=0)) ]] && echo $i # i should be 0 now +[[ a == a || $((i=1)) ]] && echo $i # i should still be 0 +[[ a == b && $((i=1)) ]] || echo $i # i should still be 0 +i=1 +[[ a == a && $((i=0)) ]] && echo $i # i should still be 0 -- cgit v1.2.3-65-gdbad