    {-# LANGUAGE DeriveDataTypeable #-}
    {-# LANGUAGE FlexibleInstances    #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE MultiWayIf           #-}
    {-# LANGUAGE NamedFieldPuns       #-}
    {-# LANGUAGE RankNTypes           #-}
    {-# LANGUAGE StandaloneDeriving   #-}
    {-# LANGUAGE TypeSynonymInstances #-}
    {-# LANGUAGE ViewPatterns         #-}

    module Language.Haskell.GHC.ExactPrint.Types
      where

    import Data.Data hiding (Fixity)
    import GHC hiding (EpaComment)
    import GHC.Utils.Outputable hiding ( (<>) )

    -- ---------------------------------------------------------------------

    type Pos = (Int,Int)

    -- ---------------------------------------------------------------------

    data Rigidity = NormalLayout | RigidLayout deriving (Rigidity -> Rigidity -> Bool
    (Rigidity -> Rigidity -> Bool)
    -> (Rigidity -> Rigidity -> Bool) -> Eq Rigidity
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Rigidity -> Rigidity -> Bool
    == :: Rigidity -> Rigidity -> Bool
    $c/= :: Rigidity -> Rigidity -> Bool
    /= :: Rigidity -> Rigidity -> Bool
    Eq, Eq Rigidity
    Eq Rigidity =>
    (Rigidity -> Rigidity -> Ordering)
    -> (Rigidity -> Rigidity -> Bool)
    -> (Rigidity -> Rigidity -> Bool)
    -> (Rigidity -> Rigidity -> Bool)
    -> (Rigidity -> Rigidity -> Bool)
    -> (Rigidity -> Rigidity -> Rigidity)
    -> (Rigidity -> Rigidity -> Rigidity)
    -> Ord Rigidity
    Rigidity -> Rigidity -> Bool
    Rigidity -> Rigidity -> Ordering
    Rigidity -> Rigidity -> Rigidity
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Rigidity -> Rigidity -> Ordering
    compare :: Rigidity -> Rigidity -> Ordering
    $c< :: Rigidity -> Rigidity -> Bool
    < :: Rigidity -> Rigidity -> Bool
    $c<= :: Rigidity -> Rigidity -> Bool
    <= :: Rigidity -> Rigidity -> Bool
    $c> :: Rigidity -> Rigidity -> Bool
    > :: Rigidity -> Rigidity -> Bool
    $c>= :: Rigidity -> Rigidity -> Bool
    >= :: Rigidity -> Rigidity -> Bool
    $cmax :: Rigidity -> Rigidity -> Rigidity
    max :: Rigidity -> Rigidity -> Rigidity
    $cmin :: Rigidity -> Rigidity -> Rigidity
    min :: Rigidity -> Rigidity -> Rigidity
    Ord, Int -> Rigidity -> ShowS
    [Rigidity] -> ShowS
    Rigidity -> String
    (Int -> Rigidity -> ShowS)
    -> (Rigidity -> String) -> ([Rigidity] -> ShowS) -> Show Rigidity
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Rigidity -> ShowS
    showsPrec :: Int -> Rigidity -> ShowS
    $cshow :: Rigidity -> String
    show :: Rigidity -> String
    $cshowList :: [Rigidity] -> ShowS
    showList :: [Rigidity] -> ShowS
    Show)

    -- ---------------------------------------------------------------------

    -- | A Haskell comment. The @AnnKeywordId@ is present if it has been converted
    -- from an @AnnKeywordId@ because the annotation must be interleaved into the
    -- stream and does not have a well-defined position
    data Comment = Comment
        {
          Comment -> String
    commentContents   :: !String -- ^ The contents of the comment including separators
        , Comment -> Anchor
    commentAnchor :: !Anchor
        , Comment -> RealSrcSpan
    commentPriorTok :: !RealSrcSpan
        , Comment -> Maybe AnnKeywordId
    commentOrigin :: !(Maybe AnnKeywordId) -- ^ We sometimes turn syntax into comments in order to process them properly.
        }
      deriving (Typeable Comment
    Typeable Comment =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> Comment -> c Comment)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c Comment)
    -> (Comment -> Constr)
    -> (Comment -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c Comment))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Comment))
    -> ((forall b. Data b => b -> b) -> Comment -> Comment)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> Comment -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> Comment -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Comment -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Comment -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Comment -> m Comment)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Comment -> m Comment)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Comment -> m Comment)
    -> Data Comment
    Comment -> Constr
    Comment -> DataType
    (forall b. Data b => b -> b) -> Comment -> Comment
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Comment -> u
    forall u. (forall d. Data d => d -> u) -> Comment -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Comment -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Comment -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Comment
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Comment -> c Comment
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Comment)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Comment)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Comment -> c Comment
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Comment -> c Comment
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Comment
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Comment
    $ctoConstr :: Comment -> Constr
    toConstr :: Comment -> Constr
    $cdataTypeOf :: Comment -> DataType
    dataTypeOf :: Comment -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Comment)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Comment)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Comment)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Comment)
    $cgmapT :: (forall b. Data b => b -> b) -> Comment -> Comment
    gmapT :: (forall b. Data b => b -> b) -> Comment -> Comment
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Comment -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Comment -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Comment -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Comment -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> Comment -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Comment -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Comment -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Comment -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Comment -> m Comment
    Data, Comment -> Comment -> Bool
    (Comment -> Comment -> Bool)
    -> (Comment -> Comment -> Bool) -> Eq Comment
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Comment -> Comment -> Bool
    == :: Comment -> Comment -> Bool
    $c/= :: Comment -> Comment -> Bool
    /= :: Comment -> Comment -> Bool
    Eq)

    instance Show Comment where
      show :: Comment -> String
    show (Comment String
    cs Anchor
    ss RealSrcSpan
    r Maybe AnnKeywordId
    o)
        = String
    "(Comment " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ ShowS
    forall a. Show a => a -> String
    show String
    cs String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    " " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Anchor -> String
    forall a. Outputable a => a -> String
    showPprUnsafe Anchor
    ss String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    " " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ RealSrcSpan -> String
    forall a. Show a => a -> String
    show RealSrcSpan
    r String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    " " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Maybe AnnKeywordId -> String
    forall a. Show a => a -> String
    show Maybe AnnKeywordId
    o String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ")"

    instance Ord Comment where
      -- When we have CPP injected comments with a fake filename, or LINE
      -- pragma, the file name changes, so we need to compare the
      -- locations only, with out the filename.
      compare :: Comment -> Comment -> Ordering
    compare (Comment String
    _ Anchor
    ss1 RealSrcSpan
    _ Maybe AnnKeywordId
    _) (Comment String
    _ Anchor
    ss2 RealSrcSpan
    _ Maybe AnnKeywordId
    _) = (Int, Int) -> (Int, Int) -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare (RealSrcSpan -> (Int, Int)
    ss2pos (RealSrcSpan -> (Int, Int)) -> RealSrcSpan -> (Int, Int)
    forall a b. (a -> b) -> a -> b
    $ Anchor -> RealSrcSpan
    anchor Anchor
    ss1) (RealSrcSpan -> (Int, Int)
    ss2pos (RealSrcSpan -> (Int, Int)) -> RealSrcSpan -> (Int, Int)
    forall a b. (a -> b) -> a -> b
    $ Anchor -> RealSrcSpan
    anchor Anchor
    ss2)
        where
          ss2pos :: RealSrcSpan -> (Int, Int)
    ss2pos RealSrcSpan
    ss = (RealSrcSpan -> Int
    srcSpanStartLine RealSrcSpan
    ss,RealSrcSpan -> Int
    srcSpanStartCol RealSrcSpan
    ss)

    instance Outputable Comment where
      ppr :: Comment -> SDoc
    ppr Comment
    x = String -> SDoc
    forall doc. IsLine doc => String -> doc
    text (Comment -> String
    forall a. Show a => a -> String
    show Comment
    x)

    -- | Marks the start column of a layout block.
    newtype LayoutStartCol = LayoutStartCol { LayoutStartCol -> Int
    getLayoutStartCol :: Int }
      deriving (LayoutStartCol -> LayoutStartCol -> Bool
    (LayoutStartCol -> LayoutStartCol -> Bool)
    -> (LayoutStartCol -> LayoutStartCol -> Bool) -> Eq LayoutStartCol
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: LayoutStartCol -> LayoutStartCol -> Bool
    == :: LayoutStartCol -> LayoutStartCol -> Bool
    $c/= :: LayoutStartCol -> LayoutStartCol -> Bool
    /= :: LayoutStartCol -> LayoutStartCol -> Bool
    Eq, Integer -> LayoutStartCol
    LayoutStartCol -> LayoutStartCol
    LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    (LayoutStartCol -> LayoutStartCol -> LayoutStartCol)
    -> (LayoutStartCol -> LayoutStartCol -> LayoutStartCol)
    -> (LayoutStartCol -> LayoutStartCol -> LayoutStartCol)
    -> (LayoutStartCol -> LayoutStartCol)
    -> (LayoutStartCol -> LayoutStartCol)
    -> (LayoutStartCol -> LayoutStartCol)
    -> (Integer -> LayoutStartCol)
    -> Num LayoutStartCol
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    + :: LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    $c- :: LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    - :: LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    $c* :: LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    * :: LayoutStartCol -> LayoutStartCol -> LayoutStartCol
    $cnegate :: LayoutStartCol -> LayoutStartCol
    negate :: LayoutStartCol -> LayoutStartCol
    $cabs :: LayoutStartCol -> LayoutStartCol
    abs :: LayoutStartCol -> LayoutStartCol
    $csignum :: LayoutStartCol -> LayoutStartCol
    signum :: LayoutStartCol -> LayoutStartCol
    $cfromInteger :: Integer -> LayoutStartCol
    fromInteger :: Integer -> LayoutStartCol
    Num)

    instance Show LayoutStartCol where
      show :: LayoutStartCol -> String
    show (LayoutStartCol Int
    sc) = String
    "(LayoutStartCol " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Int -> String
    forall a. Show a => a -> String
    show Int
    sc String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ")"

    -- ---------------------------------------------------------------------

    -- Duplicated here so it can be used in show instances
    showGhc :: (Outputable a) => a -> String
    showGhc :: forall a. Outputable a => a -> String
    showGhc = a -> String
    forall a. Outputable a => a -> String
    showPprUnsafe