From 42fe265dd2c4e6b4689ab14eaecaeebd1820da6b Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 8 Feb 2015 14:49:08 -0500 Subject: [PATCH] Smarter handling of : after a variable. Since :: is equivalent to .. in Unix, {$PathVariable}: would expand unexpectedly if PathVariable had a trailing : (which it usually does) -- i.e., some:path:: == /some/path/.. = /some/. : after a variable will be dropped if there was already a trailing : --- mpw/environment.rl | 32 ++++++++++++++++++++++++++++---- verbatim/Environment.text | 5 ++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/mpw/environment.rl b/mpw/environment.rl index 233889e..5d79bac 100644 --- a/mpw/environment.rl +++ b/mpw/environment.rl @@ -82,6 +82,20 @@ namespace { %%{ machine variables; + coalesce_colon := |* + + ':' { + if (rv.length() && rv.back() != ':') + rv.push_back(':'); + + fgoto main; + }; + any { + fhold; + fgoto main; + }; + *|; + main := |* '{' [A-Za-z0-9_]+ '}' { @@ -90,15 +104,23 @@ namespace { auto iter = Environment.find(name); if (iter != Environment.end()) rv.append(iter->second); + + fgoto coalesce_colon; }; # backwards compatibility. '${' [A-Za-z0-9_]+ '}' { - std::string name(ts + 2, te - 1); - auto iter = Environment.find(name); - if (iter != Environment.end()) - rv.append(iter->second); + if (pathname) { + rv.append(ts, te); + } else { + std::string name(ts + 2, te - 1); + auto iter = Environment.find(name); + if (iter != Environment.end()) + rv.append(iter->second); + + fgoto coalesce_colon; + } }; # backwards compatibility. @@ -112,6 +134,8 @@ namespace { auto iter = Environment.find(name); if (iter != Environment.end()) rv.append(iter->second); + + fgoto coalesce_colon; } }; diff --git a/verbatim/Environment.text b/verbatim/Environment.text index 1c387ee..c17a3d9 100644 --- a/verbatim/Environment.text +++ b/verbatim/Environment.text @@ -4,7 +4,10 @@ # $MPW uses MacOS : paths. # # $MPW includes the trailing ':'. -#Be mindful of this since '::' is equivalent to '..' in Unix. +# Since '::' is equivalent to '..' in Unix, +# A ':'' after a variable (eg, ${MPW}:) +# will be dropped if it's duplicative. +# # # = assigns (replacing any existing value) # ?= will not replace an existing value.