Stephane Bortzmeyer <[EMAIL PROTECTED]> wrote:

> 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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to