Fixed the C-- lexer to comply with the standard on hex escape sequences.
[ghc-hetmet.git] / compiler / cmm / CmmLex.x
index c2efd17..cc47796 100644 (file)
@@ -1,5 +1,6 @@
 -----------------------------------------------------------------------------
--- (c) The University of Glasgow, 2004
+--
+-- (c) The University of Glasgow, 2004-2006
 --
 -- Lexer for concrete Cmm.  We try to stay close to the C-- spec, but there
 -- are a few minor differences:
@@ -24,7 +25,7 @@ import UniqFM
 import StringBuffer
 import FastString
 import Ctype
-import Util            ( readRational )
+import Util
 --import TRACE
 }
 
@@ -32,16 +33,16 @@ $whitechar   = [\ \t\n\r\f\v\xa0]
 $white_no_nl = $whitechar # \n
 
 $ascdigit  = 0-9
-$unidigit  = \x01
+$unidigit  = \x01 -- Trick Alex into handling Unicode. See alexGetChar.
 $digit     = [$ascdigit $unidigit]
 $octit    = 0-7
 $hexit     = [$digit A-F a-f]
 
-$unilarge  = \x03
+$unilarge  = \x03 -- Trick Alex into handling Unicode. See alexGetChar.
 $asclarge  = [A-Z \xc0-\xd6 \xd8-\xde]
 $large     = [$asclarge $unilarge]
 
-$unismall  = \x04
+$unismall  = \x04 -- Trick Alex into handling Unicode. See alexGetChar.
 $ascsmall  = [a-z \xdf-\xf6 \xf8-\xff]
 $small     = [$ascsmall $unismall \_]
 
@@ -55,7 +56,7 @@ $namechar  = [$namebegin $digit]
 
 @floating_point = @decimal \. @decimal @exponent? | @decimal @exponent
 
-@escape      = \\ ([abfnrt\\\'\"\?] | x @hexadecimal | @octal)
+@escape      = \\ ([abfnrt\\\'\"\?] | x $hexit{1,2} | $octit{1,3})
 @strchar     = ($printable # [\"\\]) | @escape
 
 cmm :-
@@ -137,6 +138,7 @@ data CmmToken
   | CmmT_if
   | CmmT_jump
   | CmmT_foreign
+  | CmmT_prim
   | CmmT_import
   | CmmT_switch
   | CmmT_case
@@ -211,6 +213,7 @@ reservedWordsFM = listToUFM $
        ( "if",                 CmmT_if ),
        ( "jump",               CmmT_jump ),
        ( "foreign",            CmmT_foreign ),
+       ( "prim",               CmmT_prim ),
        ( "import",             CmmT_import ),
        ( "switch",             CmmT_switch ),
        ( "case",               CmmT_case ),
@@ -274,7 +277,7 @@ lexToken = do
   sc <- getLexState
   case alexScan inp sc of
     AlexEOF -> do let span = mkSrcSpan loc1 loc1
-                 setLastToken span 0
+                 setLastToken span 0 0
                  return (L span CmmT_EOF)
     AlexError (loc2,_) -> do failLocMsgP loc1 loc2 "lexical error"
     AlexSkip inp2 _ -> do
@@ -283,7 +286,7 @@ lexToken = do
     AlexToken inp2@(end,buf2) len t -> do
        setInput inp2
        let span = mkSrcSpan loc1 end
-       span `seq` setLastToken span len
+       span `seq` setLastToken span len len
        t span buf len
 
 -- -----------------------------------------------------------------------------