Re: [Haskell-cafe] attoparsec and backtracking

2013-03-19 Thread oleg
Wren Thornton wrote: I had some similar issues recently. The trick is figuring out how to convince attoparsec to commit to a particular alternative. For example, consider the grammar: A (B A)* C; where if the B succeeds then we want to commit to parsing an A (and if it fails then return A's

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-16 Thread Roman Cheplyaka
* Niklas Hambüchen m...@nh2.me [2013-03-16 03:49:29+] I would agree that what attoparsec does for | of Alternative and mplus for MonadPlus is correct since e.g. the mplus laws say that a failure must be identity and therefore the following alternatives must be considered. I also find it

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-16 Thread Evan Laforge
I think the mistake here is to parse something and then decide if its it valid. It should be the parser which decides whether its valid. So rather than: suffix - A.option ((:) $ A.letter_ascii) try: typ - A.choice [ {- list or valid suffix parsers -} ] return $

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-16 Thread Evan Laforge
On Fri, Mar 15, 2013 at 8:49 PM, Niklas Hambüchen m...@nh2.me wrote: Is it not possible to add an alternative (no pun intended) to | that supports the semantics Evan wants? I assume it's the performance thing. Presumably it would need to pass an extra flag with to the failure continuation to

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-16 Thread Niklas Hambüchen
@Evan Thanks for that link, I posted a somewhat longer argument in there. Personally, I'd love ||. On Sun 17 Mar 2013 02:02:44 GMT, Evan Laforge wrote: On Fri, Mar 15, 2013 at 8:49 PM, Niklas Hambüchen m...@nh2.me wrote: Is it not possible to add an alternative (no pun intended) to | that

[Haskell-cafe] attoparsec and backtracking

2013-03-15 Thread Evan Laforge
I have a couple of problems with attoparsec which I think are related to its always backtrack nature, but maybe there's some other way to solve the same problems. The first is that it's hard to get the right error msg out. For instance, I have a parser that tries to parse a number with an

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-15 Thread wren ng thornton
On 3/15/13 3:29 PM, Evan Laforge wrote: However, which error msg shows up depends on the order of the (|) alternatives, and in general the global structure of the entire parser, because I think it just backtracks and then picks the last failing backtrack. Even after carefully rearranging all

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-15 Thread Erik de Castro Lopo
Evan Laforge wrote: The first is that it's hard to get the right error msg out. For instance, I have a parser that tries to parse a number with an optional type suffix. It's an error if the suffix is unrecognized: p_num :: A.Parser Score.TypedVal p_num = do num - p_untyped_num

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-15 Thread Ivan Lazar Miljenovic
On 16 March 2013 12:54, Erik de Castro Lopo mle...@mega-nerd.com wrote: Evan Laforge wrote: The first is that it's hard to get the right error msg out. For instance, I have a parser that tries to parse a number with an optional type suffix. It's an error if the suffix is unrecognized:

Re: [Haskell-cafe] attoparsec and backtracking

2013-03-15 Thread Niklas Hambüchen
Is it not possible to add an alternative (no pun intended) to | that supports the semantics Evan wants? I would agree that what attoparsec does for | of Alternative and mplus for MonadPlus is correct since e.g. the mplus laws say that a failure must be identity and therefore the following