Changeset 13183 for src/Pugs/Lexer.hs

Show
Ignore:
Timestamp:
09/11/06 16:31:53 (2 years ago)
Author:
audreyt
Message:

* Add support for character name escapes:

say "\c[LATIN CAPITAL LETTER Y]";

With Perl 5 embedding, the full Unicode range is supported via
charnames.pm. Without Perl 5 embedding (e.g. in "make ghci"),
only codepoints in the range 0x00-0xFF are supported.

Note: Now Perl5 embedding is on by default, we can implement
more "core" Pugs functionalities this way, instead of maintaining
huge amount of duplicate information. (Encode.pm comes to mind.)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Lexer.hs

    r13177 r13183  
    3131import Pugs.Types 
    3232import Pugs.Parser.Types 
     33import Pugs.Parser.Charnames 
    3334 
    3435identStart, identLetter :: RuleParser Char 
     
    265266 
    266267charControl :: RuleParser Char 
    267 charControl     = do{ char 'c' 
    268                     ; code <- upper <|> char '@' 
    269                     ; return (toEnum (fromEnum code - fromEnum '@')) 
    270                     } 
     268charControl = do 
     269    char 'c' 
     270    code <- upper <|> oneOf "@[" 
     271    case code of 
     272        '[' -> do 
     273            charName <- many (satisfy (/= ']')) 
     274            char ']' 
     275            case nameToCode charName of 
     276                Just c  -> return (chr c) 
     277                _       -> error $ "Invalid unicode character name: " ++ charName 
     278        _   -> return (toEnum (fromEnum code - fromEnum '@')) 
    271279 
    272280-- This is currently the only escape that can return multiples. 
     
    483491                     
    484492fractExponent n = do{ fract <- fraction 
    485                     ; expo  <- option 1.0 exponent' 
     493                    ; expo  <- option (1.0 :: Double) exponent' 
    486494                    ; return ((fromInteger n + fract)*expo) 
    487495                    } 
     
    493501fraction        = do{ char '.' 
    494502                    ; digits <- many1 digit <?> "fraction" 
    495                     ; return (foldr op 0.0 digits) 
     503                    ; return (foldr op (0.0 :: Double) digits) 
    496504                    } 
    497505                    <?> "fraction" 
    498506                where 
    499                     op d f    = (f + fromIntegral (digitToInt d))/10.0 
     507                    op d f    = (f + fromIntegral (digitToInt d)) / (10.0 :: Double) 
    500508                     
    501509exponent'       = do{ oneOf "eE"