{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Language.Haskell.Exts.SrcLoc
-- Copyright   :  (c) Niklas Broberg 2009
-- License     :  BSD-style (see the file LICENSE.txt)
--
-- Maintainer  :  Niklas Broberg, d00nibro@chalmers.se
-- Stability   :  stable
-- Portability :  portable
--
-- This module defines various data types representing source location
-- information, of varying degree of preciseness.
--
-----------------------------------------------------------------------------
module Language.Haskell.Exts.SrcLoc where

import Data.Data
import GHC.Generics (Generic)

showInt :: Int -> String
showInt :: Int -> String
showInt Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = String
"(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")"
showInt Int
i = Int -> String
forall a. Show a => a -> String
show Int
i

-- | A single position in the source.
data SrcLoc = SrcLoc
    { SrcLoc -> String
srcFilename :: String
    , SrcLoc -> Int
srcLine :: Int
    , SrcLoc -> Int
srcColumn :: Int
    }
  deriving (SrcLoc -> SrcLoc -> Bool
(SrcLoc -> SrcLoc -> Bool)
-> (SrcLoc -> SrcLoc -> Bool) -> Eq SrcLoc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SrcLoc -> SrcLoc -> Bool
$c/= :: SrcLoc -> SrcLoc -> Bool
== :: SrcLoc -> SrcLoc -> Bool
$c== :: SrcLoc -> SrcLoc -> Bool
Eq,Eq SrcLoc
Eq SrcLoc
-> (SrcLoc -> SrcLoc -> Ordering)
-> (SrcLoc -> SrcLoc -> Bool)
-> (SrcLoc -> SrcLoc -> Bool)
-> (SrcLoc -> SrcLoc -> Bool)
-> (SrcLoc -> SrcLoc -> Bool)
-> (SrcLoc -> SrcLoc -> SrcLoc)
-> (SrcLoc -> SrcLoc -> SrcLoc)
-> Ord SrcLoc
SrcLoc -> SrcLoc -> Bool
SrcLoc -> SrcLoc -> Ordering
SrcLoc -> SrcLoc -> SrcLoc
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
min :: SrcLoc -> SrcLoc -> SrcLoc
$cmin :: SrcLoc -> SrcLoc -> SrcLoc
max :: SrcLoc -> SrcLoc -> SrcLoc
$cmax :: SrcLoc -> SrcLoc -> SrcLoc
>= :: SrcLoc -> SrcLoc -> Bool
$c>= :: SrcLoc -> SrcLoc -> Bool
> :: SrcLoc -> SrcLoc -> Bool
$c> :: SrcLoc -> SrcLoc -> Bool
<= :: SrcLoc -> SrcLoc -> Bool
$c<= :: SrcLoc -> SrcLoc -> Bool
< :: SrcLoc -> SrcLoc -> Bool
$c< :: SrcLoc -> SrcLoc -> Bool
compare :: SrcLoc -> SrcLoc -> Ordering
$ccompare :: SrcLoc -> SrcLoc -> Ordering
$cp1Ord :: Eq SrcLoc
Ord,Typeable,Typeable SrcLoc
DataType
Constr
Typeable SrcLoc
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> SrcLoc -> c SrcLoc)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SrcLoc)
-> (SrcLoc -> Constr)
-> (SrcLoc -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SrcLoc))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcLoc))
-> ((forall b. Data b => b -> b) -> SrcLoc -> SrcLoc)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r)
-> (forall u. (forall d. Data d => d -> u) -> SrcLoc -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> SrcLoc -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc)
-> Data SrcLoc
SrcLoc -> DataType
SrcLoc -> Constr
(forall b. Data b => b -> b) -> SrcLoc -> SrcLoc
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcLoc -> c SrcLoc
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcLoc
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) -> SrcLoc -> u
forall u. (forall d. Data d => d -> u) -> SrcLoc -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcLoc
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcLoc -> c SrcLoc
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SrcLoc)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcLoc)
$cSrcLoc :: Constr
$tSrcLoc :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
gmapMp :: (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
gmapM :: (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc
gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcLoc -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SrcLoc -> u
gmapQ :: (forall d. Data d => d -> u) -> SrcLoc -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SrcLoc -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r
gmapT :: (forall b. Data b => b -> b) -> SrcLoc -> SrcLoc
$cgmapT :: (forall b. Data b => b -> b) -> SrcLoc -> SrcLoc
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcLoc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcLoc)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c SrcLoc)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SrcLoc)
dataTypeOf :: SrcLoc -> DataType
$cdataTypeOf :: SrcLoc -> DataType
toConstr :: SrcLoc -> Constr
$ctoConstr :: SrcLoc -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcLoc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcLoc
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcLoc -> c SrcLoc
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcLoc -> c SrcLoc
$cp1Data :: Typeable SrcLoc
Data,(forall x. SrcLoc -> Rep SrcLoc x)
-> (forall x. Rep SrcLoc x -> SrcLoc) -> Generic SrcLoc
forall x. Rep SrcLoc x -> SrcLoc
forall x. SrcLoc -> Rep SrcLoc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SrcLoc x -> SrcLoc
$cfrom :: forall x. SrcLoc -> Rep SrcLoc x
Generic)

instance Show SrcLoc where
  showsPrec :: Int -> SrcLoc -> String -> String
showsPrec Int
n (SrcLoc String
fn Int
sl Int
sc) =
    Bool -> (String -> String) -> String -> String
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$
      String -> String -> String
showString (String -> String -> String) -> String -> String -> String
forall a b. (a -> b) -> a -> b
$ String
"SrcLoc " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
fn String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
unwords ((Int -> String) -> [Int] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Int -> String
showInt [Int
sl,Int
sc])

noLoc :: SrcLoc
noLoc :: SrcLoc
noLoc = String -> Int -> Int -> SrcLoc
SrcLoc String
"" (-Int
1) (-Int
1)

-- | A portion of the source, spanning one or more lines and zero or more columns.
data SrcSpan = SrcSpan
    { SrcSpan -> String
srcSpanFilename    :: String
    , SrcSpan -> Int
srcSpanStartLine   :: Int
    , SrcSpan -> Int
srcSpanStartColumn :: Int
    , SrcSpan -> Int
srcSpanEndLine     :: Int
    , SrcSpan -> Int
srcSpanEndColumn   :: Int
    }
  deriving (SrcSpan -> SrcSpan -> Bool
(SrcSpan -> SrcSpan -> Bool)
-> (SrcSpan -> SrcSpan -> Bool) -> Eq SrcSpan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SrcSpan -> SrcSpan -> Bool
$c/= :: SrcSpan -> SrcSpan -> Bool
== :: SrcSpan -> SrcSpan -> Bool
$c== :: SrcSpan -> SrcSpan -> Bool
Eq,Eq SrcSpan
Eq SrcSpan
-> (SrcSpan -> SrcSpan -> Ordering)
-> (SrcSpan -> SrcSpan -> Bool)
-> (SrcSpan -> SrcSpan -> Bool)
-> (SrcSpan -> SrcSpan -> Bool)
-> (SrcSpan -> SrcSpan -> Bool)
-> (SrcSpan -> SrcSpan -> SrcSpan)
-> (SrcSpan -> SrcSpan -> SrcSpan)
-> Ord SrcSpan
SrcSpan -> SrcSpan -> Bool
SrcSpan -> SrcSpan -> Ordering
SrcSpan -> SrcSpan -> SrcSpan
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
min :: SrcSpan -> SrcSpan -> SrcSpan
$cmin :: SrcSpan -> SrcSpan -> SrcSpan
max :: SrcSpan -> SrcSpan -> SrcSpan
$cmax :: SrcSpan -> SrcSpan -> SrcSpan
>= :: SrcSpan -> SrcSpan -> Bool
$c>= :: SrcSpan -> SrcSpan -> Bool
> :: SrcSpan -> SrcSpan -> Bool
$c> :: SrcSpan -> SrcSpan -> Bool
<= :: SrcSpan -> SrcSpan -> Bool
$c<= :: SrcSpan -> SrcSpan -> Bool
< :: SrcSpan -> SrcSpan -> Bool
$c< :: SrcSpan -> SrcSpan -> Bool
compare :: SrcSpan -> SrcSpan -> Ordering
$ccompare :: SrcSpan -> SrcSpan -> Ordering
$cp1Ord :: Eq SrcSpan
Ord,Typeable,Typeable SrcSpan
DataType
Constr
Typeable SrcSpan
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> SrcSpan -> c SrcSpan)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SrcSpan)
-> (SrcSpan -> Constr)
-> (SrcSpan -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SrcSpan))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan))
-> ((forall b. Data b => b -> b) -> SrcSpan -> SrcSpan)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r)
-> (forall u. (forall d. Data d => d -> u) -> SrcSpan -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> SrcSpan -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan)
-> Data SrcSpan
SrcSpan -> DataType
SrcSpan -> Constr
(forall b. Data b => b -> b) -> SrcSpan -> SrcSpan
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpan -> c SrcSpan
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpan
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) -> SrcSpan -> u
forall u. (forall d. Data d => d -> u) -> SrcSpan -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpan -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpan -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpan
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpan -> c SrcSpan
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SrcSpan)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan)
$cSrcSpan :: Constr
$tSrcSpan :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
gmapMp :: (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
gmapM :: (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan
gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcSpan -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SrcSpan -> u
gmapQ :: (forall d. Data d => d -> u) -> SrcSpan -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SrcSpan -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpan -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpan -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpan -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpan -> r
gmapT :: (forall b. Data b => b -> b) -> SrcSpan -> SrcSpan
$cgmapT :: (forall b. Data b => b -> b) -> SrcSpan -> SrcSpan
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c SrcSpan)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SrcSpan)
dataTypeOf :: SrcSpan -> DataType
$cdataTypeOf :: SrcSpan -> DataType
toConstr :: SrcSpan -> Constr
$ctoConstr :: SrcSpan -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpan
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpan
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpan -> c SrcSpan
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpan -> c SrcSpan
$cp1Data :: Typeable SrcSpan
Data,(forall x. SrcSpan -> Rep SrcSpan x)
-> (forall x. Rep SrcSpan x -> SrcSpan) -> Generic SrcSpan
forall x. Rep SrcSpan x -> SrcSpan
forall x. SrcSpan -> Rep SrcSpan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SrcSpan x -> SrcSpan
$cfrom :: forall x. SrcSpan -> Rep SrcSpan x
Generic)

instance Show SrcSpan where
  showsPrec :: Int -> SrcSpan -> String -> String
showsPrec Int
n (SrcSpan String
fn Int
sl Int
sc Int
el Int
ec) =
    Bool -> (String -> String) -> String -> String
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$
      String -> String -> String
showString (String -> String -> String) -> String -> String -> String
forall a b. (a -> b) -> a -> b
$ String
"SrcSpan " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
fn String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
unwords ((Int -> String) -> [Int] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Int -> String
showInt [Int
sl,Int
sc,Int
el,Int
ec])


-- | Returns 'srcSpanStartLine' and 'srcSpanStartColumn' in a pair.
srcSpanStart :: SrcSpan -> (Int,Int)
srcSpanStart :: SrcSpan -> (Int, Int)
srcSpanStart SrcSpan
x = (SrcSpan -> Int
srcSpanStartLine SrcSpan
x, SrcSpan -> Int
srcSpanStartColumn SrcSpan
x)

-- | Returns 'srcSpanEndLine' and 'srcSpanEndColumn' in a pair.
srcSpanEnd :: SrcSpan -> (Int,Int)
srcSpanEnd :: SrcSpan -> (Int, Int)
srcSpanEnd SrcSpan
x = (SrcSpan -> Int
srcSpanEndLine SrcSpan
x, SrcSpan -> Int
srcSpanEndColumn SrcSpan
x)


-- | Combine two locations in the source to denote a span.
mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan
mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan
mkSrcSpan (SrcLoc String
fn Int
sl Int
sc) (SrcLoc String
_ Int
el Int
ec) = String -> Int -> Int -> Int -> Int -> SrcSpan
SrcSpan String
fn Int
sl Int
sc Int
el Int
ec

-- | Merge two source spans into a single span from the start of the first
--   to the end of the second. Assumes that the two spans relate to the
--   same source file.
mergeSrcSpan :: SrcSpan -> SrcSpan -> SrcSpan
mergeSrcSpan :: SrcSpan -> SrcSpan -> SrcSpan
mergeSrcSpan (SrcSpan String
fn Int
sl1 Int
sc1 Int
el1 Int
ec1) (SrcSpan String
_ Int
sl2 Int
sc2 Int
el2 Int
ec2) =
    let (Int
sl,Int
sc) = (Int, Int) -> (Int, Int) -> (Int, Int)
forall a. Ord a => a -> a -> a
min (Int
sl1,Int
sc1) (Int
sl2,Int
sc2)
        (Int
el,Int
ec) = (Int, Int) -> (Int, Int) -> (Int, Int)
forall a. Ord a => a -> a -> a
max (Int
el1,Int
ec1) (Int
el2,Int
ec2)
     in String -> Int -> Int -> Int -> Int -> SrcSpan
SrcSpan String
fn Int
sl Int
sc Int
el Int
ec

-- | Test if a given span starts and ends at the same location.
isNullSpan :: SrcSpan -> Bool
isNullSpan :: SrcSpan -> Bool
isNullSpan SrcSpan
ss = SrcSpan -> (Int, Int)
spanSize SrcSpan
ss (Int, Int) -> (Int, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
0,Int
0)
{- isNullSpan ss = srcSpanStartLine ss == srcSpanEndLine ss &&
                    srcSpanStartColumn ss >= srcSpanEndColumn ss
-}

spanSize :: SrcSpan -> (Int, Int)
spanSize :: SrcSpan -> (Int, Int)
spanSize SrcSpan
ss = (SrcSpan -> Int
srcSpanEndLine SrcSpan
ss Int -> Int -> Int
forall a. Num a => a -> a -> a
- SrcSpan -> Int
srcSpanStartLine SrcSpan
ss, Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (SrcSpan -> Int
srcSpanEndColumn SrcSpan
ss Int -> Int -> Int
forall a. Num a => a -> a -> a
- SrcSpan -> Int
srcSpanStartColumn SrcSpan
ss))

-- | An entity located in the source.
data Loc a = Loc
    { Loc a -> SrcSpan
loc :: SrcSpan
    , Loc a -> a
unLoc :: a
    }
  deriving (Loc a -> Loc a -> Bool
(Loc a -> Loc a -> Bool) -> (Loc a -> Loc a -> Bool) -> Eq (Loc a)
forall a. Eq a => Loc a -> Loc a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Loc a -> Loc a -> Bool
$c/= :: forall a. Eq a => Loc a -> Loc a -> Bool
== :: Loc a -> Loc a -> Bool
$c== :: forall a. Eq a => Loc a -> Loc a -> Bool
Eq,Eq (Loc a)
Eq (Loc a)
-> (Loc a -> Loc a -> Ordering)
-> (Loc a -> Loc a -> Bool)
-> (Loc a -> Loc a -> Bool)
-> (Loc a -> Loc a -> Bool)
-> (Loc a -> Loc a -> Bool)
-> (Loc a -> Loc a -> Loc a)
-> (Loc a -> Loc a -> Loc a)
-> Ord (Loc a)
Loc a -> Loc a -> Bool
Loc a -> Loc a -> Ordering
Loc a -> Loc a -> Loc a
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
forall a. Ord a => Eq (Loc a)
forall a. Ord a => Loc a -> Loc a -> Bool
forall a. Ord a => Loc a -> Loc a -> Ordering
forall a. Ord a => Loc a -> Loc a -> Loc a
min :: Loc a -> Loc a -> Loc a
$cmin :: forall a. Ord a => Loc a -> Loc a -> Loc a
max :: Loc a -> Loc a -> Loc a
$cmax :: forall a. Ord a => Loc a -> Loc a -> Loc a
>= :: Loc a -> Loc a -> Bool
$c>= :: forall a. Ord a => Loc a -> Loc a -> Bool
> :: Loc a -> Loc a -> Bool
$c> :: forall a. Ord a => Loc a -> Loc a -> Bool
<= :: Loc a -> Loc a -> Bool
$c<= :: forall a. Ord a => Loc a -> Loc a -> Bool
< :: Loc a -> Loc a -> Bool
$c< :: forall a. Ord a => Loc a -> Loc a -> Bool
compare :: Loc a -> Loc a -> Ordering
$ccompare :: forall a. Ord a => Loc a -> Loc a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Loc a)
Ord,Int -> Loc a -> String -> String
[Loc a] -> String -> String
Loc a -> String
(Int -> Loc a -> String -> String)
-> (Loc a -> String)
-> ([Loc a] -> String -> String)
-> Show (Loc a)
forall a. Show a => Int -> Loc a -> String -> String
forall a. Show a => [Loc a] -> String -> String
forall a. Show a => Loc a -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [Loc a] -> String -> String
$cshowList :: forall a. Show a => [Loc a] -> String -> String
show :: Loc a -> String
$cshow :: forall a. Show a => Loc a -> String
showsPrec :: Int -> Loc a -> String -> String
$cshowsPrec :: forall a. Show a => Int -> Loc a -> String -> String
Show,(forall x. Loc a -> Rep (Loc a) x)
-> (forall x. Rep (Loc a) x -> Loc a) -> Generic (Loc a)
forall x. Rep (Loc a) x -> Loc a
forall x. Loc a -> Rep (Loc a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Loc a) x -> Loc a
forall a x. Loc a -> Rep (Loc a) x
$cto :: forall a x. Rep (Loc a) x -> Loc a
$cfrom :: forall a x. Loc a -> Rep (Loc a) x
Generic)


-- | A portion of the source, extended with information on the position of entities within the span.
data SrcSpanInfo = SrcSpanInfo
    { SrcSpanInfo -> SrcSpan
srcInfoSpan    :: SrcSpan
--    , explLayout     :: Bool
    , SrcSpanInfo -> [SrcSpan]
srcInfoPoints  :: [SrcSpan]    -- Marks the location of specific entities inside the span
    }
  deriving (SrcSpanInfo -> SrcSpanInfo -> Bool
(SrcSpanInfo -> SrcSpanInfo -> Bool)
-> (SrcSpanInfo -> SrcSpanInfo -> Bool) -> Eq SrcSpanInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SrcSpanInfo -> SrcSpanInfo -> Bool
$c/= :: SrcSpanInfo -> SrcSpanInfo -> Bool
== :: SrcSpanInfo -> SrcSpanInfo -> Bool
$c== :: SrcSpanInfo -> SrcSpanInfo -> Bool
Eq,Eq SrcSpanInfo
Eq SrcSpanInfo
-> (SrcSpanInfo -> SrcSpanInfo -> Ordering)
-> (SrcSpanInfo -> SrcSpanInfo -> Bool)
-> (SrcSpanInfo -> SrcSpanInfo -> Bool)
-> (SrcSpanInfo -> SrcSpanInfo -> Bool)
-> (SrcSpanInfo -> SrcSpanInfo -> Bool)
-> (SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo)
-> (SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo)
-> Ord SrcSpanInfo
SrcSpanInfo -> SrcSpanInfo -> Bool
SrcSpanInfo -> SrcSpanInfo -> Ordering
SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
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
min :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
$cmin :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
max :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
$cmax :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
>= :: SrcSpanInfo -> SrcSpanInfo -> Bool
$c>= :: SrcSpanInfo -> SrcSpanInfo -> Bool
> :: SrcSpanInfo -> SrcSpanInfo -> Bool
$c> :: SrcSpanInfo -> SrcSpanInfo -> Bool
<= :: SrcSpanInfo -> SrcSpanInfo -> Bool
$c<= :: SrcSpanInfo -> SrcSpanInfo -> Bool
< :: SrcSpanInfo -> SrcSpanInfo -> Bool
$c< :: SrcSpanInfo -> SrcSpanInfo -> Bool
compare :: SrcSpanInfo -> SrcSpanInfo -> Ordering
$ccompare :: SrcSpanInfo -> SrcSpanInfo -> Ordering
$cp1Ord :: Eq SrcSpanInfo
Ord,Typeable,Typeable SrcSpanInfo
DataType
Constr
Typeable SrcSpanInfo
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> SrcSpanInfo -> c SrcSpanInfo)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SrcSpanInfo)
-> (SrcSpanInfo -> Constr)
-> (SrcSpanInfo -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SrcSpanInfo))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c SrcSpanInfo))
-> ((forall b. Data b => b -> b) -> SrcSpanInfo -> SrcSpanInfo)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r)
-> (forall u. (forall d. Data d => d -> u) -> SrcSpanInfo -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SrcSpanInfo -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo)
-> Data SrcSpanInfo
SrcSpanInfo -> DataType
SrcSpanInfo -> Constr
(forall b. Data b => b -> b) -> SrcSpanInfo -> SrcSpanInfo
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpanInfo -> c SrcSpanInfo
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpanInfo
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) -> SrcSpanInfo -> u
forall u. (forall d. Data d => d -> u) -> SrcSpanInfo -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpanInfo
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpanInfo -> c SrcSpanInfo
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SrcSpanInfo)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SrcSpanInfo)
$cSrcSpanInfo :: Constr
$tSrcSpanInfo :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
gmapMp :: (forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
gmapM :: (forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SrcSpanInfo -> m SrcSpanInfo
gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcSpanInfo -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SrcSpanInfo -> u
gmapQ :: (forall d. Data d => d -> u) -> SrcSpanInfo -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SrcSpanInfo -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SrcSpanInfo -> r
gmapT :: (forall b. Data b => b -> b) -> SrcSpanInfo -> SrcSpanInfo
$cgmapT :: (forall b. Data b => b -> b) -> SrcSpanInfo -> SrcSpanInfo
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SrcSpanInfo)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SrcSpanInfo)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c SrcSpanInfo)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SrcSpanInfo)
dataTypeOf :: SrcSpanInfo -> DataType
$cdataTypeOf :: SrcSpanInfo -> DataType
toConstr :: SrcSpanInfo -> Constr
$ctoConstr :: SrcSpanInfo -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpanInfo
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SrcSpanInfo
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpanInfo -> c SrcSpanInfo
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SrcSpanInfo -> c SrcSpanInfo
$cp1Data :: Typeable SrcSpanInfo
Data,(forall x. SrcSpanInfo -> Rep SrcSpanInfo x)
-> (forall x. Rep SrcSpanInfo x -> SrcSpanInfo)
-> Generic SrcSpanInfo
forall x. Rep SrcSpanInfo x -> SrcSpanInfo
forall x. SrcSpanInfo -> Rep SrcSpanInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SrcSpanInfo x -> SrcSpanInfo
$cfrom :: forall x. SrcSpanInfo -> Rep SrcSpanInfo x
Generic)

-- Identical output to the derived show instance for GHC 7.10 and earlier.
instance Show SrcSpanInfo where
  showsPrec :: Int -> SrcSpanInfo -> String -> String
showsPrec Int
n (SrcSpanInfo SrcSpan
s [SrcSpan]
pts) = Bool -> (String -> String) -> String -> String
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11) ((String -> String) -> String -> String)
-> (String -> String -> String) -> String -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> String
showString (String -> String -> String) -> String -> String -> String
forall a b. (a -> b) -> a -> b
$
    String
"SrcSpanInfo {srcInfoSpan = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SrcSpan -> String
forall a. Show a => a -> String
show SrcSpan
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
", srcInfoPoints = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [SrcSpan] -> String
forall a. Show a => a -> String
show [SrcSpan]
pts String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"}"

-- | Generate a 'SrcSpanInfo' with no positional information for entities.
noInfoSpan :: SrcSpan -> SrcSpanInfo
noInfoSpan :: SrcSpan -> SrcSpanInfo
noInfoSpan SrcSpan
ss = SrcSpan -> [SrcSpan] -> SrcSpanInfo
SrcSpanInfo SrcSpan
ss []

-- | A bogus `SrcSpanInfo`, the location is @noLoc@.
-- `noSrcSpan = noInfoSpan (mkSrcSpan noLoc noLoc)`
noSrcSpan :: SrcSpanInfo
noSrcSpan :: SrcSpanInfo
noSrcSpan = SrcSpan -> SrcSpanInfo
noInfoSpan (SrcLoc -> SrcLoc -> SrcSpan
mkSrcSpan SrcLoc
noLoc SrcLoc
noLoc)

-- | Generate a 'SrcSpanInfo' with the supplied positional information for entities.
infoSpan :: SrcSpan -> [SrcSpan] -> SrcSpanInfo
infoSpan :: SrcSpan -> [SrcSpan] -> SrcSpanInfo
infoSpan = SrcSpan -> [SrcSpan] -> SrcSpanInfo
SrcSpanInfo

-- | Combine two 'SrcSpanInfo's into one that spans the combined source area of
--   the two arguments, leaving positional information blank.
combSpanInfo :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
combSpanInfo :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
combSpanInfo SrcSpanInfo
s1 SrcSpanInfo
s2 = SrcSpan -> [SrcSpan] -> SrcSpanInfo
SrcSpanInfo
    (SrcSpan -> SrcSpan -> SrcSpan
mergeSrcSpan (SrcSpanInfo -> SrcSpan
srcInfoSpan SrcSpanInfo
s1) (SrcSpanInfo -> SrcSpan
srcInfoSpan SrcSpanInfo
s2))
    []

-- | Like '(<+?>)', but it also concatenates the 'srcInfoPoints'.
combSpanMaybe :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo
combSpanMaybe :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo
combSpanMaybe SrcSpanInfo
s1 Maybe SrcSpanInfo
Nothing = SrcSpanInfo
s1
combSpanMaybe SrcSpanInfo
s1 (Just SrcSpanInfo
s2) = SrcSpan -> [SrcSpan] -> SrcSpanInfo
SrcSpanInfo
    (SrcSpan -> SrcSpan -> SrcSpan
mergeSrcSpan (SrcSpanInfo -> SrcSpan
srcInfoSpan SrcSpanInfo
s1) (SrcSpanInfo -> SrcSpan
srcInfoSpan SrcSpanInfo
s2))
    (SrcSpanInfo -> [SrcSpan]
srcInfoPoints SrcSpanInfo
s1 [SrcSpan] -> [SrcSpan] -> [SrcSpan]
forall a. [a] -> [a] -> [a]
++ SrcSpanInfo -> [SrcSpan]
srcInfoPoints SrcSpanInfo
s2)

-- | Short name for 'combSpanInfo'
(<++>) :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
<++> :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
(<++>) = SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
combSpanInfo

-- | Optionally combine the first argument with the second,
--   or return it unchanged if the second argument is 'Nothing'.
(<+?>) :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo
SrcSpanInfo
a <+?> :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo
<+?> Maybe SrcSpanInfo
b = case Maybe SrcSpanInfo
b of {Maybe SrcSpanInfo
Nothing -> SrcSpanInfo
a; Just SrcSpanInfo
b' -> SrcSpanInfo
a SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
<++> SrcSpanInfo
b'}

-- | Optionally combine the second argument with the first,
--   or return it unchanged if the first argument is 'Nothing'.
(<?+>) :: Maybe SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
Maybe SrcSpanInfo
a <?+> :: Maybe SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
<?+> SrcSpanInfo
b = case Maybe SrcSpanInfo
a of {Maybe SrcSpanInfo
Nothing -> SrcSpanInfo
b; Just SrcSpanInfo
a' -> SrcSpanInfo
a' SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
<++> SrcSpanInfo
b}

-- | Add more positional information for entities of a span.
(<**) :: SrcSpanInfo -> [SrcSpan] -> SrcSpanInfo
ss :: SrcSpanInfo
ss@(SrcSpanInfo {srcInfoPoints :: SrcSpanInfo -> [SrcSpan]
srcInfoPoints = [SrcSpan]
ps}) <** :: SrcSpanInfo -> [SrcSpan] -> SrcSpanInfo
<** [SrcSpan]
xs = SrcSpanInfo
ss {srcInfoPoints :: [SrcSpan]
srcInfoPoints = [SrcSpan]
ps [SrcSpan] -> [SrcSpan] -> [SrcSpan]
forall a. [a] -> [a] -> [a]
++ [SrcSpan]
xs}

-- | Merge two 'SrcSpan's and lift them to a 'SrcInfoSpan' with
--   no positional information for entities.
(<^^>) :: SrcSpan -> SrcSpan -> SrcSpanInfo
SrcSpan
a <^^> :: SrcSpan -> SrcSpan -> SrcSpanInfo
<^^> SrcSpan
b = SrcSpan -> SrcSpanInfo
noInfoSpan (SrcSpan -> SrcSpan -> SrcSpan
mergeSrcSpan SrcSpan
a SrcSpan
b)

infixl 6 <^^>
infixl 5 <++>
infixl 4 <**, <+?>, <?+>

-- | A class to work over all kinds of source location information.
class SrcInfo si where
  toSrcInfo   :: SrcLoc -> [SrcSpan] -> SrcLoc -> si
  fromSrcInfo :: SrcSpanInfo -> si
  getPointLoc :: si -> SrcLoc
  fileName    :: si -> String
  startLine   :: si -> Int
  startColumn :: si -> Int

  getPointLoc si
si = String -> Int -> Int -> SrcLoc
SrcLoc (si -> String
forall si. SrcInfo si => si -> String
fileName si
si) (si -> Int
forall si. SrcInfo si => si -> Int
startLine si
si) (si -> Int
forall si. SrcInfo si => si -> Int
startColumn si
si)

instance SrcInfo SrcLoc where
  toSrcInfo :: SrcLoc -> [SrcSpan] -> SrcLoc -> SrcLoc
toSrcInfo SrcLoc
s [SrcSpan]
_ SrcLoc
_ = SrcLoc
s
  fromSrcInfo :: SrcSpanInfo -> SrcLoc
fromSrcInfo SrcSpanInfo
si = String -> Int -> Int -> SrcLoc
SrcLoc (SrcSpanInfo -> String
forall si. SrcInfo si => si -> String
fileName SrcSpanInfo
si) (SrcSpanInfo -> Int
forall si. SrcInfo si => si -> Int
startLine SrcSpanInfo
si) (SrcSpanInfo -> Int
forall si. SrcInfo si => si -> Int
startColumn SrcSpanInfo
si)
  fileName :: SrcLoc -> String
fileName = SrcLoc -> String
srcFilename
  startLine :: SrcLoc -> Int
startLine = SrcLoc -> Int
srcLine
  startColumn :: SrcLoc -> Int
startColumn = SrcLoc -> Int
srcColumn

instance SrcInfo SrcSpan where
  toSrcInfo :: SrcLoc -> [SrcSpan] -> SrcLoc -> SrcSpan
toSrcInfo SrcLoc
st [SrcSpan]
_ SrcLoc
end = SrcLoc -> SrcLoc -> SrcSpan
mkSrcSpan SrcLoc
st SrcLoc
end
  fromSrcInfo :: SrcSpanInfo -> SrcSpan
fromSrcInfo = SrcSpanInfo -> SrcSpan
srcInfoSpan
  fileName :: SrcSpan -> String
fileName = SrcSpan -> String
srcSpanFilename
  startLine :: SrcSpan -> Int
startLine = SrcSpan -> Int
srcSpanStartLine
  startColumn :: SrcSpan -> Int
startColumn = SrcSpan -> Int
srcSpanStartColumn

instance SrcInfo SrcSpanInfo where
  toSrcInfo :: SrcLoc -> [SrcSpan] -> SrcLoc -> SrcSpanInfo
toSrcInfo SrcLoc
st [SrcSpan]
pts SrcLoc
end = SrcSpan -> [SrcSpan] -> SrcSpanInfo
SrcSpanInfo (SrcLoc -> SrcLoc -> SrcSpan
mkSrcSpan SrcLoc
st SrcLoc
end) [SrcSpan]
pts
  fromSrcInfo :: SrcSpanInfo -> SrcSpanInfo
fromSrcInfo = SrcSpanInfo -> SrcSpanInfo
forall a. a -> a
id
  fileName :: SrcSpanInfo -> String
fileName = SrcSpan -> String
forall si. SrcInfo si => si -> String
fileName (SrcSpan -> String)
-> (SrcSpanInfo -> SrcSpan) -> SrcSpanInfo -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanInfo -> SrcSpan
srcInfoSpan
  startLine :: SrcSpanInfo -> Int
startLine = SrcSpan -> Int
forall si. SrcInfo si => si -> Int
startLine (SrcSpan -> Int) -> (SrcSpanInfo -> SrcSpan) -> SrcSpanInfo -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanInfo -> SrcSpan
srcInfoSpan
  startColumn :: SrcSpanInfo -> Int
startColumn = SrcSpan -> Int
forall si. SrcInfo si => si -> Int
startColumn (SrcSpan -> Int) -> (SrcSpanInfo -> SrcSpan) -> SrcSpanInfo -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanInfo -> SrcSpan
srcInfoSpan