[Haskell-beginners] parsec problem

Tobias tobnels at freenet.de
Fri Oct 12 19:20:42 CEST 2012


Hello,

I would like to parse the input "word1 word2 word3 ." into 
["word1","word2","word3"] using Parsec.

My code below fails with:
/> unexpected "."//
//> expecting letter or digit

/I guess the problem is that the blank before the dot is considered as 
belonging to the "sepBy word blank" parsing and therefore a next word is 
expected, and it is missing.
I would like the "sepBy word blank" parsing to stop after "word3".
How can I do this?
/
//sentence :: Parser [String]//
//sentence =  do words <- word `sepBy` blank//
//                         blank//
//                         oneOf ".?!"//
//                         return words//
//
//word :: Parser String//
//word = many1 (letter <|> digit) //
//
//blank :: Parser String//
//blank = string " "

/Regards,
Tobias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121012/48a1d031/attachment.htm>


More information about the Beginners mailing list