diff options
author | 2012-03-01 15:51:58 +0800 | |
---|---|---|
committer | 2012-03-01 15:51:58 +0800 | |
commit | 62f2e7c112601d5bc7e7f5d042d4fce1e354865e (patch) | |
tree | 56a71efbe59dd1f2ab1e1e5348880f5f842cfc59 | |
parent | Parser: allow multiple operands in test expression (diff) | |
download | libbash-62f2e7c112601d5bc7e7f5d042d4fce1e354865e.tar.gz libbash-62f2e7c112601d5bc7e7f5d042d4fce1e354865e.tar.bz2 libbash-62f2e7c112601d5bc7e7f5d042d4fce1e354865e.zip |
Parser: allow empty replacement pattern
-rw-r--r-- | bashast/bashast.g | 3 | ||||
-rw-r--r-- | bashast/gunit/param_main.gunit | 3 | ||||
-rw-r--r-- | scripts/var_expansion.bash | 5 |
3 files changed, 10 insertions, 1 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index 8d627c4..73249ef 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -879,7 +879,8 @@ parameter_value_operator | QMARK -> DISPLAY_ERROR_WHEN_UNSET | PLUS -> USE_ALTERNATE_WHEN_UNSET; parameter_replace_pattern - : ((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+); + : (SLASH) => -> ^(STRING NAME) // Create an empty string + | ((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+); parameter_delete_pattern : parameter_pattern_part+ -> ^(STRING parameter_pattern_part+); parameter_pattern_part diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit index 01ec853..2168d54 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -90,6 +90,9 @@ variable_reference: "${!#/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF #) (STRING a) (STRING bc))) "${!abc/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF abc) (STRING a) (STRING bc))) "${!123/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF 123) (STRING a) (STRING bc))) +"${search_paths/%/${root}}" -> (VAR_REF (REPLACE_AT_END search_paths (STRING NAME) (STRING $ { root }))) +"${search_paths/#/${root}}" -> (VAR_REF (REPLACE_AT_START search_paths (STRING NAME) (STRING $ { root }))) +"${search_paths//${root}}" -> (VAR_REF (REPLACE_ALL search_paths (STRING (VAR_REF root)))) variable_definition_atom: "MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -))))) diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash index 5f0bfca..e78ac8f 100644 --- a/scripts/var_expansion.bash +++ b/scripts/var_expansion.bash @@ -130,6 +130,11 @@ foo= unset bar echo ${bar=abc} +search_paths="a%#b" +root=123 +echo "${search_paths/%/${root}}" +echo "${search_paths/#/${root}}" + # This regular expression will cause boost::exception_detail::clone_impl<boost::xpressive::regex_error> #[[ "${version_components_groups}" =~ ("*".*" "|" *"|^2.*\ (2|\*)|^3.*\ (3|\*)) ]] [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]] |