Haskell parsec parsing a string of items
- by Chris
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?