Issue When Calling External Methods From Within Recursive Combinator #629
-
Hey!! For the past few days I have been pulling hair to figure out the issue I've been having but I finally found it, It seems that when using a recursive combinator in such a way you cannot use external functions. Since I'm bad at explaining here is an example, surprisingly this error only occurs when the parsers are returning a type other then Example use chumsky::prelude::{recursive, any, text, Rich, Parser, extra::Err};
#[derive(Clone)]
enum Token { Hash, }
fn test_external<'ast>() -> impl Parser<'ast, &'ast str, Token, Err<Rich<'ast, char>>> {
any().to(Token::Hash)
}
fn test<'ast>() -> impl Parser<'ast, &'ast str, Token, Err<Rich<'ast, char>>> {
recursive(| text_or_macro | {
text::ascii::ident()
.map_with(| identity, extra| {
return Token::Hash;
})
.then(test_external())
.try_map_with(| (call, arguments), extra | {
Ok(call)
})
})
}
/*
error[E0277]: the trait bound `impl Parser<'_, &str, Token, chumsky::extra::Full<Rich<'_, char>, (), ()>>: Clone` is not satisfied
--> src\lib.rs:10:5
|
10 | / recursive(| text_or_macro | {
11 | | text::ascii::ident()
12 | | .map_with(| identity, extra| {
13 | |
... |
19 | | })
20 | | })
| |______^ the trait `Clone` is not implemented for `impl Parser<'_, &str, Token, chumsky::extra::Full<Rich<'_, char>, (), ()>>`, which is required by `TryMapWith<Then<MapWith<impl Parser<'_, &str, &<char as chumsky::text::Char>::Str, chumsky::extra::Full<Rich<'_, char>, (), ()>> + Copy, &str, {closure@src\lib.rs:12:23: 12:41}>, impl Parser<'_, &str, Token, chumsky::extra::Full<Rich<'_, char>, (), ()>>, Token, Token, chumsky::extra::Full<Rich<'_, char>, (), ()>>, (Token, Token), {closure@src\lib.rs:17:27: 17:55}>: Clone`
|
= note: required for `Then<MapWith<impl Parser<'_, &str, &<char as Char>::Str, ...> + Copy, ..., ...>, ..., ..., ..., ...>` to implement `Clone`
= note: the full type name has been written to 'C:\Users\Ellie\RustroverProjects\chumsky-testing\target\debug\deps\chumsky_testing-86fc35c00a6cfd84.long-type-7863178368529499131.txt'
= note: 1 redundant requirement hidden
= note: required for `TryMapWith<Then<MapWith<impl Parser<'_, &str, &..., ...> + Copy, ..., ...>, ..., ..., ..., ...>, ..., ...>` to implement `Clone`
= note: the full type name has been written to 'C:\Users\Ellie\RustroverProjects\chumsky-testing\target\debug\deps\chumsky_testing-86fc35c00a6cfd84.long-type-9597227331149914401.txt'
note: required by a bound in `recursive`
--> C:\Users\Ellie\.cargo\registry\src\index.crates.io-6f17d22bba15001f\chumsky-1.0.0-alpha.7\src\recursive.rs:271:30
|
267 | pub fn recursive<'a, 'b, I, O, E, A, F>(f: F) -> Recursive<Direct<'a, 'b, I, O, E>>
| --------- required by a bound in this function
...
271 | A: Parser<'a, I, O, E> + Clone + MaybeSync + 'b,
| ^^^^^ required by this bound in `recursive`
*/ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Add a Edit: Going to try to find time to reply to your other discussion thread this weekend, I've just been really busy this week (it's election season where I live). |
Beta Was this translation helpful? Give feedback.
Add a
+ Clone
to the end of yourimpl Parser<...>
return types.Edit: Going to try to find time to reply to your other discussion thread this weekend, I've just been really busy this week (it's election season where I live).