    {-# LANGUAGE DeriveAnyClass #-}
    {-# LANGUAGE DeriveGeneric #-}
    {-# LANGUAGE Safe #-}
    module Cryptol.Parser.Token where

    import Data.Text(Text)
    import qualified Data.Text as Text
    import Control.DeepSeq
    import GHC.Generics

    import Cryptol.Utils.PP

    data Token    = Token { Token -> TokenT
    tokenType :: !TokenT, Token -> Text
    tokenText :: !Text }
                    deriving (Int -> Token -> ShowS
    [Token] -> ShowS
    Token -> String
    (Int -> Token -> ShowS)
    -> (Token -> String) -> ([Token] -> ShowS) -> Show Token
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Token -> ShowS
    showsPrec :: Int -> Token -> ShowS
    $cshow :: Token -> String
    show :: Token -> String
    $cshowList :: [Token] -> ShowS
    showList :: [Token] -> ShowS
    Show, (forall x. Token -> Rep Token x)
    -> (forall x. Rep Token x -> Token) -> Generic Token
    forall x. Rep Token x -> Token
    forall x. Token -> Rep Token x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. Token -> Rep Token x
    from :: forall x. Token -> Rep Token x
    $cto :: forall x. Rep Token x -> Token
    to :: forall x. Rep Token x -> Token
    Generic, Token -> ()
    (Token -> ()) -> NFData Token
    forall a. (a -> ()) -> NFData a
    $crnf :: Token -> ()
    rnf :: Token -> ()
    NFData)

    -- | Virtual tokens, inserted by layout processing.
    data TokenV   = VCurlyL| VCurlyR | VSemi
                    deriving (TokenV -> TokenV -> Bool
    (TokenV -> TokenV -> Bool)
    -> (TokenV -> TokenV -> Bool) -> Eq TokenV
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenV -> TokenV -> Bool
    == :: TokenV -> TokenV -> Bool
    $c/= :: TokenV -> TokenV -> Bool
    /= :: TokenV -> TokenV -> Bool
    Eq, Int -> TokenV -> ShowS
    [TokenV] -> ShowS
    TokenV -> String
    (Int -> TokenV -> ShowS)
    -> (TokenV -> String) -> ([TokenV] -> ShowS) -> Show TokenV
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenV -> ShowS
    showsPrec :: Int -> TokenV -> ShowS
    $cshow :: TokenV -> String
    show :: TokenV -> String
    $cshowList :: [TokenV] -> ShowS
    showList :: [TokenV] -> ShowS
    Show, (forall x. TokenV -> Rep TokenV x)
    -> (forall x. Rep TokenV x -> TokenV) -> Generic TokenV
    forall x. Rep TokenV x -> TokenV
    forall x. TokenV -> Rep TokenV x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenV -> Rep TokenV x
    from :: forall x. TokenV -> Rep TokenV x
    $cto :: forall x. Rep TokenV x -> TokenV
    to :: forall x. Rep TokenV x -> TokenV
    Generic, TokenV -> ()
    (TokenV -> ()) -> NFData TokenV
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenV -> ()
    rnf :: TokenV -> ()
    NFData)

    data TokenW   = BlockComment | LineComment | Space | DocStr
                    deriving (TokenW -> TokenW -> Bool
    (TokenW -> TokenW -> Bool)
    -> (TokenW -> TokenW -> Bool) -> Eq TokenW
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenW -> TokenW -> Bool
    == :: TokenW -> TokenW -> Bool
    $c/= :: TokenW -> TokenW -> Bool
    /= :: TokenW -> TokenW -> Bool
    Eq, Int -> TokenW -> ShowS
    [TokenW] -> ShowS
    TokenW -> String
    (Int -> TokenW -> ShowS)
    -> (TokenW -> String) -> ([TokenW] -> ShowS) -> Show TokenW
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenW -> ShowS
    showsPrec :: Int -> TokenW -> ShowS
    $cshow :: TokenW -> String
    show :: TokenW -> String
    $cshowList :: [TokenW] -> ShowS
    showList :: [TokenW] -> ShowS
    Show, (forall x. TokenW -> Rep TokenW x)
    -> (forall x. Rep TokenW x -> TokenW) -> Generic TokenW
    forall x. Rep TokenW x -> TokenW
    forall x. TokenW -> Rep TokenW x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenW -> Rep TokenW x
    from :: forall x. TokenW -> Rep TokenW x
    $cto :: forall x. Rep TokenW x -> TokenW
    to :: forall x. Rep TokenW x -> TokenW
    Generic, TokenW -> ()
    (TokenW -> ()) -> NFData TokenW
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenW -> ()
    rnf :: TokenW -> ()
    NFData)

    data TokenKW  = KW_else
                  | KW_fin
                  | KW_if
                  | KW_private
                  | KW_include
                  | KW_inf
                  | KW_lg2
                  | KW_lengthFromThen
                  | KW_lengthFromThenTo
                  | KW_max
                  | KW_min
                  | KW_module
                  | KW_submodule
                  | KW_newtype
                  | KW_pragma
                  | KW_property
                  | KW_then
                  | KW_type
                  | KW_where
                  | KW_let
                  | KW_x
                  | KW_import
                  | KW_as
                  | KW_hiding
                  | KW_infixl
                  | KW_infixr
                  | KW_infix
                  | KW_primitive
                  | KW_parameter
                  | KW_constraint
                  | KW_interface
                  | KW_foreign
                  | KW_Prop
                  | KW_by
                  | KW_down
                    deriving (TokenKW -> TokenKW -> Bool
    (TokenKW -> TokenKW -> Bool)
    -> (TokenKW -> TokenKW -> Bool) -> Eq TokenKW
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenKW -> TokenKW -> Bool
    == :: TokenKW -> TokenKW -> Bool
    $c/= :: TokenKW -> TokenKW -> Bool
    /= :: TokenKW -> TokenKW -> Bool
    Eq, Int -> TokenKW -> ShowS
    [TokenKW] -> ShowS
    TokenKW -> String
    (Int -> TokenKW -> ShowS)
    -> (TokenKW -> String) -> ([TokenKW] -> ShowS) -> Show TokenKW
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenKW -> ShowS
    showsPrec :: Int -> TokenKW -> ShowS
    $cshow :: TokenKW -> String
    show :: TokenKW -> String
    $cshowList :: [TokenKW] -> ShowS
    showList :: [TokenKW] -> ShowS
    Show, (forall x. TokenKW -> Rep TokenKW x)
    -> (forall x. Rep TokenKW x -> TokenKW) -> Generic TokenKW
    forall x. Rep TokenKW x -> TokenKW
    forall x. TokenKW -> Rep TokenKW x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenKW -> Rep TokenKW x
    from :: forall x. TokenKW -> Rep TokenKW x
    $cto :: forall x. Rep TokenKW x -> TokenKW
    to :: forall x. Rep TokenKW x -> TokenKW
    Generic, TokenKW -> ()
    (TokenKW -> ()) -> NFData TokenKW
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenKW -> ()
    rnf :: TokenKW -> ()
    NFData)

    -- | The named operators are a special case for parsing types, and 'Other' is
    -- used for all other cases that lexed as an operator.
    data TokenOp  = Plus | Minus | Mul | Div | Exp | Mod
                  | Equal | LEQ | GEQ
                  | Complement | Hash | At
                  | Other [Text] Text
                    deriving (TokenOp -> TokenOp -> Bool
    (TokenOp -> TokenOp -> Bool)
    -> (TokenOp -> TokenOp -> Bool) -> Eq TokenOp
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenOp -> TokenOp -> Bool
    == :: TokenOp -> TokenOp -> Bool
    $c/= :: TokenOp -> TokenOp -> Bool
    /= :: TokenOp -> TokenOp -> Bool
    Eq, Int -> TokenOp -> ShowS
    [TokenOp] -> ShowS
    TokenOp -> String
    (Int -> TokenOp -> ShowS)
    -> (TokenOp -> String) -> ([TokenOp] -> ShowS) -> Show TokenOp
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenOp -> ShowS
    showsPrec :: Int -> TokenOp -> ShowS
    $cshow :: TokenOp -> String
    show :: TokenOp -> String
    $cshowList :: [TokenOp] -> ShowS
    showList :: [TokenOp] -> ShowS
    Show, (forall x. TokenOp -> Rep TokenOp x)
    -> (forall x. Rep TokenOp x -> TokenOp) -> Generic TokenOp
    forall x. Rep TokenOp x -> TokenOp
    forall x. TokenOp -> Rep TokenOp x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenOp -> Rep TokenOp x
    from :: forall x. TokenOp -> Rep TokenOp x
    $cto :: forall x. Rep TokenOp x -> TokenOp
    to :: forall x. Rep TokenOp x -> TokenOp
    Generic, TokenOp -> ()
    (TokenOp -> ()) -> NFData TokenOp
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenOp -> ()
    rnf :: TokenOp -> ()
    NFData)

    data TokenSym = Bar
                  | ArrL | ArrR | FatArrR
                  | Lambda
                  | EqDef
                  | Comma
                  | Semi
                  | Dot
                  | DotDot
                  | DotDotDot
                  | DotDotLt
                  | DotDotGt
                  | Colon
                  | BackTick
                  | ParenL   | ParenR
                  | BracketL | BracketR
                  | CurlyL   | CurlyR
                  | TriL     | TriR
                  | Lt | Gt
                  | Underscore
                    deriving (TokenSym -> TokenSym -> Bool
    (TokenSym -> TokenSym -> Bool)
    -> (TokenSym -> TokenSym -> Bool) -> Eq TokenSym
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenSym -> TokenSym -> Bool
    == :: TokenSym -> TokenSym -> Bool
    $c/= :: TokenSym -> TokenSym -> Bool
    /= :: TokenSym -> TokenSym -> Bool
    Eq, Int -> TokenSym -> ShowS
    [TokenSym] -> ShowS
    TokenSym -> String
    (Int -> TokenSym -> ShowS)
    -> (TokenSym -> String) -> ([TokenSym] -> ShowS) -> Show TokenSym
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenSym -> ShowS
    showsPrec :: Int -> TokenSym -> ShowS
    $cshow :: TokenSym -> String
    show :: TokenSym -> String
    $cshowList :: [TokenSym] -> ShowS
    showList :: [TokenSym] -> ShowS
    Show, (forall x. TokenSym -> Rep TokenSym x)
    -> (forall x. Rep TokenSym x -> TokenSym) -> Generic TokenSym
    forall x. Rep TokenSym x -> TokenSym
    forall x. TokenSym -> Rep TokenSym x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenSym -> Rep TokenSym x
    from :: forall x. TokenSym -> Rep TokenSym x
    $cto :: forall x. Rep TokenSym x -> TokenSym
    to :: forall x. Rep TokenSym x -> TokenSym
    Generic, TokenSym -> ()
    (TokenSym -> ()) -> NFData TokenSym
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenSym -> ()
    rnf :: TokenSym -> ()
    NFData)

    data TokenErr = UnterminatedComment
                  | UnterminatedString
                  | UnterminatedChar
                  | InvalidString
                  | InvalidChar
                  | LexicalError
                  | MalformedLiteral
                  | MalformedSelector
                  | InvalidIndentation TokenT -- expected closing paren
                    deriving (TokenErr -> TokenErr -> Bool
    (TokenErr -> TokenErr -> Bool)
    -> (TokenErr -> TokenErr -> Bool) -> Eq TokenErr
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenErr -> TokenErr -> Bool
    == :: TokenErr -> TokenErr -> Bool
    $c/= :: TokenErr -> TokenErr -> Bool
    /= :: TokenErr -> TokenErr -> Bool
    Eq, Int -> TokenErr -> ShowS
    [TokenErr] -> ShowS
    TokenErr -> String
    (Int -> TokenErr -> ShowS)
    -> (TokenErr -> String) -> ([TokenErr] -> ShowS) -> Show TokenErr
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenErr -> ShowS
    showsPrec :: Int -> TokenErr -> ShowS
    $cshow :: TokenErr -> String
    show :: TokenErr -> String
    $cshowList :: [TokenErr] -> ShowS
    showList :: [TokenErr] -> ShowS
    Show, (forall x. TokenErr -> Rep TokenErr x)
    -> (forall x. Rep TokenErr x -> TokenErr) -> Generic TokenErr
    forall x. Rep TokenErr x -> TokenErr
    forall x. TokenErr -> Rep TokenErr x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenErr -> Rep TokenErr x
    from :: forall x. TokenErr -> Rep TokenErr x
    $cto :: forall x. Rep TokenErr x -> TokenErr
    to :: forall x. Rep TokenErr x -> TokenErr
    Generic, TokenErr -> ()
    (TokenErr -> ()) -> NFData TokenErr
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenErr -> ()
    rnf :: TokenErr -> ()
    NFData)

    data SelectorType = RecordSelectorTok Text | TupleSelectorTok Int
                    deriving (SelectorType -> SelectorType -> Bool
    (SelectorType -> SelectorType -> Bool)
    -> (SelectorType -> SelectorType -> Bool) -> Eq SelectorType
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SelectorType -> SelectorType -> Bool
    == :: SelectorType -> SelectorType -> Bool
    $c/= :: SelectorType -> SelectorType -> Bool
    /= :: SelectorType -> SelectorType -> Bool
    Eq, Int -> SelectorType -> ShowS
    [SelectorType] -> ShowS
    SelectorType -> String
    (Int -> SelectorType -> ShowS)
    -> (SelectorType -> String)
    -> ([SelectorType] -> ShowS)
    -> Show SelectorType
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SelectorType -> ShowS
    showsPrec :: Int -> SelectorType -> ShowS
    $cshow :: SelectorType -> String
    show :: SelectorType -> String
    $cshowList :: [SelectorType] -> ShowS
    showList :: [SelectorType] -> ShowS
    Show, (forall x. SelectorType -> Rep SelectorType x)
    -> (forall x. Rep SelectorType x -> SelectorType)
    -> Generic SelectorType
    forall x. Rep SelectorType x -> SelectorType
    forall x. SelectorType -> Rep SelectorType x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. SelectorType -> Rep SelectorType x
    from :: forall x. SelectorType -> Rep SelectorType x
    $cto :: forall x. Rep SelectorType x -> SelectorType
    to :: forall x. Rep SelectorType x -> SelectorType
    Generic, SelectorType -> ()
    (SelectorType -> ()) -> NFData SelectorType
    forall a. (a -> ()) -> NFData a
    $crnf :: SelectorType -> ()
    rnf :: SelectorType -> ()
    NFData)

    data TokenT   = Num !Integer !Int !Int    -- ^ value, base, number of digits
                  | Frac !Rational !Int       -- ^ value, base.
                  | ChrLit  !Char             -- ^ character literal
                  | Ident ![Text] !Text       -- ^ (qualified) identifier
                  | StrLit !String            -- ^ string literal
                  | Selector !SelectorType    -- ^ .hello or .123
                  | KW    !TokenKW            -- ^ keyword
                  | Op    !TokenOp            -- ^ operator
                  | Sym   !TokenSym           -- ^ symbol
                  | Virt  !TokenV             -- ^ virtual token (for layout)
                  | White !TokenW             -- ^ white space token
                  | Err   !TokenErr           -- ^ error token
                  | EOF
                    deriving (TokenT -> TokenT -> Bool
    (TokenT -> TokenT -> Bool)
    -> (TokenT -> TokenT -> Bool) -> Eq TokenT
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TokenT -> TokenT -> Bool
    == :: TokenT -> TokenT -> Bool
    $c/= :: TokenT -> TokenT -> Bool
    /= :: TokenT -> TokenT -> Bool
    Eq, Int -> TokenT -> ShowS
    [TokenT] -> ShowS
    TokenT -> String
    (Int -> TokenT -> ShowS)
    -> (TokenT -> String) -> ([TokenT] -> ShowS) -> Show TokenT
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TokenT -> ShowS
    showsPrec :: Int -> TokenT -> ShowS
    $cshow :: TokenT -> String
    show :: TokenT -> String
    $cshowList :: [TokenT] -> ShowS
    showList :: [TokenT] -> ShowS
    Show, (forall x. TokenT -> Rep TokenT x)
    -> (forall x. Rep TokenT x -> TokenT) -> Generic TokenT
    forall x. Rep TokenT x -> TokenT
    forall x. TokenT -> Rep TokenT x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. TokenT -> Rep TokenT x
    from :: forall x. TokenT -> Rep TokenT x
    $cto :: forall x. Rep TokenT x -> TokenT
    to :: forall x. Rep TokenT x -> TokenT
    Generic, TokenT -> ()
    (TokenT -> ()) -> NFData TokenT
    forall a. (a -> ()) -> NFData a
    $crnf :: TokenT -> ()
    rnf :: TokenT -> ()
    NFData)

    instance PP Token where
      ppPrec :: Int -> Token -> Doc
    ppPrec Int
    _ (Token TokenT
    _ Text
    s) = String -> Doc
    text (Text -> String
    Text.unpack Text
    s)