[Haskell-cafe] Parsec (Zero or One of)

Paul Keir pkeir at dcs.gla.ac.uk
Tue Mar 25 11:31:19 EDT 2008



I'm having some difficulty using the Parsec library, perhaps you could
help. I've reduced my problem as shown below. I would like the
'only_prod' parser to require the reserved string "only", _optionally_
followed by an identifier. As part of 'mytest', this should then be
followed by the reserved string "end".


mytest = do { only_prod; end }

only_prod = do { reserved "only"; try identifier }

end = reserved "end"


i.e. I'd like both

> parseTest mytest "only end"


>parseTest mytest "only green end"

to parse successfully. As it stands, only the second is successful. The
first fails with:


parse error at (line 1, column 9):

unexpected end of input

expecting letter or digit or "end"


Does anyone have an idea how I could repair the situation?


Thanks in advance,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080325/aae76f05/attachment.htm

More information about the Haskell-Cafe mailing list