Skip to content

Commit

Permalink
Merge pull request #13222 from rwcarlsen/no-empty-fieldvals
Browse files Browse the repository at this point in the history
disallow empty field values for HIT
  • Loading branch information
permcody committed Apr 16, 2019
2 parents f6d153d + 31842b4 commit 9e4f758
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 14 deletions.
17 changes: 9 additions & 8 deletions framework/contrib/hit/lex.cc
Expand Up @@ -329,7 +329,7 @@ lexEq(Lexer * l)
return lexString;
}

void
size_t
consumeUnquotedString(Lexer * l)
{
while (true)
Expand All @@ -340,6 +340,7 @@ consumeUnquotedString(Lexer * l)
break;
}
l->backup();
return l->pos() - l->start();
}

void
Expand Down Expand Up @@ -376,8 +377,8 @@ lexString(Lexer * l)

if (!charIn(l->peek(), "'\""))
{
consumeUnquotedString(l);
l->emit(TokType::String);
if (consumeUnquotedString(l))
l->emit(TokType::String);
return lexHit;
}

Expand Down Expand Up @@ -431,16 +432,16 @@ lexNumber(Lexer * l)
if (n == 0)
{
// fall back to string
consumeUnquotedString(l);
l->emit(TokType::String);
if (consumeUnquotedString(l))
l->emit(TokType::String);
return lexHit;
}

if (!charIn(l->peek(), allspace + "[") && l->peek() != '\0')
{
// fall back to string
consumeUnquotedString(l);
l->emit(TokType::String);
if (consumeUnquotedString(l))
l->emit(TokType::String);
return lexHit;
}

Expand Down Expand Up @@ -470,7 +471,7 @@ lexHit(Lexer * l)
l->emit(TokType::EOF);
return NULL;
}
return l->error("invalid character '" + std::string(1, c) + "'");
return l->error("invalid character '" + std::string(1, c) + "' - did you leave a field value blank after a previous '='?");
}

} // namespace hit
Expand Down
6 changes: 5 additions & 1 deletion framework/contrib/hit/parse.cc
Expand Up @@ -481,6 +481,10 @@ Field::render(int indent, const std::string & indent_text, int maxlen)
s += quote + unquoted.substr(pos, std::string::npos) + quote;
}
}
else if (_val.size() == 0)
s += "''";
else if (quote == "" && _val.find_first_of("\n\r \t") != std::string::npos)
s += "'" + _val + "'";
else
s += _val;

Expand Down Expand Up @@ -860,7 +864,7 @@ parseField(Parser * p, Node * n)
else if (valtok.type == TokType::Error)
p->error(valtok, valtok.val);
else
p->error(valtok, "unexpected field token type");
p->error(valtok, "missing value for field '" + fieldtok.val + "' - found '" + valtok.val + "'");
n->addChild(field);
}

Expand Down
3 changes: 3 additions & 0 deletions framework/src/outputs/formatters/InputFileFormatter.C
Expand Up @@ -128,6 +128,9 @@ InputFileFormatter::printParams(const std::string & /*prefix*/,
}
else
quotes = "";

if (value.size() == 0)
value = "(no_default)";
oss << quotes << value << quotes;
l_offset -= value.size();
}
Expand Down
2 changes: 2 additions & 0 deletions framework/src/outputs/formatters/JsonInputFileFormatter.C
Expand Up @@ -157,6 +157,8 @@ JsonInputFileFormatter::addParameters(const moosecontrib::Json::Value & params)
std::string required;
if (param["required"].asBool())
required = "(required)";
if (def.size() == 0 && required.size() == 0)
def = "(no_default)";
std::string l = name + indent + " = " + def + required;
if (l.size() > max_len)
max_len = l.size();
Expand Down
@@ -1,6 +1,6 @@
[Tests]
design = 'functional_expansion_tools/index.md'
issues = #10577
issues = '#10577'
[./interface_coupling]
type = Exodiff
input = interface_coupled.i
Expand Down
4 changes: 2 additions & 2 deletions test/tests/mesh/no_mesh_block/tests
Expand Up @@ -4,7 +4,7 @@
input = 'no_mesh_block.i'
expect_err = "No mesh file was supplied and no generation block was provided"

issues = #2408
issues = '#2408'
design = "Mesh/index.md"
requirement = "The system shall issue an error if no Mesh block is provided."
[../]
Expand All @@ -14,7 +14,7 @@
input = 'generators_no_mesh_block.i'
expect_err = "No mesh file was supplied and no generation block was provided"

issues = #2408
issues = '#2408'
design = "Mesh/index.md"
requirement = "The system shall issue an error if no Mesh block is provided even when MeshGenerators are provided."
[../]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/misc/app_name/tests
Expand Up @@ -5,7 +5,7 @@
expect_out = "MooseTestApp"
input = 'IGNORED'
input_switch = ''
issues = #11337
issues = '#11337'
design = MooseApp.md
requirement = "The compiled application shall be capable of returning the name used for registering objects."
[../]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/multiapps/time_offset/tests
Expand Up @@ -4,7 +4,7 @@
input = master.i
exodiff = master_out_sub_app0.e

issues = #12755
issues = '#12755'
requirement = "The system shall support a time offset between the master and a subapp when using the Multiapp system."
design = "TransientMultiApp.md"
[]
Expand Down
2 changes: 2 additions & 0 deletions unit/src/HitTests.C
Expand Up @@ -40,6 +40,8 @@ TEST(HitTests, FailCases)
PassFailCase cases[] = {
{"comment in path", "[hello#world] []"},
{"comment in field", "hello#world=foo"},
{"missing string", "[hello] foo = []"},
{"missing string 2", "[hello] foo = \n bar = 42[]"},
{"invalid path char '='", "[hello=world] []"},
{"invalid path char '&'", "[hello&world] []"},
{"invalid path char '['", "[hello[world] []"},
Expand Down

0 comments on commit 9e4f758

Please sign in to comment.