{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}

module Haddock.Backends.Hyperlinker.Types where

import Data.ByteString (ByteString)
import Data.Map (Map)
import qualified GHC

data Token = Token
  { Token -> TokenType
tkType :: TokenType
  , Token -> ByteString
tkValue :: ByteString
  -- ^ UTF-8 encoded
  , Token -> Span
tkSpan :: {-# UNPACK #-} !Span
  }
  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)

pattern BacktickTok, OpenParenTok, CloseParenTok :: Span -> Token
pattern $mBacktickTok :: forall {r}. Token -> (Span -> r) -> ((# #) -> r) -> r
$bBacktickTok :: Span -> Token
BacktickTok sp = Token TkSpecial "`" sp
pattern $mOpenParenTok :: forall {r}. Token -> (Span -> r) -> ((# #) -> r) -> r
$bOpenParenTok :: Span -> Token
OpenParenTok sp = Token TkSpecial "(" sp
pattern $mCloseParenTok :: forall {r}. Token -> (Span -> r) -> ((# #) -> r) -> r
$bCloseParenTok :: Span -> Token
CloseParenTok sp = Token TkSpecial ")" sp

type Position = GHC.RealSrcLoc
type Span = GHC.RealSrcSpan

data TokenType
  = TkIdentifier
  | TkKeyword
  | TkString
  | TkChar
  | TkNumber
  | TkOperator
  | TkGlyph
  | TkSpecial
  | TkSpace
  | TkComment
  | TkCpp
  | TkPragma
  | TkUnknown
  deriving (Int -> TokenType -> ShowS
[TokenType] -> ShowS
TokenType -> String
(Int -> TokenType -> ShowS)
-> (TokenType -> String)
-> ([TokenType] -> ShowS)
-> Show TokenType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TokenType -> ShowS
showsPrec :: Int -> TokenType -> ShowS
$cshow :: TokenType -> String
show :: TokenType -> String
$cshowList :: [TokenType] -> ShowS
showList :: [TokenType] -> ShowS
Show, TokenType -> TokenType -> Bool
(TokenType -> TokenType -> Bool)
-> (TokenType -> TokenType -> Bool) -> Eq TokenType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TokenType -> TokenType -> Bool
== :: TokenType -> TokenType -> Bool
$c/= :: TokenType -> TokenType -> Bool
/= :: TokenType -> TokenType -> Bool
Eq)

-- | Path for making cross-package hyperlinks in generated sources.
--
-- Used in 'SrcMap' to determine whether module originates in current package
-- or in an external package.
data SrcPath
  = SrcExternal FilePath
  | SrcLocal

-- | Mapping from modules to cross-package source paths.
type SrcMaps = (Map GHC.Module SrcPath, Map GHC.ModuleName SrcPath)