Skip to content

Commit

Permalink
Issue #38 fix and add grammar validation check for wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
petervwyatt committed Nov 3, 2022
1 parent b73f94e commit 122afda
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion TestGrammar/src/CheckGrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,12 @@ bool check_grammar(CArlingtonTSVGrammarFile& reader, std::string& arl_type, bool
}

// Check "*" wildcard key - must be last (duplicate keys already checked above)
if (std::find(std::begin(keys_list), std::end(keys_list), "*") != std::end(keys_list))
if (std::find(std::begin(keys_list), std::end(keys_list), "*") != std::end(keys_list)) {
if (keys_list[keys_list.size() - 1] != "*") {
report_stream << COLOR_ERROR << "wildcard key '*' in " << reader.get_tsv_name() << " was not last key" << COLOR_RESET;
retval = false;
}
}

// Array filenames match "ArrayOf*" or "*Array"
auto filename = reader.get_tsv_name();
Expand Down
6 changes: 5 additions & 1 deletion TestGrammar/src/PredicateProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,12 @@ bool PredicateProcessor::ValidateRequiredSyntax(const int key_idx) {
assert((key_idx >= 0) && (key_idx < (int)tsv.size()));
std::string tsv_field = tsv[key_idx][TSV_REQUIRED];

if ((tsv_field == "TRUE") || (tsv_field == "FALSE"))
if ((tsv_field == "TRUE") || (tsv_field == "FALSE")) {
// Wildcards must have Required be FALSE
if ((tsv[key_idx][TSV_KEYNAME] == "*") && (tsv_field != "FALSE"))
return false;
return true;
}
else if ((tsv_field.find("fn:IsRequired(") == 0) && (tsv_field[tsv_field.size()-1] == ')')) {
ASTNode *ast = new ASTNode();
ASTNodeStack stack;
Expand Down
2 changes: 1 addition & 1 deletion tsv/latest/ArrayOfCIDGlyphMetricsW.tsv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Key Type SinceVersion DeprecatedIn Required IndirectReference Inheritable DefaultValue PossibleValues SpecialCase Link Note
* array;integer;number 1.2 TRUE FALSE FALSE [ArrayOfNumbersGeneral];[];[] Clause 9.7.4.3
* array;integer;number 1.2 FALSE FALSE FALSE [ArrayOfNumbersGeneral];[];[] Clause 9.7.4.3
2 changes: 1 addition & 1 deletion tsv/latest/ArrayOfCIDGlyphMetricsW2.tsv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Key Type SinceVersion DeprecatedIn Required IndirectReference Inheritable DefaultValue PossibleValues SpecialCase Link Note
* array;integer;number 1.2 TRUE FALSE FALSE [fn:Eval((fn:ArrayLength(1) mod 3)==0)];[];[] [ArrayOfNumbersGeneral];[];[] Clause 9.7.4.3 - C-last
* array;integer;number 1.2 FALSE FALSE FALSE [fn:Eval((fn:ArrayLength(1) mod 3)==0)];[];[] [ArrayOfNumbersGeneral];[];[] Clause 9.7.4.3 - C-last

0 comments on commit 122afda

Please sign in to comment.