Open Dan-wanna-M opened 1 year ago
This is a good question! Should an undefined nonterminal be an error?
In a similar way, should this code cause an error?:
let mut grammar = bnf::Grammar::new();
let production_with_undefined_nonterminal: bnf::Production = "<start> ::= <end>".parse().unwrap();
grammar.add_production(production_with_undefined_nonterminal);
The root question seems to be "Is a bnf::Grammar
always valid / fully defined?"
The current bnf
version does not enforce anything. But maybe as this issue suggests, this should be changed.
This is a good question! Should an undefined nonterminal be an error?
In a similar way, should this code cause an error?:
let mut grammar = bnf::Grammar::new(); let production_with_undefined_nonterminal: bnf::Production = "<start> ::= <end>".parse().unwrap(); grammar.add_production(production_with_undefined_nonterminal);
The root question seems to be "Is a
bnf::Grammar
always valid / fully defined?"The current
bnf
version does not enforce anything. But maybe as this issue suggests, this should be changed.
I think so. A quick fix would be add grammar.is_valid()
that returns a bool to indicate whether the grammar is valid.
Describe the bug A nonterminal that is not defined is not rejected during parsing.
To Reproduce For example,
does not panic, while 'base' is not defined in the input.
Desktop (please complete the following information):