From c8b13641610f4f6b37b15a91f9f5ff390071545e Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Mon, 26 Mar 2012 18:14:42 +0800 Subject: Parser&Walker: improve escaped double quote handling --- bashast/bashast.g | 3 ++- bashast/gunit/fname.gunit | 2 +- bashast/libbashWalker.g | 1 + scripts/command_execution.bash | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index c836047..f7ce358 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -784,7 +784,7 @@ ns_string_part |OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON |TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT // Escaped characters - |ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK + |ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK|ESC_DQUOTE // The following is for filename expansion |TIMES|QMARK; @@ -1126,6 +1126,7 @@ AMP_RSHIFT : '&>>'; SEMIC : ';'; DOUBLE_SEMIC : ';;'; PIPE : '|'; +ESC_DQUOTE : '\\"'; DQUOTE : '"' { if(LA(-1) != '\\') double_quoted = !double_quoted; }; SQUOTE : { double_quoted }? => '\''; SINGLE_QUOTED_STRING_TOKEN : { !double_quoted }? => '\'' .* '\''; diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit index 9ac0b25..65bb614 100644 --- a/bashast/gunit/fname.gunit +++ b/bashast/gunit/fname.gunit @@ -77,4 +77,4 @@ condition_expr: "[[ x == ab!(gh|i) ]]" -> (KEYWORD_TEST (MATCH_PATTERN (STRING x) (STRING ab (EXTENDED_MATCH_NONE (BRANCH gh) (BRANCH i))))) double_quoted_string: -"\"\\\\\"\$\`\"" -> (DOUBLE_QUOTED_STRING \ " \$ \`) +"\"\\\\\"\$\`\"" -> (DOUBLE_QUOTED_STRING \ \" \$ \`) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 5d5b557..fb1ca55 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -446,6 +446,7 @@ options {backtrack = true;} :ESC_RPAREN { $libbash_value = ")"; } |ESC_LPAREN { $libbash_value = "("; } |ESC_DOLLAR { $libbash_value = "$"; } + |ESC_DQUOTE { $libbash_value = "\""; } |ESC_GT { $libbash_value = ">"; } |ESC_LT { $libbash_value = "<"; } |ESC_TICK { $libbash_value = "`"; } diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash index 89a0ed7..58f1279 100644 --- a/scripts/command_execution.bash +++ b/scripts/command_execution.bash @@ -89,3 +89,4 @@ echo "${!variable// /_}" echo "${!#// /_}" echo "${!1// /_}" echo "${!variable// /$'\n'}" +eval abc+=\( \"\$@\" \) -- cgit v1.2.3-65-gdbad