Stephane Bortzmeyer wrote: > I'm trying to use Parsec for a language which have identifiers where > the '-' character is allowed only inside identifiers, not at the start > or the end. > > identifier = do > start <- letter > rest <- many (alphaNum <|> char '-') > end <- letter > return ([start] ++ rest ++ [end]) > <?> "characters authorized for identifiers"
identifier = do
start <- letter
rest <- many (alphaNum <|> try inner_minus)
return $ start : rest
where
inner_minus = do
char '-'
lookAhead alphaNum
return '-'
> because the parser created by "many" is greedy: it consumes
> everything, including the final letter.
Yes, it does. You could implement you own non-greedy many combinator,
but you get the associated inefficiency. Or you could use ReadP, which
doesn't have this problem (but replaces it with other surprises).
Udo.
--
Eagles may soar but weasels don't get sucked into jet engines.
-- Steven Wright
signature.asc
Description: Digital signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
