Hey, I'm quite new to rust and I'm wondering if I'm missing something here.
I'm in the middle of trying to create a compiler in rust, using https://pest.rs/ for defining the grammar and parsing the input.
I want to be able to traverse the tree pest creates multiple times. ( first time to generate a symbol table, second to do code generation).
I think I understand the problem I have (although it would be good to check I understand correctly).
To traverse the tree I have code like this
for line in ast.into_inner() {
match line.as_rule() {
Rule::EOI => Ok(()),
Rule::line => doStuff,
_ => unreachable!(),
}?;
}
into_inner doesn't return a reference, but a concrete type, as I understand assignment in rust, is move by default, so into_inner effectively removes this node from the tree.
If I want to traverse the tree multiple times (reading only!) the only option i can see is to clone the whole tree for each pass.
I'm not sure if this is an intentional property of the language/pest or if I'm missing something?