Skip to content
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

Diverges with sepEndBy from parser-combinator #56

Closed
tryzniak opened this issue Jul 5, 2021 · 1 comment
Closed

Diverges with sepEndBy from parser-combinator #56

tryzniak opened this issue Jul 5, 2021 · 1 comment

Comments

@tryzniak
Copy link

tryzniak commented Jul 5, 2021

Hello. Thank you for this great library.

I think I found a bug. The grammar below diverges if I use default sepEndBy from parser-combinators:

-- Does not work, but sepEndBy only requires an Applicative instance and we have it
grammar' = rule $ sepEndBy (satisfy (== OpenBracket)) (satisfy (== Dot))
-- but with this one everything is ok
sepEndBy :: Prod r e t a -> Prod r e t b -> Prod r e t [a]
-- btw sepBy can come from parser-combinators, and still no problem here
sepEndBy p sep = sepBy p sep <* optional sep
@ollef
Copy link
Owner

ollef commented Jul 6, 2021

It looks like sepByEnd is implemented using recursion, which results in an infinitely large production when used with Earley. Earley only supports finite grammars, and recursion (other than many and some which are special-cased) needs to be done with rule. So this is a known limitation. It's a bit unfortunate that it seems like parts of the parser-combinators library can't be used because of this limitation, but I don't see any way around it.

The reason your implementation of sepByEnd works is that sepBy is implemented using many.

@ollef ollef closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants