From ffe3e0e425f86df2adbf151a3f052846bacd2155 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 25 Apr 2017 11:57:21 +0200 Subject: [PATCH] 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. --- applications/test/dictionary/testSubkeyword | 7 ++++--- src/OpenFOAM/db/dictionary/dictionary.C | 2 +- src/OpenFOAM/db/dictionary/dictionary.H | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/applications/test/dictionary/testSubkeyword b/applications/test/dictionary/testSubkeyword index 665fc1978a..f8ee148501 100644 --- a/applications/test/dictionary/testSubkeyword +++ b/applications/test/dictionary/testSubkeyword @@ -34,15 +34,16 @@ update key2 $key1; key3 val3; key2b ${..key2}; - key3b ${:key1}; + key3b $^key1; } } $update -key3 ${:subdict.key1}; -key3 ${:update.subdict.key3}; +// Can a leading '^' or ':' as anchor for scoping +key3 $^subdict.key1; +key3 ${^update.subdict.key3}; key4 ${:update.subdict...subdict.key1}; // This is currently not working diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 07c2eb4b2d..08c702fee3 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -575,7 +575,7 @@ const Foam::entry* Foam::dictionary::lookupScopedEntryPtr bool patternMatch ) const { - if (keyword[0] == ':') + if (keyword[0] == ':' || keyword[0] == '^') { // Go up to top level const dictionary* dictPtr = this; diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 8083f169df..a2031ede03 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -43,7 +43,7 @@ Note Within dictionaries, entries can be referenced by using the '$' syntax familiar from shell programming. A '.' separator is used when referencing 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, \verbatim @@ -62,7 +62,7 @@ Note } } - key4 $:subdict1.subdict2.key3; + key4 $^subdict1.subdict2.key3; // lookup with absolute scoping \endverbatim It is also possible to use the '${}' syntax for clarity.