From cc290b7c02d2191008d11b1b842673497fad158c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 19 Jul 2017 11:00:44 +0200 Subject: [PATCH] ENH: improve dictionary parsing behaviour for ill-formed entries (closes #510) - mostly associated with forgotten quotes around "(abd|def)" ... - Address different potential problems: (key) { key1 entry1; } (key) { key1 entry1; }; // <- Note trailing ';' (key) entry2; --- applications/test/dictionary/testDictList | 54 +++++++++++++++++++ .../dictionaryListEntryIO.C | 12 +++-- src/OpenFOAM/db/dictionary/entry/entryIO.C | 34 ++++++------ 3 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 applications/test/dictionary/testDictList diff --git a/applications/test/dictionary/testDictList b/applications/test/dictionary/testDictList new file mode 100644 index 0000000000..d0e1171bc1 --- /dev/null +++ b/applications/test/dictionary/testDictList @@ -0,0 +1,54 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: plus | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object testDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Test some parsing + +// #default +internalField uniform 10; +// #default +dimensions [ 0 2 -2 0 0 0 0 ]; + +active +{ + type turbulentIntensityKineticEnergyInlet; + intensity 0.1; + value $internalField; +} + +// #inputMode error +active +{ + type turbulentIntensityKineticEnergyInlet; + intensity 0.1; + value 100; +} + +(U|k|epsilon|omega) +{ + solver smoothSolver; + smoother symGaussSeidel; + tolerance 1e-6; + relTol 0; +} +/* +; + */ + +(rho) smoothSolver + +//OK smoothSolver // <- missing ';' as well + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C index 5043a206c2..c368e68035 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C @@ -60,11 +60,11 @@ Foam::dictionaryListEntry::dictionaryListEntry token firstToken(is); if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label sz = firstToken.labelToken(); is.readBeginList("List"); - for (label i=0; i Foam::entry::New(Istream& is) { is.fatalCheck(FUNCTION_NAME); - keyType keyword; + autoPtr ptr(nullptr); // Get the next keyword and if invalid return false - if (!getKeyword(keyword, is)) - { - return autoPtr(nullptr); - } - else // Keyword starts entry ... + keyType keyword; + if (getKeyword(keyword, is)) { + // Keyword starts entry ... token nextToken(is); is.putBack(nextToken); if (nextToken == token::BEGIN_BLOCK) { - return autoPtr - ( - new dictionaryEntry(keyword, dictionary::null, is) - ); + // A sub-dictionary + ptr.reset(new dictionaryEntry(keyword, dictionary::null, is)); } else { - return autoPtr - ( - new primitiveEntry(keyword, is) - ); + ptr.reset(new primitiveEntry(keyword, is)); } } + + return ptr; }