J-F-Liu / pom

PEG parser combinators using operator overloading without macros.
MIT License
496 stars 30 forks source link

Recursive parser with additional arguments #22

Closed singaraiona closed 5 years ago

singaraiona commented 5 years ago

Hi, I've tried your library for creating programming language parser, all things seems be fine until I've reached recursion. I have code like this (simplified):

fn expr<'a>(n: AST, c: Context) -> Combinator<impl Parser<'a, u8, Output = AST>> { (oneof(b"<>=|~,^#$?@:'") + phrase(c.clone())).map(move |(v, e)| {...} | empty().map(move |_| n.clone()) } // fn phrase<'a>(c: Context) -> Combinator<impl Parser<'a, u8, Output = AST>> { noun(c.clone()) >> move |n: AST| expr(n, c.clone()) } // fn prg<'a>(c: Context) -> Combinator<impl Parser<'a, u8, Output = AST>> { phrase(c.clone()) - endp() }

Compiler says: error[E0275]: overflow evaluating the requirement impl pom::Parser<u8>... I've found call() and comb(), unfortunately, they don't accept passing additional arguments (like Context and AST in my case). Maybe, I've missed something?