module Agda.Syntax.Parser.Tokens
    ( Token(..)
    , Keyword(..)
    , layoutKeywords
    , Symbol(..)
    ) where

import Agda.Syntax.Literal (RLiteral)
import Agda.Syntax.Position

data Keyword
        = KwLet | KwIn | KwWhere | KwData | KwCoData | KwDo
        | KwPostulate | KwAbstract | KwPrivate | KwInstance
        | KwInterleaved | KwMutual
        | KwOverlap
        | KwOpen | KwImport | KwModule | KwPrimitive | KwMacro
        | KwInfix | KwInfixL | KwInfixR | KwWith | KwRewrite
        | KwForall | KwRecord | KwConstructor | KwField
        | KwInductive | KwCoInductive
        | KwEta | KwNoEta
        | KwHiding | KwUsing | KwRenaming | KwTo | KwPublic
        | KwOPTIONS | KwBUILTIN | KwLINE
        | KwFOREIGN | KwCOMPILE
        | KwIMPOSSIBLE | KwSTATIC | KwINJECTIVE | KwINLINE | KwNOINLINE
        | KwETA
        | KwNO_TERMINATION_CHECK | KwTERMINATING | KwNON_TERMINATING
        | KwNOT_PROJECTION_LIKE
        | KwNON_COVERING
        | KwWARNING_ON_USAGE | KwWARNING_ON_IMPORT
        | KwMEASURE | KwDISPLAY
        | KwREWRITE
        | KwQuote | KwQuoteTerm
        | KwUnquote | KwUnquoteDecl | KwUnquoteDef
        | KwSyntax
        | KwPatternSyn | KwTactic | KwCATCHALL
        | KwVariable
        | KwNO_POSITIVITY_CHECK | KwPOLARITY
        | KwNO_UNIVERSE_CHECK
    deriving (Keyword -> Keyword -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Keyword -> Keyword -> Bool
$c/= :: Keyword -> Keyword -> Bool
== :: Keyword -> Keyword -> Bool
$c== :: Keyword -> Keyword -> Bool
Eq, Int -> Keyword -> ShowS
[Keyword] -> ShowS
Keyword -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Keyword] -> ShowS
$cshowList :: [Keyword] -> ShowS
show :: Keyword -> String
$cshow :: Keyword -> String
showsPrec :: Int -> Keyword -> ShowS
$cshowsPrec :: Int -> Keyword -> ShowS
Show)

-- | Unconditional layout keywords.
--
-- Some keywords introduce layout only in certain circumstances,
-- these are not included here.
--
layoutKeywords :: [Keyword]
layoutKeywords :: [Keyword]
layoutKeywords =
    [ Keyword
KwAbstract
    , Keyword
KwDo
    , Keyword
KwField
    , Keyword
KwInstance
    , Keyword
KwLet
    , Keyword
KwMacro
    , Keyword
KwMutual
    , Keyword
KwPostulate
    , Keyword
KwPrimitive
    , Keyword
KwPrivate
    , Keyword
KwVariable
    , Keyword
KwWhere
    ]

data Symbol
        = SymDot | SymSemi | SymVirtualSemi | SymBar
        | SymColon | SymArrow | SymEqual | SymLambda
        | SymUnderscore | SymQuestionMark   | SymAs
        | SymOpenParen        | SymCloseParen
        | SymOpenIdiomBracket | SymCloseIdiomBracket | SymEmptyIdiomBracket
        | SymDoubleOpenBrace  | SymDoubleCloseBrace
        | SymOpenBrace        | SymCloseBrace
        | SymOpenVirtualBrace | SymCloseVirtualBrace
        | SymOpenPragma       | SymClosePragma | SymEllipsis | SymDotDot
        | SymEndComment -- ^ A misplaced end-comment "-}".
    deriving (Symbol -> Symbol -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Symbol -> Symbol -> Bool
$c/= :: Symbol -> Symbol -> Bool
== :: Symbol -> Symbol -> Bool
$c== :: Symbol -> Symbol -> Bool
Eq, Int -> Symbol -> ShowS
[Symbol] -> ShowS
Symbol -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Symbol] -> ShowS
$cshowList :: [Symbol] -> ShowS
show :: Symbol -> String
$cshow :: Symbol -> String
showsPrec :: Int -> Symbol -> ShowS
$cshowsPrec :: Int -> Symbol -> ShowS
Show)

data Token
          -- Keywords
        = TokKeyword Keyword Interval
          -- Identifiers and operators
        | TokId         (Interval, String)
        | TokQId        [(Interval, String)]
                        -- Non-empty namespace. The intervals for
                        -- "A.B.x" correspond to "A.", "B." and "x".
          -- Literals
        | TokLiteral    RLiteral
          -- Special symbols
        | TokSymbol Symbol Interval
          -- Other tokens
        | TokString (Interval, String)
            -- ^ Arbitrary string (not enclosed in double quotes), used in pragmas.
        | TokTeX (Interval, String)
        | TokMarkup (Interval, String)
        | TokComment (Interval, String)
        | TokDummy      -- Dummy token to make Happy not complain
                        -- about overlapping cases.
        | TokEOF Interval
    deriving (Token -> Token -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Token -> Token -> Bool
$c/= :: Token -> Token -> Bool
== :: Token -> Token -> Bool
$c== :: Token -> Token -> Bool
Eq, Int -> Token -> ShowS
[Token] -> ShowS
Token -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Token] -> ShowS
$cshowList :: [Token] -> ShowS
show :: Token -> String
$cshow :: Token -> String
showsPrec :: Int -> Token -> ShowS
$cshowsPrec :: Int -> Token -> ShowS
Show)

instance HasRange Token where
  getRange :: Token -> Range
getRange (TokKeyword Keyword
_ Interval
i)    = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange (TokId (Interval
i, String
_))      = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange (TokQId [(Interval, String)]
iss)        = forall a. HasRange a => a -> Range
getRange (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Interval, String)]
iss)
  getRange (TokLiteral RLiteral
lit)    = forall a. HasRange a => a -> Range
getRange RLiteral
lit
  getRange (TokSymbol Symbol
_ Interval
i)     = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange (TokString (Interval
i, String
_))  = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange (TokTeX (Interval
i, String
_))     = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange (TokMarkup (Interval
i, String
_))  = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange (TokComment (Interval
i, String
_)) = forall a. HasRange a => a -> Range
getRange Interval
i
  getRange Token
TokDummy            = forall a. Range' a
noRange
  getRange (TokEOF Interval
i)          = forall a. HasRange a => a -> Range
getRange Interval
i