[Haskell-cafe] Parsing words with parsec
Paolo Veronelli
paolo.veronelli at gmail.com
Sat Mar 31 11:10:04 EDT 2007
On Friday 30 March 2007 06:59, Stefan O'Rear wrote:
> Anyway, I think parsec is *far* too big a hammer for the nail you're trying
> to hit.
In the end , the big hammer solution has become
parseLine = fmap (map fst. filter snd) $ many parser
where parser = do w <- option ("",False) parseAWord
anyChar -- skip the separator
return w
parseAWord = try positive <|> (many1 nonSeparator >> return
("",False))
positive = do c <- wordChar
(cs,tn) <- option ("",True) parseAWord
return (c:cs,tn)
wordChar = letter <|> oneOf "_@" <?> "a word-character"
nonSeparator = wordChar <|> digit <?> "a non-separator"
while your, corrected not parsec solution is
wordsOfLine isNonSeparator isWordChar = (filter (all isWordChar)).
groupBy (\x y -> (isNonSeparator x) == (isNonSeparator y))
Still ,I wonder if the parsec solution can be simplified.
Thanks.
(PS. I put an option on the ML software which sends me an ack on posting , so
at least I know I sent the mail :) )
More information about the Haskell-Cafe
mailing list