elm-community / parser-combinators

A parser combinator library for Elm.
http://package.elm-lang.org/packages/elm-community/parser-combinators/latest
BSD 3-Clause "New" or "Revised" License
104 stars 13 forks source link

There is no try #10

Closed capicue closed 8 years ago

capicue commented 8 years ago

I'm encountering difficulties with manyTill that I believe are due to an absence of a try combinator that doesn't consume any input on error.

As an example, I would expect the following to return the list ['a', ' ', 'b', ' ', 'c'], but it returns ['a', 'b', 'c'].

parse (manyTill anyChar ((many space) *> eol)) "a b c\n"
-->  (Ok ['a','b','c'],{ input = "", position = 7 })
-->      : ( Combine.Result (List Char), Combine.Context )
Bogdanp commented 8 years ago

Thanks for reporting the issue!

This was actually a bug in manyTill: it incorrectly passed the end parser's failure context to the p parser. try should not be necessary in Combine at this point because all its combinators favor backtracking on error.

capicue commented 8 years ago

Great, thanks so much!

I prefer the backtracking-on-error behavior. Glad it went this way.