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;
This commit is contained in:
Mark Olesen
2017-07-19 11:00:44 +02:00
parent efe9b04adc
commit cc290b7c02
3 changed files with 82 additions and 18 deletions

View File

@ -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
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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<s; i++)
for (label i=0; i<sz; ++i)
{
entry::New(*this, is);
}
@ -79,7 +79,13 @@ Foam::dictionaryListEntry::dictionaryListEntry
while (true)
{
token nextToken(is);
if
if (nextToken.error())
{
FatalIOErrorInFunction(is)
<< "parsing error " << nextToken.info()
<< exit(FatalIOError);
}
else if
(
nextToken.isPunctuation()
&& nextToken.pToken() == token::END_LIST

View File

@ -246,6 +246,15 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
token nextToken(is);
is.putBack(nextToken);
if (nextToken == token::END_LIST)
{
FatalIOErrorInFunction(is)
<< "Unexpected token encountered for "
<< keyword << " - " << nextToken.info()
<< exit(FatalIOError);
return false;
}
// Deal with duplicate entries
bool mergeEntry = false;
@ -288,7 +297,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
else if (functionEntries::inputModeEntry::error())
{
FatalIOErrorInFunction(is)
<< "ERROR! duplicate entry: " << keyword
<< "duplicate entry: " << keyword
<< exit(FatalIOError);
return false;
@ -320,33 +329,28 @@ Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
{
is.fatalCheck(FUNCTION_NAME);
keyType keyword;
autoPtr<entry> ptr(nullptr);
// Get the next keyword and if invalid return false
if (!getKeyword(keyword, is))
{
return autoPtr<entry>(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<entry>
(
new dictionaryEntry(keyword, dictionary::null, is)
);
// A sub-dictionary
ptr.reset(new dictionaryEntry(keyword, dictionary::null, is));
}
else
{
return autoPtr<entry>
(
new primitiveEntry(keyword, is)
);
ptr.reset(new primitiveEntry(keyword, is));
}
}
return ptr;
}