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

&mut rule argument doesn't work with precedence!{} #313

Open
kevinmehall opened this issue Jul 18, 2022 Discussed in #312 · 0 comments
Open

&mut rule argument doesn't work with precedence!{} #313

kevinmehall opened this issue Jul 18, 2022 Discussed in #312 · 0 comments
Labels

Comments

@kevinmehall
Copy link
Owner

Minimal example:

    pub rule mut_prec(a: &mut ()) -> () = precedence! {
        "a" { a; () }
    }
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0507]: cannot move out of `a`, a captured variable in an `Fn` closure
  --> $DIR/rule_args.rs:31:13
   |
30 |     pub rule mut_prec(a: &mut ()) -> () = precedence! {
   |                       -                   ---------- captured by this `Fn` closure
   |                       |
   |                       captured outer variable
31 |         "a" { a; () }
   |             ^^-^^^^^^
   |             | |
   |             | move occurs because `a` has type `&mut ()`, which does not implement the `Copy` trait
   |             move out of `a` occurs here
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

Discussed in #312

Originally posted by lfnoise July 17, 2022
I created a working parser for a non-trivial language syntax in a few hours, so that was pretty neat, thanks.

I needed to pass a &mut symbol table struct down the tree of parsing rules. This worked fine for all but precedence climbing and left recursive rules. The left recursion gave me an error message that arguments weren't supported.. fair enough. Precedence climbing just wouldn't compile. It gave an error about not being able to capture a mutable in the rule closure and needing a FnMut instead of a Fn. Left recursion was easy to solve, but creating separate nested rules for a dozen levels of precedence by hand was not so nice. My parser works, but is not as simple it would be with the precedence! macro.

Did I do something wrong? Is there a way to pass an argument down into the @ (next lower precedence rule) somehow?
Here's the code.
Thank you.

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

No branches or pull requests

1 participant