[Haskell-cafe] [Parsec] No identEnd in ParsecToken?

Udo Stenzel u.stenzel at web.de
Tue Sep 5 11:06:37 EDT 2006


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 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060905/22ef6c4e/attachment.bin


More information about the Haskell-Cafe mailing list