diff options
author | 2011-07-22 16:48:08 +0800 | |
---|---|---|
committer | 2011-08-02 15:46:29 +0800 | |
commit | 93de5730f17b88b96974ed4712ca32d815daf3a4 (patch) | |
tree | eac6dc79f5dc9b7a5c1384680876907ef26c5f8a | |
parent | Parser: remove tokens for assignment (diff) | |
download | libbash-93de5730f17b88b96974ed4712ca32d815daf3a4.tar.gz libbash-93de5730f17b88b96974ed4712ca32d815daf3a4.tar.bz2 libbash-93de5730f17b88b96974ed4712ca32d815daf3a4.zip |
Parser&Walker: support escaped characters in string
-rw-r--r-- | bashast/bashast.g | 2 | ||||
-rw-r--r-- | bashast/gunit/fname.gunit | 1 | ||||
-rw-r--r-- | bashast/libbashWalker.g | 9 | ||||
-rw-r--r-- | scripts/command_execution.bash | 1 |
4 files changed, 12 insertions, 1 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index 7351a56..d55a392 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -685,6 +685,8 @@ ns_string_part : num|name|escaped_character |OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR |TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT + // Escaped characters + |ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK // The following is for filename expansion |TIMES|QMARK; diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit index 3d60bc2..9ac0b25 100644 --- a/bashast/gunit/fname.gunit +++ b/bashast/gunit/fname.gunit @@ -48,6 +48,7 @@ string_expr: "--preserve=timestamps,mode" -> (STRING - - preserve = timestamps , mode) "$'asdf'" -> (STRING (ANSI_C_QUOTING 'asdf')) "\"abc#$/\"" -> (STRING (DOUBLE_QUOTED_STRING abc # $ /)) +"\`\(\)\$\>\<" -> (STRING \` \( \) \$ \> \<) condition_expr: // bracket patterns diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 25bfcb2..f4ebaaf 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -422,10 +422,17 @@ double_quoted_string returns[std::string libbash_value] |libbash_string=any_string { $libbash_value = libbash_string; }; any_string returns[std::string libbash_value] +options {backtrack = true;} @declarations { pANTLR3_BASE_TREE any_token; } - :any_token=. { $libbash_value = get_string(any_token); }; + :ESC_RPAREN { $libbash_value = ")"; } + |ESC_LPAREN { $libbash_value = "("; } + |ESC_DOLLAR { $libbash_value = "$"; } + |ESC_GT { $libbash_value = ">"; } + |ESC_LT { $libbash_value = "<"; } + |ESC_TICK { $libbash_value = "`"; } + |any_token=. { $libbash_value = get_string(any_token); }; //Allowable variable names in the variable expansion var_name returns[std::string libbash_value, unsigned index] diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash index 017d3af..add4145 100644 --- a/scripts/command_execution.bash +++ b/scripts/command_execution.bash @@ -72,3 +72,4 @@ echo ${array[@]} ech\ o Hello\ world +echo \`\(\)\$\>\<\` |