[Haskell-cafe] Re: Parsec : Problems with operator precedence
(solution)
Benedikt Huber
benjovi at gmx.net
Fri Jan 2 20:21:07 EST 2009
Erik de Castro Lopo schrieb:
> Erik de Castro Lopo wrote:
>
>> binaryOp :: String -> (SourcePos -> a -> a -> a) -> E.Assoc -> E.Operator Char st a
>> binaryOp name con assoc =
>> E.Infix (reservedOp name >>
>> getPosition >>=
>> return . con) assoc
>
> Replacing reservedOp above with:
>
> reservedOpNf :: String -> CharParser st ()
> reservedOpNf name = try (reservedOp name >> notFollowedBy (oneOf "|&="))
>
> fixed the problem.
>
Hi Erik,
There is an easy, better solution, modifying the lexer:
> lexer = makeTokenParser $ emptyDef
> { L.reservedOpNames = words "&& || & | ^" }
> reservedOp = P.reservedOp lexer
> identifier = P.identifier lexer
> ...
I'd try to avoid 'try', if possible.
benedikt
More information about the Haskell-Cafe
mailing list