It seems the lifetime of an AST is entangled with the parser itself:
pub fn js_to_ast(js: &str) -> Program {
let mut p = Parser::new(js).unwrap();
let ast = p.parse().unwrap();
ast
}
// error[E0515]: cannot return value referencing local variable `p`
// |
// 177 | let ast = p.parse().unwrap();
// | --------- `p` is borrowed here
// 178 | ast
// | ^^^ returns a value referencing data owned by the current function
I think the AST should be completely independent from parser/scanner etc.
Otherwise we always needs to have the parser object around with our AST.
It seems the lifetime of an AST is entangled with the parser itself:
I think the AST should be completely independent from parser/scanner etc.
Otherwise we always needs to have the parser object around with our AST.