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

How do "_" rules work? #243

Closed
piegamesde opened this issue Dec 14, 2020 · 3 comments
Closed

How do "_" rules work? #243

piegamesde opened this issue Dec 14, 2020 · 3 comments

Comments

@piegamesde
Copy link

I don't understand this rule:

_ or __ or ___ - Rule (underscore): As a special case, rule names consisting of underscores are invoked without parentheses. These are conventionally used to match whitespace between tokens.

If I read the definition correctly, I need to call my rule _ and then it will work?

rule _ = skip_whitespace()

however gives me:

error: expected one of "(", "<"
  --> src/placement.rs:43:16
   |
43 |         rule _ = skip_whitespace()
   |                ^

error: aborting due to previous error
@mdenchev
Copy link

mdenchev commented Dec 14, 2020

You only omit the () when invoking, not when defining. So it would be:
rule _() = skip_whitespace()

Example:

rule _() = [' ' | '\t' | '\r' | '\n']*

@piegamesde
Copy link
Author

piegamesde commented Dec 15, 2020

Yeah, that makes sense, thanks. Maybe add that line somewhere as an example in to the documentation, please?

@kevinmehall
Copy link
Owner

We should probably just make it accept the more obvious rule _ = syntax here.

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