-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
-- |
-- Module : Text.Read.Lex
import GHC.Base
import GHC.Num( Num(..), Integer )
import GHC.Show( Show(..) )
+#ifndef __HADDOCK__
import {-# SOURCE #-} GHC.Unicode ( isSpace, isAlpha, isAlphaNum )
+#endif
import GHC.Real( Ratio(..), Integral, Rational, (%), fromIntegral,
toInteger, (^), (^^), infinity, notANumber )
import GHC.List
-- -----------------------------------------------------------------------------
-- Lexing types
+-- ^ Haskell lexemes.
data Lexeme
- = Char Char -- Quotes removed,
- | String String -- escapes interpreted
- | Punc String -- Punctuation, eg "(", "::"
- | Ident String -- Haskell identifiers, e.g. foo, baz
- | Symbol String -- Haskell symbols, e.g. >>, %
- | Int Integer
- | Rat Rational
+ = Char Char -- ^ Character literal
+ | String String -- ^ String literal, with escapes interpreted
+ | Punc String -- ^ Punctuation or reserved symbol, e.g. @(@, @::@
+ | Ident String -- ^ Haskell identifier, e.g. @foo@, @Baz@
+ | Symbol String -- ^ Haskell symbol, e.g. @>>@, @:%@
+ | Int Integer -- ^ Integer literal
+ | Rat Rational -- ^ Floating point literal
| EOF
deriving (Eq, Show)
_ -> pfail
lexNumeric =
- do base <- lexBaseChar
+ do base <- lexBaseChar <++ return 10
n <- lexInteger base
guard (n <= toInteger (ord maxBound))
return (chr (fromInteger n))
return (Int (val (fromIntegral base) 0 digits))
lexBaseChar :: ReadP Int
--- Lex a single character indicating the base,
--- or return 10 if there isn't one
-lexBaseChar = lex_base <++ return 10
- where
- lex_base = do { c <- get;
- case c of
+-- Lex a single character indicating the base; fail if not there
+lexBaseChar = do { c <- get;
+ case c of
'o' -> return 8
'O' -> return 8
'x' -> return 16