zesterer / chumsky

Write expressive, high-performance parsers with ease.
https://crates.io/crates/chumsky
MIT License
3.63k stars 155 forks source link

I'm upgrading to 1.0.0-alpha.7 I can't get the parser function signature right #637

Closed AverageLinuxEnjoyer closed 6 months ago

AverageLinuxEnjoyer commented 6 months ago

I'm upgrading from 0.9.3 to 1.0.0-alpha.7 to use pratt parsing and I can't really understand how the new Parser works. This is what I've been previously using:

pub fn parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone

where Token's are generated by the lexer and meant to be fed to this parser, so it can generate an Expr. No lifetimes involved, everything is owned. But it seems to be no longer working and I'm not sure how to adapt it to 1.0.0-alpha.7. I've looked a bit at the docs and at some examples and, from my understanding, now there's this Input trait bound that I needs to satisfy, but I can't find a single example on how to do it without lifetimes. I'd like to pass a Vec<Token> in and get an Expr out.

Any ideas?

AverageLinuxEnjoyer commented 6 months ago

I found a way to do it:

fn expr_parser<'a>() -> impl Parser<'a, &'a [Token], Expr> + Clone {
    ...
}