
27 Apr
2007
27 Apr
'07
12:58 p.m.
Jim Burton wrote:
After posting I realised the difference between parsing "(a)" <|> "(b)" and parsing "a" <|> "aa" ... so Parsec doesn't do the latter well or at all?
It should do (try "aa") <|> "a" just fine. If you mean a general sequence of "a"s then (many1 (char "a")) should do. The Morse Code problem is a little harder though. To handle the ambiguity you may need to simultaneously consider possible parses of the dots and dashes. I suggest you look into using the List monad. As for the actual parsing of the dots and dashes, Parsec may be overkill.