Closed JeffDemanche closed 21 hours ago
Hello, perhaps this is reflects a poor understanding on my part, in which case I'm seeking clarification.
export const bnf = ` ifl ::= filter EOF filter ::= "highlights" (WS* highlights_expression)? (WS* highlights_sort)? | "arcs" highlights_expression ::= (highlights_criterion | highlights_expression_conjunction | highlights_expression_disjunction) highlights_expression_conjunction ::= "(" highlights_expression WS* "and" WS* highlights_expression ")" highlights_expression_disjunction ::= "(" highlights_expression WS* "or" WS* highlights_expression ")" highlights_criterion ::= highlights_criterion_dates | highlights_criterion_relation highlights_criterion_dates ::= "from" WS* day WS* "to" WS* day highlights_criterion_relation ::= "which" WS* predicate WS* relation_object highlights_sort ::= "sorted by" WS* highlights_sort_type highlights_sort_as_of? highlights_sort_as_of ::= WS* "as of" WS* day highlights_sort_type ::= "importance" | "recent" predicate ::= "are" | "relate to" relation_object ::= STRING day ::= STRING STRING ::= '"' ([1-9] | [a-z])+ '"' WS ::= [#x20#x09#x0A#x0D]+ `; const parser = new Grammars.W3C.Parser(bnf, {}); const ast = parser.getAST("highlights bad input"); console.log(ast);
In this example, ast becomes null. I would expect it instead be defined with Unexpected token as an error on "bad input"?
ast
null
Unexpected token
If I remove EOF from the first rule in the grammar ast is non-null, but reports Unexpected end of input for any tokens past highlights.
EOF
Unexpected end of input
highlights
Thank you
Closing this, the issue was with using WS* over WS+. I change them and removed EOF.
WS*
WS+
Hello, perhaps this is reflects a poor understanding on my part, in which case I'm seeking clarification.
In this example,
ast
becomesnull
. I would expect it instead be defined withUnexpected token
as an error on "bad input"?If I remove
EOF
from the first rule in the grammarast
is non-null, but reportsUnexpected end of input
for any tokens pasthighlights
.Thank you