Haskell parsec parsing a string of items

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-03-15T16:23:30Z Indexed on 2010/03/15 18:29 UTC
Read the original article Hit count: 361

Filed under:
|

I have a list that I need to parse where the all but the last element needs to be parsed by one parser, and the last element needs to be parsed by another parser.

a = "p1 p1b ... p2"
or
a = "p2"

Originally I tried

parser = do parse1 <- many parser1
            parse2 <- parser2
            return AParse parse1 parse2

The problem is that parse1 can consume a parse2 input. So parse1 always consumes the entire list, and leave parse2 with nothing.

Is there a way to say to apply parse1 to everything besides the last element in a string, and then apply parse2?

© Stack Overflow or respective owner

Related posts about haskell

Related posts about parsec