-
Notifications
You must be signed in to change notification settings - Fork 20
Add many1Till to Combinators #30
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
Conversation
many1Till :: forall a end. Parser a -> Parser end -> Parser (List a) | ||
many1Till p end = do | ||
x <- p | ||
xs <- manyTill p end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we can also write manyTill p end = (end *> pure Nil) <|> many1Till p end
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but - forgive my ignorance - surely we can't mutually define manyTill and many1Till each in terms of the other can we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can, because many1Till
only uses manyTill
after p
, which means the recursive call is guarded by a function (implicit in the do
notation block).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I think I see what you mean - I'd never have spotted it. I'll try it out - it certainly simplifies manyTill.
Looks great, thanks! |
Thanks. I've just become a bit concerned by this, though: let
target = (joinWith "" $ replicate 100000 "a") <> "b"
assert' "manyTill should not blow the stack" $ canParse (manyTill (string "a") (string "b")) (target) blows the call stack. |
Yes, that's a general issue right now. It's not just this function. |
Oh - that's good news. It's just that I saw similar tests in place for many. |
Well, |
Hmm - looks like I need to do some more learning. Thanks again for all your help and advice. |
No description provided.