Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined nonterminal is accepted in bnf parsing #136

Open
Dan-wanna-M opened this issue Aug 7, 2023 · 3 comments
Open

Undefined nonterminal is accepted in bnf parsing #136

Dan-wanna-M opened this issue Aug 7, 2023 · 3 comments

Comments

@Dan-wanna-M
Copy link

Dan-wanna-M commented Aug 7, 2023

Describe the bug
A nonterminal that is not defined is not rejected during parsing.

To Reproduce
For example,

let input = "<dna> ::= <base> | <base> <dna>";
let grammar: Grammar = input.parse().unwrap();

does not panic, while 'base' is not defined in the input.

Desktop (please complete the following information):

  • Windows 11
@CrockAgile
Copy link
Collaborator

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.

@Dan-wanna-M
Copy link
Author

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.

@hoijui
Copy link

hoijui commented Oct 23, 2024

I agree, though I would prefer grammar.validate(), as it is not simply the fetching of a property value (which is somewhat suggested by grammar.is_valid()), but a reasonably complex calculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants