diff options
author | Petteri Räty <petsku@petteriraty.eu> | 2011-05-10 18:19:40 +0300 |
---|---|---|
committer | Petteri Räty <petsku@petteriraty.eu> | 2011-05-10 18:19:40 +0300 |
commit | 68d05d5b690b4ce190b7f789705efd34eb5a4a30 (patch) | |
tree | 944a50256605c5713b8c373ea642945acd385aa4 | |
parent | Merge remote-tracking branch 'mu/variable_setup' (diff) | |
download | libbash-68d05d5b690b4ce190b7f789705efd34eb5a4a30.tar.gz libbash-68d05d5b690b4ce190b7f789705efd34eb5a4a30.tar.bz2 libbash-68d05d5b690b4ce190b7f789705efd34eb5a4a30.zip |
Parser: allow white space in replacement strings
Now the parser doesn't swallow white spaces from the replacement string
in variable expansion and they get reflected properly in the AST. Fixes
bug #364119.
-rw-r--r-- | bashast/bashast.g | 4 | ||||
-rw-r--r-- | bashast/gunit/param_main.gunit | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index 51fe9a9..682d81b 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -262,7 +262,7 @@ var_exp : var_name ( -> ^(OFFSET var_name $os ^($len)?) | parameter_delete_operator parameter_pattern_part+ -> ^(parameter_delete_operator var_name ^(STRING parameter_pattern_part+)) - | parameter_replace_operator parameter_replace_pattern parameter_replace_string + | parameter_replace_operator parameter_replace_pattern (SLASH parameter_replace_string?)? -> ^(parameter_replace_operator var_name parameter_replace_pattern parameter_replace_string?) | -> var_name ) @@ -294,7 +294,7 @@ parameter_replace_pattern parameter_pattern_part : fname_part|BLANK|SEMIC; parameter_replace_string - : (SLASH fname|SLASH)? -> fname?; + : parameter_pattern_part+ -> ^(STRING parameter_pattern_part+); parameter_replace_operator : SLASH SLASH -> REPLACE_ALL | SLASH PCT -> REPLACE_AT_END diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit index 61cc140..91ed8be 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -60,6 +60,8 @@ var_ref: "${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace)))) "${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar))) "${PV/%foo/bar}" -> (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar))) +"${PN/%spaces /more }" -> (VAR_REF (REPLACE_AT_END PN (STRING spaces ) (STRING more ))) +"${PN/wrong#/#correct}" -> (VAR_REF (REPLACE_FIRST PN (STRING wrong #) (STRING # correct))) var_def: "MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -))))) |