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

Empty String Rules Fail to Match #108

Closed
Axiomatic-Mind opened this issue Sep 12, 2022 · 4 comments · Fixed by #109
Closed

Empty String Rules Fail to Match #108

Axiomatic-Mind opened this issue Sep 12, 2022 · 4 comments · Fixed by #109

Comments

@Axiomatic-Mind
Copy link
Contributor

Axiomatic-Mind commented Sep 12, 2022

When I match a grammar such as

<main> ::= "foo:" <bar>
 <bar> ::= "bar"

against foo:bar, it works. When I match a grammar such as

<main> ::= "foo:" ""

against foo:, it works. However, when I match

<main> ::= "foo:" <baz>
 <baz> ::= ""

against foo:, it doesn't work.

Replicable using this code:

fn main() {
	let grammar1: bnf::Grammar = "
		<main> ::= \"foo:\" <bar>
		 <bar> ::= \"bar\"
	".parse().unwrap();

	let grammar2: bnf::Grammar = "
		<main> ::= \"foo:\" \"\"
	".parse().unwrap();

	let grammar3: bnf::Grammar = "
		<main> ::= \"foo:\" <baz>
		 <baz> ::= \"\"
	".parse().unwrap();

	assert!(grammar1.parse_input("foo:bar").next().is_some(), "grammar1 failed!");
	assert!(grammar2.parse_input("foo:"   ).next().is_some(), "grammar2 failed!");
	assert!(grammar3.parse_input("foo:"   ).next().is_some(), "grammar3 failed!");
}

Screenshot
Why isn't a parse tree like this being generated?

ParseTree {
	lhs: Term::Nonterminal("main"),
	rhs: [
		ParseTreeNode::Terminal("foo:"),
		ParseTreeNode::Nonterminal(ParseTree {
			lhs: Term::Nonterminal("baz"),
			rhs: [
				ParseTreeNode::Terminal(""),
			],
		}),
	],
}

Is this intentional/explicable behavior, or a bug? Thanks!

@CrockAgile
Copy link
Collaborator

since the behavior is varying across those similar grammars, this seems like a bug to me. I have a hunch! so thanks for the great reproduction steps, and I will start investigating 🕵️

@shnewto
Copy link
Owner

shnewto commented Sep 13, 2022

@Axiomatic-Mind I just merged the PR that addresses this, the release will be publised to crates soon. Thanks for raising the issue!

@shnewto
Copy link
Owner

shnewto commented Sep 13, 2022

okay version 0.4.2 published to crates.io!

@Axiomatic-Mind
Copy link
Contributor Author

Thanks for fixing this!

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

Successfully merging a pull request may close this issue.

3 participants