-
-
Couldn't load subscription status.
- Fork 189
Open
Description
This isn't necessarily an issue per se, but I thought the following problem I encountered would be worth documenting since this took me a while to finally figure out:
If you use recursive and call a function in it that returns a parser, then make sure that the parser that function returns also implements Clone.
This doesn't work:
fn another_parser<'a>() -> impl Parser<'a, &'a str, ()> {
// ...
}
fn test(){
// the trait bound `impl chumsky::Parser<'_, &str, ()>: Clone` is not satisfied
// the trait `Clone` is not implemented for `impl chumsky::Parser<'_, &str, ()>`
recursive(|r| {
let parser = another_parser();
parser
});
}This works:
// Note the Clone
fn another_parser<'a>() -> impl Parser<'a, &'a str, ()> + Clone {
// ...
}
fn test(){
recursive(|r| {
let parser = another_parser();
parser
});
}This also applies to cases where the parser passes useful data i.e. impl Parser<'a, &'a str, SomeType> instead of impl Parser<'a, &'a str, ()>.
Metadata
Metadata
Assignees
Labels
No labels