Closed p0lunin closed 3 years ago
I find where error:
rule logic(i: usize, single_rule: rule<Token>) -> Token = precedence! {
...
d:block(i, <logic(i, <single_rule()>)>) { d }
}
when i comment these lines with recursive call logic(i, <single_rule()>)
build was succesful
I fixed this error by adding copy of logic() rule, but i don't like this because i duplicate the same code
The minimized version is:
rule logic(single_rule: rule<()>) = " " logic(<single_rule()>)
This expands to something like
fn logic(single_rule: impl Fn()) {
logic(|| single_rule())
}
which fails to compile with the same error.
This is because it creates an infinite chain of monomorphized versions of the closure. In plain Rust, you could work around this by passing single_rule
instead of || single_rule()
, but in rust-peg we prohibit that with "parameter single_rule
expects a PEG expression, but a value was passed". That restriction could be loosened to allow passing the existing closure, or we could look at using &Fn
closures instead of impl Fn
to avoid the monomorphization.
https://github.com/kevinmehall/rust-peg/commit/7b45748b9d5d5969b4f834a70a591937164944ad removes the "parameter single_rule expects a PEG expression, but a value was passed" error, allowing you to pass down the rule closure unmodified as a way to avoid the issues with re-capturing the closure:
rule logic(single_rule: rule<()>) = " " logic(single_rule)
I got a very strange error:
when i try
cargo build
. I tried to create MRE, but if i moved all code related to parsing into another crate, it worked without errors. Build in actions: https://github.com/p0lunin/vglang/runs/663466273 When i build use macro-backtrace, it show: