-
Notifications
You must be signed in to change notification settings - Fork 107
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
Parsing into a flat AST / Side effects in actions #386
Comments
There are two places where this comes up: PEG involves backtracking, which means that if a rule fails, it will throw away the result, back up, and try another alternative of a Secondly, when overall parsing fails, rust-peg will re-run the parse in a slower mode that traces intermediate failures in order to build the "expected" set for the error position. This will run all the actions a second time. It assumes the action code is deterministic and expects this parse to take the same path as the prior parse and may panic if this is not the case. That's just for control flow, e.g the result of a You could pass in a Vec or other type of arena as a grammar argument: peg::parser!{
grammar test(arena: &mut Vec<Node>) for str {
pub rule expression() -> usize = { let id = arena.len(); arena.push(...); id }
}}
let mut vec = Vec::new();
test::expression("input str", &mut vec); |
Thank you! The only problem here would be that the AST takes more space than necessary but that is an evil that i am willing to take for now. |
|
Hello, i am investigating peg to parse the grammar of a programming language i am working on.
Is there any way to store the generated AST in a flat Vec instead of building it up with boxes?
The documentation says that rust actions must be deterministic and must not have side effects, is this not possible because of this? Any "workarounds"?
Thanks in advance and have a nice day ::)
The text was updated successfully, but these errors were encountered: