Ticket #5740: 0001-remove-tabs-ignore-tabs-option-from-LexCore.hs.patch

File 0001-remove-tabs-ignore-tabs-option-from-LexCore.hs.patch, 5.1 KB (added by nsch, 3 years ago)
  • compiler/parser/LexCore.hs

    From a555222974bf4bbd1e48b9267a05e62fce548c84 Mon Sep 17 00:00:00 2001
    From: Nils Schweinsberg <[email protected]>
    Date: Tue, 3 Jan 2012 00:48:04 +0100
    Subject: [PATCH] remove tabs (+ ignore tabs option) from LexCore.hs
    
    ---
     compiler/parser/LexCore.hs |   72 +++++++++++++++++++------------------------
     1 files changed, 32 insertions(+), 40 deletions(-)
    
    diff --git a/compiler/parser/LexCore.hs b/compiler/parser/LexCore.hs
    index b3d8d63..3e37e06 100644
    a b  
    1  
    2 {-# OPTIONS -fno-warn-tabs #-} 
    3 -- The above warning supression flag is a temporary kludge. 
    4 -- While working on this module you are encouraged to remove it and 
    5 -- detab the module (please do the detabbing in a separate patch). See 
    6 --     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces 
    7 -- for details 
    8  
    91module LexCore where 
    102 
    113import ParserCoreUtils 
    import Numeric 
    157 
    168isNameChar :: Char -> Bool 
    179isNameChar c = isAlpha c || isDigit c || (c == '_') || (c == '\'') 
    18                || (c == '$') || (c == '-') || (c == '.') 
     10               || (c == '$') || (c == '-') || (c == '.') 
    1911 
    2012isKeywordChar :: Char -> Bool 
    21 isKeywordChar c = isAlpha c || (c == '_')  
     13isKeywordChar c = isAlpha c || (c == '_') 
    2214 
    2315lexer :: (Token -> P a) -> P a  
    24 lexer cont []           = cont TKEOF [] 
    25 lexer cont ('\n':cs)    = \line -> lexer cont cs (line+1) 
     16lexer cont []           = cont TKEOF [] 
     17lexer cont ('\n':cs)    = \line -> lexer cont cs (line+1) 
    2618lexer cont ('-':'>':cs) = cont TKrarrow cs 
    2719 
    2820lexer cont (c:cs)  
    29       | isSpace c               = lexer cont cs 
     21      | isSpace c               = lexer cont cs 
    3022      | isLower c || (c == '_') = lexName cont TKname (c:cs) 
    31       | isUpper c               = lexName cont TKcname (c:cs) 
     23      | isUpper c               = lexName cont TKcname (c:cs) 
    3224      | isDigit c || (c == '-') = lexNum cont (c:cs) 
    3325 
    34 lexer cont ('%':cs)     = lexKeyword cont cs 
    35 lexer cont ('\'':cs)    = lexChar cont cs 
    36 lexer cont ('\"':cs)    = lexString [] cont cs  
    37 lexer cont ('#':cs)     = cont TKhash cs 
    38 lexer cont ('(':cs)     = cont TKoparen cs 
    39 lexer cont (')':cs)     = cont TKcparen cs 
    40 lexer cont ('{':cs)     = cont TKobrace cs 
    41 lexer cont ('}':cs)     = cont TKcbrace cs 
     26lexer cont ('%':cs)     = lexKeyword cont cs 
     27lexer cont ('\'':cs)    = lexChar cont cs 
     28lexer cont ('\"':cs)    = lexString [] cont cs  
     29lexer cont ('#':cs)     = cont TKhash cs 
     30lexer cont ('(':cs)     = cont TKoparen cs 
     31lexer cont (')':cs)     = cont TKcparen cs 
     32lexer cont ('{':cs)     = cont TKobrace cs 
     33lexer cont ('}':cs)     = cont TKcbrace cs 
    4234lexer cont ('=':cs)     = cont TKeq cs 
    4335lexer cont (':':'=':':':cs) = cont TKcoloneqcolon cs 
    4436lexer cont (':':':':cs) = cont TKcoloncolon cs 
    45 lexer cont ('*':cs)     = cont TKstar cs 
    46 lexer cont ('.':cs)     = cont TKdot cs 
     37lexer cont ('*':cs)     = cont TKstar cs 
     38lexer cont ('.':cs)     = cont TKdot cs 
    4739lexer cont ('\\':cs)    = cont TKlambda cs 
    48 lexer cont ('@':cs)     = cont TKat cs 
    49 lexer cont ('?':cs)     = cont TKquestion cs 
    50 lexer cont (';':cs)     = cont TKsemicolon cs 
     40lexer cont ('@':cs)     = cont TKat cs 
     41lexer cont ('?':cs)     = cont TKquestion cs 
     42lexer cont (';':cs)     = cont TKsemicolon cs 
    5143-- 20060420 GHC spits out constructors with colon in them nowadays. jds 
    5244-- 20061103 but it's easier to parse if we split on the colon, and treat them 
    5345-- as several tokens 
    lexNum :: (Token -> String -> a) -> String -> a 
    8678lexNum cont cs = 
    8779  case cs of 
    8880     ('-':cs) -> f (-1) cs 
    89      _        -> f 1 cs 
     81     _        -> f 1 cs 
    9082 where f sgn cs =  
    9183         case span isDigit cs of 
    9284          (digits,'.':c:rest)  
    93                 | isDigit c -> cont (TKrational (fromInteger sgn * r)) rest' 
    94                 where ((r,rest'):_) = readFloat (digits ++ ('.':c:rest)) 
    95                 -- When reading a floating-point number, which is 
    96                 -- a bit complicated, use the standard library function 
     85                | isDigit c -> cont (TKrational (fromInteger sgn * r)) rest' 
     86                where ((r,rest'):_) = readFloat (digits ++ ('.':c:rest)) 
     87                -- When reading a floating-point number, which is 
     88                -- a bit complicated, use the standard library function 
    9789                -- "readFloat" 
    9890          (digits,rest) -> cont (TKinteger (sgn * (read digits))) rest 
    9991 
    lexKeyword cont cs = 
    108100      ("module",rest) -> cont TKmodule rest 
    109101      ("data",rest)  -> cont TKdata rest 
    110102      ("newtype",rest) -> cont TKnewtype rest 
    111       ("forall",rest) -> cont TKforall rest      
    112       ("rec",rest) -> cont TKrec rest    
    113       ("let",rest) -> cont TKlet rest    
    114       ("in",rest) -> cont TKin rest      
    115       ("case",rest) -> cont TKcase rest  
    116       ("of",rest) -> cont TKof rest      
    117       ("cast",rest) -> cont TKcast rest  
    118       ("note",rest) -> cont TKnote rest  
     103      ("forall",rest) -> cont TKforall rest 
     104      ("rec",rest) -> cont TKrec rest 
     105      ("let",rest) -> cont TKlet rest 
     106      ("in",rest) -> cont TKin rest 
     107      ("case",rest) -> cont TKcase rest 
     108      ("of",rest) -> cont TKof rest 
     109      ("cast",rest) -> cont TKcast rest 
     110      ("note",rest) -> cont TKnote rest 
    119111      ("external",rest) -> cont TKexternal rest 
    120112      ("local",rest) -> cont TKlocal rest 
    121113      ("_",rest) -> cont TKwild rest