Skip to content

Lifetimes of AST entangled with parser? #79

@Fee0

Description

@Fee0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions