ENH: allow '^' as anchor for dictionary scoping (issue #429)

- The existing ':' anchor works for rvalue substitutions
  (Eg, ${:subdict.name}), but fails for lvalues, since it is
  a punctuation token and parse stops there.
This commit is contained in:
Mark Olesen
2017-04-25 11:57:21 +02:00
parent c6bcd65dfd
commit ffe3e0e425
3 changed files with 7 additions and 6 deletions

View File

@ -34,15 +34,16 @@ update
key2 $key1; key2 $key1;
key3 val3; key3 val3;
key2b ${..key2}; key2b ${..key2};
key3b ${:key1}; key3b $^key1;
} }
} }
$update $update
key3 ${:subdict.key1}; // Can a leading '^' or ':' as anchor for scoping
key3 ${:update.subdict.key3}; key3 $^subdict.key1;
key3 ${^update.subdict.key3};
key4 ${:update.subdict...subdict.key1}; key4 ${:update.subdict...subdict.key1};
// This is currently not working // This is currently not working

View File

@ -575,7 +575,7 @@ const Foam::entry* Foam::dictionary::lookupScopedEntryPtr
bool patternMatch bool patternMatch
) const ) const
{ {
if (keyword[0] == ':') if (keyword[0] == ':' || keyword[0] == '^')
{ {
// Go up to top level // Go up to top level
const dictionary* dictPtr = this; const dictionary* dictPtr = this;

View File

@ -43,7 +43,7 @@ Note
Within dictionaries, entries can be referenced by using the '$' syntax Within dictionaries, entries can be referenced by using the '$' syntax
familiar from shell programming. A '.' separator is used when referencing familiar from shell programming. A '.' separator is used when referencing
sub-dictionary entries. Leading '.' prefixes can be used to specify sub-dictionary entries. Leading '.' prefixes can be used to specify
an entry from a parent directory. A leading ':' prefix specifies an entry from a parent directory. A leading ':' or '^' prefix specifies
starting from the top-level entry. For example, starting from the top-level entry. For example,
\verbatim \verbatim
@ -62,7 +62,7 @@ Note
} }
} }
key4 $:subdict1.subdict2.key3; key4 $^subdict1.subdict2.key3; // lookup with absolute scoping
\endverbatim \endverbatim
It is also possible to use the '${}' syntax for clarity. It is also possible to use the '${}' syntax for clarity.