> I copied this example exactly from the page > http://www.cs.uu.nl/people/daan/download/parsec/parsec.html > > price = lexeme (do{ ds1 <- many1 digit > ... > However attempting to compile it gives the error message > ... > I wish I knew what that meant. If someone could explain it > and tell me what's wrong, I'd appreciate it.
The documentation for Parsec is a bit out-of-date; some things still work as described, and some things have changed. You'll have to browse the current libraries at the same time as reading the Parsec documentation to determine if a particular feature is still working as described, or if there's a newer (better?) way of doing the same thing. If you want to learn how to use the libraries, I recommend writing some very simple character/string parsers first, to see how the combinators work. Back to your parser... A lexeme parser (as described in the Parsec document) is one that consumes any trailing whitespace after the token has been read, so as to leave the next non-whitespace token ready on the input stream. The easiest way to fix the price parser is simply to add Text.ParserCombinators.Parsec.Char.spaces after the last digits have been read. price = do { ds1 <- many1 digit ; char '.' ; ds2 <- count 2 digit ; spaces -- eat trailing whitespace ; return (convert 0 (ds1 ++ ds2)) } <?> "price" where convert n [] = n convert n (d:ds) = convert (10*n + digitToInt d) ds (The lexeme function is now a record field accessor in Text.ParserCombinators.Parsec.Token. There is a data type called TokenParser, of which lexeme is one field. There's probably a way to write the price parser using TokenParser and the lexeme function/field, but I haven't figured this out yet.) Alistair. ----------------------------------------- ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe