-
Notifications
You must be signed in to change notification settings - Fork 21
Make sepEndBy stack safe #95
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
base: main
Are you sure you want to change the base?
Conversation
as <- sepEndBy p sep | ||
pure (cons' a as) | ||
) <|> pure (NEL.singleton a) | ||
as <- many $ try (sep *> p) |
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.
If I'm not mistaken, this changes the behavior of the function in case of a parser error in p
due to the usage of try
. PS I'm currently on vacation and may not be very swift to respond.
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.
What you pointed out is correct.
Thanks for the quick review.
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.
NOTE
It gets
> runParser (sepEndBy (char 'a') (char ';')) "a;b"
(Right ('a' : Nil))
It seems that b is trashed. I think this is a little problem.
I found this result occurs also in original sebEndBy
.
I wonder if it is the intended behavior.
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.
Hm yeah, I can't think of obvious situations where this would be what you want. In test/BasicSpecs.purs we have some basic specs that say what should be parsable and what shouldn't. Perhaps we should extend these specs to also cover partial successes and assert on the expected remaining unparsed string.
We should also look at what purescript-parsing does in these cases.
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 would naievely expect sepEndBy to successfully parse a separated sequence and whenever either the sep
or the p
fails to just stop parsing and yield what has been parsed so far.
I encountered stack overflow when I used
sepEndBy
for large data.It seemed to be caused by
sepEndBy
andsepEndBy1
are calling each other.So I added a test and fixed
sepEndBy1
using stack safemany
.It seems that
chainl
andchainr
should also be fixed.However I fixed only
sepEndBy
with this PR because these functions are a little complicated to me.Checklist: