node-ebnf
node-ebnf copied to clipboard
Are empty constructions valid?
const grammar = `
root ::= ws 'x'
ws ::= #x20*
`;
const parser = new Grammars.W3C.Parser(grammar, {debug:true});
console.log(parser.getAST('x'));
console.log(parser.getAST(' x'));
I'd expect both cases to work, but the first does not parse.
Same issue for me.
test1 ::= 'A' OWS '=' OWS 'B'
OWS ::= ( SP | HTAB )*
SP ::= ' '
HTAB ::= #x9
A = B works without issues.
However if an Optional Whitespace (OWS) is 0, it stops working: A= B
If I change the EBNF to:
test1 ::= 'A' ( SP | HTAB )* '=' ( SP | HTAB )* 'B'
SP ::= ' '
HTAB ::= #x9
it works as expected.
From what I remember, there can NOT be empty constructions. Constructions must be at least one character in length. Otherwise if you had OWS+ being OWS ::= ' '? then when OWS+ finish? It would be valid to have an infinite amount of OWS not matching any character.
This may be the a good scenario for your parser:
{ws=explicit}
test1 ::= 'A' OWS? '=' OWS? 'B' '\n'?
OWS ::= ( SP | HTAB )+
SP ::= ' '
HTAB ::= #x9