---> being mislexed at the start of a line?
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sat Feb 21 12:29:55 EST 2004
igloo:
>
> Looks like ---> at the start of a line is being mislexed as >:
>
> $ cat Q.hs
>
> module Q where
> a ---> b = a + a
> foo = 3
> ---> 4
> ---> 5
> $ ghc -c Q.hs -ddump-parsed
>
> ==================== Parser ====================
> module Q where
> ---> a b = a + a
> foo = (3 > 4) > 5
>
>
>
> Q.hs:4:6:
> precedence parsing error
> cannot mix `(>)' [infix 4] and `(>)' [infix 4] in the same infix expression
Now, this should be lexed as a varsym, and looking through
compiler/parser/Lexer.x, you see the single line comment parsing code:
line 111:
"--"\-* ([^$symbol] .*)? ;
The associated comment:
The regex says: "munch all the characters after the dashes, as
long as the first one is not a symbol".
But I read the whole regex as:
"Munch dashes. Also munch all characters after the dashes, as
long as the first one is not a symbol".
There's the bug, I think. So none of these will work either: --> --<
-->= etc. So the regex might need to explicitly match varsyms, and rule
them out first. A quick hack:
"--"\-* $symbol+ { goto varsym code }
"--"\-* .* ;
-- Don
More information about the Cvs-ghc
mailing list