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 :
This commit is contained in:
Kelvin Sherlock 2015-02-08 14:49:08 -05:00
parent 9fda034e0e
commit 42fe265dd2
2 changed files with 32 additions and 5 deletions

View File

@ -82,6 +82,20 @@ namespace {
%%{ %%{
machine variables; machine variables;
coalesce_colon := |*
':' {
if (rv.length() && rv.back() != ':')
rv.push_back(':');
fgoto main;
};
any {
fhold;
fgoto main;
};
*|;
main := |* main := |*
'{' [A-Za-z0-9_]+ '}' { '{' [A-Za-z0-9_]+ '}' {
@ -90,15 +104,23 @@ namespace {
auto iter = Environment.find(name); auto iter = Environment.find(name);
if (iter != Environment.end()) if (iter != Environment.end())
rv.append(iter->second); rv.append(iter->second);
fgoto coalesce_colon;
}; };
# backwards compatibility. # backwards compatibility.
'${' [A-Za-z0-9_]+ '}' { '${' [A-Za-z0-9_]+ '}' {
std::string name(ts + 2, te - 1); if (pathname) {
auto iter = Environment.find(name); rv.append(ts, te);
if (iter != Environment.end()) } else {
rv.append(iter->second); 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. # backwards compatibility.
@ -112,6 +134,8 @@ namespace {
auto iter = Environment.find(name); auto iter = Environment.find(name);
if (iter != Environment.end()) if (iter != Environment.end())
rv.append(iter->second); rv.append(iter->second);
fgoto coalesce_colon;
} }
}; };

View File

@ -4,7 +4,10 @@
# $MPW uses MacOS : paths. # $MPW uses MacOS : paths.
# #
# $MPW includes the trailing ':'. # $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) # = assigns (replacing any existing value)
# ?= will not replace an existing value. # ?= will not replace an existing value.