You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
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
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
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.
The text was updated successfully, but these errors were encountered:
Ran into this today. The workaround mentioned in #312 to use RefCell works fine, but it would be really great if this could get fixed so you could just use &mut arguments like normal! I would also be fine if rust-peg wrapped the argument with RefCell automatically since it's already doing plenty of magic behind the scenes anyway.
Minimal example:
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.
The text was updated successfully, but these errors were encountered: