
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

Ok, I managed it by using a modified sepBy / sepBy1: /" ... x//s////<-////many////(//sep////>>////p//) ... "/ changed to /" ... x//s////<-////many////(//try (sep////>>////p//)) ..."/ Regards, Tobias/ /On 10/12/2012 07:20 PM, Tobias wrote:
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hi Tobias, the "proper" way is to skip white spaces after each token. Leading white spaces are skipped only once at the beginning. lex :: Parser a -> Parser a lex = (<* spaces) -- skip trailing blanks sentence = many (lex word) <* lex (oneOf ".?!") -- finally alltext = spaces *> many sentence HTH Christian Am 12.10.2012 19:20, schrieb Tobias:
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
participants (2)
-
Christian Maeder
-
Tobias