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

Strange compiler errors when doing super simple example #214

Closed
nshcat opened this issue Nov 24, 2019 · 3 comments
Closed

Strange compiler errors when doing super simple example #214

nshcat opened this issue Nov 24, 2019 · 3 comments

Comments

@nshcat
Copy link

nshcat commented Nov 24, 2019

Hello,
when using this crate with the following super simple grammar:

parser!{
	grammar test_parser() for str {
		pub rule number() -> f64
			= n:$(['0'..='9']+) { n.parse().unwrap() }
	}
}

I get a weird error:

error[E0107]: wrong number of type arguments: expected 0, found 2
   --> src/main.rs:637:24
    |
635 | / parser!{
636 | |     grammar test_parser() for str {
637 | |         pub rule number() -> f64
    | |                              ^^^ unexpected type argument
638 | |             = n:$(['0'..='9']+) { n.parse().unwrap() }
...   |
651 | |     }
652 | | }
    | |_^ unexpected type argument

Interestingly, if I remove the pub specifier from the rule it works, but then the rule is no longer useable. Am I doing something wrong?

Thanks in advance.

@kevinmehall
Copy link
Owner

That's weird. Can you share a more complete example? I was unable to reproduce it with Rust 1.39 and peg 0.6 by putting that in a file with use peg::parser; on top.

I suspect something in your module is getting pulled into the peg-generated module by the use super::* it inserts, and shadowing something that the generated code needs. Rust macros aren't fully hygienic yet, so we have to be careful to use only fully qualified names in the generated code to avoid those conflicts. It's possible that I missed one.

@kevinmehall
Copy link
Owner

kevinmehall commented Nov 24, 2019

Do you have a struct Result; in your module? I was able to reproduce your error by adding that. It's expanding into a function returning Result<f64, ParseError> and if that's getting the new type instead of std::Result, it breaks. It's an easy fix, but I'm going through to make sure there aren't others.

In the meantime, a workaround is to put the parser!{} invocation in its own mod{ } or file so that's not in scope.

@nshcat
Copy link
Author

nshcat commented Nov 24, 2019

Thank you very much, it was my own Result type that made things go wrong!

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

2 participants