-
Notifications
You must be signed in to change notification settings - Fork 50
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
Can we have more typesafety w.r.t. many-like combinators and infinite loops? #120
Comments
I like your thinking about this and it would be nice to solve this problem. Some further notes:
I can think of one useful parser that consumes no input and succeeds:
Because |
I've given a little bit of thought. I like the direction of the second solution (stopping the loop when no input is consumed) the best for the following reasons.
I can't imagine a practical situation for this, but you are correct. Perhaps we can expose two flavors of |
I like the idea of having a flavor of We would have to think about which combinators we want to supply this flavor for. Here are some candidates:
That's a pretty long list. But we could start with just a few of those, and then add more if there was popular demand. Here's another idea which just occurred to me: a combinator Here's an implementation for consume :: forall m a. Monad m => ParserT String m a -> ParserT String m a
consume p = do
ParseState input1 _ _ <- get
x <- p
ParseState input2 _ _ <- get
if CodeUnits.length input2 < CodeUnits.length input1 then pure x else fail "Consumed no input." So if we have a |
I like your idea of a I see you included some non-parser functions in your list, like |
(The |
I changed my mind, I think that the The internal What we want to assert with the |
Nice @jamesdbrock . Perhaps the existence of the advance function could be mentioned in the docs of all relevant many-like parser combinators? So that users will know that the many combinator will hang when there is a chance that their parser does not consume, and how to solve that. |
Is your change request related to a problem? Please describe.
many p
will get stuck in a loop if p possibly doesn't consume any input but still succeeds.One could argue that the parser is bogus in that case. However, it would be nice to have some compile time safety guarantees for this, because a hanging application isn't fun to deal with, even if it occurs while developing.
Some solution directions that cross my mind
many
such that it stops (or fails?) whenever the position of the parser state hasn't moved after applyingp
.The text was updated successfully, but these errors were encountered: