mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
54
applications/test/dictionary/testDictList
Normal file
54
applications/test/dictionary/testDictList
Normal 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
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user