Make sepEndBy stack safe#95
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.
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.
What you pointed out is correct.
Thanks for the quick review.
There was a problem hiding this comment.
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.
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.
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
sepEndByfor large data.It seemed to be caused by
sepEndByandsepEndBy1are calling each other.So I added a test and fixed
sepEndBy1using stack safemany.It seems that
chainlandchainrshould also be fixed.However I fixed only
sepEndBywith this PR because these functions are a little complicated to me.Checklist: