-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unbounded mutual recursion in Parser impl #347
Comments
I'd generally avoid implementing If you still need a manual implementation I would copy paste from an implementation in the impl<Input, P> Parser<Input> for Satisfy<Input, P>
where
Input: Stream,
P: FnMut(Input::Token) -> bool,
{
type Output = Input::Token;
type PartialState = ();
#[inline]
fn parse_lazy(&mut self, input: &mut Input) -> ParseResult<Self::Output, Input::Error> {
satisfy_impl(input, |c| {
if (self.predicate)(c.clone()) {
Some(c)
} else {
None
}
})
}
} |
I can confirm that simply changing my impl to implement That suggests to me that the |
I encountered a similar issue. We should at least update the document. |
I've implemented a recursive descent parser via the precedence climbing method using Combine, but it seems prone to unbounded mutual recursion somewhere in undocumented methods of the
Parser
impl.The parser itself looks something like this:
I find that in some formulations this gets stuck calling
parse_first
,parse_partial
andparse_lazy
on theParser
without end (until the stack overflows) as illustrated by this stack trace (most recent call first) taken from whereparse
is called before things go wrong:According to the documentation it seems like implementing
parse_stream
alone is fine, andparse_partial
/parse_first
are not documented so I don't understand what they're meant to be doing or why they end up mutually recursing.When I previously had this problem in
parse_terminal
I was able to work around it (for reasons I don't understand) by wrapping the recursive call in a wrapper function. Whereas this sort of thing exhibited the same problem described here:wrapping it in
parser
and explicitly callingparse_stream
did not:The text was updated successfully, but these errors were encountered: