X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fparser%2FLexCore.hs;h=9109c0469af980dd6c2397a31afab50bb38b6ef6;hp=32ea6a83953c1cb20ba2d6fefea3b5dc0f5d334b;hb=de777ba42eb12b6a20e548a959b23b60179d9b57;hpb=a7515ed727fc7e50ad9a59864f20cb4ddc93fb20 diff --git a/compiler/parser/LexCore.hs b/compiler/parser/LexCore.hs index 32ea6a8..9109c04 100644 --- a/compiler/parser/LexCore.hs +++ b/compiler/parser/LexCore.hs @@ -3,10 +3,10 @@ module LexCore where import ParserCoreUtils import Ratio import Char -import qualified Numeric( readFloat, readDec ) +import Numeric isNameChar c = isAlpha c || isDigit c || (c == '_') || (c == '\'') - || (c == ':') || (c == '$') + || (c == '$') || (c == '-') || (c == '.') isKeywordChar c = isAlpha c || (c == '_') lexer :: (Token -> P a) -> P a @@ -29,6 +29,7 @@ lexer cont (')':cs) = cont TKcparen cs lexer cont ('{':cs) = cont TKobrace cs lexer cont ('}':cs) = cont TKcbrace cs lexer cont ('=':cs) = cont TKeq cs +lexer cont (':':'=':':':cs) = cont TKcoloneqcolon cs lexer cont (':':':':cs) = cont TKcoloncolon cs lexer cont ('*':cs) = cont TKstar cs lexer cont ('.':cs) = cont TKdot cs @@ -37,7 +38,9 @@ lexer cont ('@':cs) = cont TKat cs lexer cont ('?':cs) = cont TKquestion cs lexer cont (';':cs) = cont TKsemicolon cs -- 20060420 GHC spits out constructors with colon in them nowadays. jds -lexer cont (':':cs) = lexName cont TKcname (':':cs) +-- 20061103 but it's easier to parse if we split on the colon, and treat them +-- as several tokens +lexer cont (':':cs) = cont TKcolon cs -- 20060420 Likewise does it create identifiers starting with dollar. jds lexer cont ('$':cs) = lexName cont TKname ('$':cs) lexer cont (c:cs) = failP "invalid character" [c] @@ -91,45 +94,10 @@ lexKeyword cont cs = ("in",rest) -> cont TKin rest ("case",rest) -> cont TKcase rest ("of",rest) -> cont TKof rest - ("coerce",rest) -> cont TKcoerce rest + ("cast",rest) -> cont TKcast rest ("note",rest) -> cont TKnote rest ("external",rest) -> cont TKexternal rest + ("local",rest) -> cont TKlocal rest ("_",rest) -> cont TKwild rest _ -> failP "invalid keyword" ('%':cs) - -#if __GLASGOW_HASKELL__ >= 504 --- The readFloat in the Numeric library will do the job - -readFloat :: (RealFrac a) => ReadS a -readFloat = Numeric.readFloat - -#else --- Haskell 98's Numeric.readFloat used to have a bogusly restricted signature --- so it was incapable of reading a rational. --- So for GHCs that have that old bogus library, here is the code, written out longhand. - -readFloat r = [(fromRational ((n%1)*10^^(k-d)),t) | (n,d,s) <- readFix r, - (k,t) <- readExp s] ++ - [ (0/0, t) | ("NaN",t) <- lex r] ++ - [ (1/0, t) | ("Infinity",t) <- lex r] - where - readFix r = [(read (ds++ds'), length ds', t) - | (ds,d) <- lexDigits r, - (ds',t) <- lexFrac d ] - - lexFrac ('.':ds) = lexDigits ds - lexFrac s = [("",s)] - - readExp (e:s) | e `elem` "eE" = readExp' s - readExp s = [(0,s)] - - readExp' ('-':s) = [(-k,t) | (k,t) <- Numeric.readDec s] - readExp' ('+':s) = Numeric.readDec s - readExp' s = Numeric.readDec s - -lexDigits :: ReadS String -lexDigits s = case span isDigit s of - (cs,s') | not (null cs) -> [(cs,s')] - otherwise -> [] -#endif