
5 Sep
2006
5 Sep
'06
2:31 p.m.
Stephane Bortzmeyer
identifier = do start <- letter rest <- many (alphaNum <|> char '-') end <- letter return ([start] ++ rest ++ [end]) > "characters authorized for identifiers"
because the parser created by "many" is greedy: it consumes everything, including the final letter.
How about eating chunks of alphaNum, then chunks of '-', in alternation. You just need to flatten the returned list of words to a single word. identifier = do init <- many alphaNum rest <- many ( do dash <- many1 (char '-') alfa <- many1 alphaNum return (dash++alfa) ) return (concat (init:rest)) Regards, Malcolm