{-# LANGUAGE DeriveDataTypeable, TypeFamilies #-}
module Text.Boomerang.Pos
( Pos
, InitialPosition(..)
, ErrorPosition(..)
, MajorMinorPos(..)
, incMajor, incMinor
)
where
import Data.Data (Data, Typeable)
type family Pos err :: *
class ErrorPosition err where
getPosition :: err -> Maybe (Pos err)
class InitialPosition e where
initialPos :: Maybe e -> Pos e
data MajorMinorPos = MajorMinorPos
{ MajorMinorPos -> Integer
major :: Integer
, MajorMinorPos -> Integer
minor :: Integer
}
deriving (MajorMinorPos -> MajorMinorPos -> Bool
(MajorMinorPos -> MajorMinorPos -> Bool)
-> (MajorMinorPos -> MajorMinorPos -> Bool) -> Eq MajorMinorPos
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MajorMinorPos -> MajorMinorPos -> Bool
$c/= :: MajorMinorPos -> MajorMinorPos -> Bool
== :: MajorMinorPos -> MajorMinorPos -> Bool
$c== :: MajorMinorPos -> MajorMinorPos -> Bool
Eq, Eq MajorMinorPos
Eq MajorMinorPos
-> (MajorMinorPos -> MajorMinorPos -> Ordering)
-> (MajorMinorPos -> MajorMinorPos -> Bool)
-> (MajorMinorPos -> MajorMinorPos -> Bool)
-> (MajorMinorPos -> MajorMinorPos -> Bool)
-> (MajorMinorPos -> MajorMinorPos -> Bool)
-> (MajorMinorPos -> MajorMinorPos -> MajorMinorPos)
-> (MajorMinorPos -> MajorMinorPos -> MajorMinorPos)
-> Ord MajorMinorPos
MajorMinorPos -> MajorMinorPos -> Bool
MajorMinorPos -> MajorMinorPos -> Ordering
MajorMinorPos -> MajorMinorPos -> MajorMinorPos
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 :: MajorMinorPos -> MajorMinorPos -> MajorMinorPos
$cmin :: MajorMinorPos -> MajorMinorPos -> MajorMinorPos
max :: MajorMinorPos -> MajorMinorPos -> MajorMinorPos
$cmax :: MajorMinorPos -> MajorMinorPos -> MajorMinorPos
>= :: MajorMinorPos -> MajorMinorPos -> Bool
$c>= :: MajorMinorPos -> MajorMinorPos -> Bool
> :: MajorMinorPos -> MajorMinorPos -> Bool
$c> :: MajorMinorPos -> MajorMinorPos -> Bool
<= :: MajorMinorPos -> MajorMinorPos -> Bool
$c<= :: MajorMinorPos -> MajorMinorPos -> Bool
< :: MajorMinorPos -> MajorMinorPos -> Bool
$c< :: MajorMinorPos -> MajorMinorPos -> Bool
compare :: MajorMinorPos -> MajorMinorPos -> Ordering
$ccompare :: MajorMinorPos -> MajorMinorPos -> Ordering
$cp1Ord :: Eq MajorMinorPos
Ord, Typeable, Typeable MajorMinorPos
DataType
Constr
Typeable MajorMinorPos
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MajorMinorPos -> c MajorMinorPos)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MajorMinorPos)
-> (MajorMinorPos -> Constr)
-> (MajorMinorPos -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MajorMinorPos))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MajorMinorPos))
-> ((forall b. Data b => b -> b) -> MajorMinorPos -> MajorMinorPos)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r)
-> (forall u. (forall d. Data d => d -> u) -> MajorMinorPos -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> MajorMinorPos -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos)
-> Data MajorMinorPos
MajorMinorPos -> DataType
MajorMinorPos -> Constr
(forall b. Data b => b -> b) -> MajorMinorPos -> MajorMinorPos
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MajorMinorPos -> c MajorMinorPos
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MajorMinorPos
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) -> MajorMinorPos -> u
forall u. (forall d. Data d => d -> u) -> MajorMinorPos -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MajorMinorPos
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MajorMinorPos -> c MajorMinorPos
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MajorMinorPos)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MajorMinorPos)
$cMajorMinorPos :: Constr
$tMajorMinorPos :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
gmapMp :: (forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
gmapM :: (forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MajorMinorPos -> m MajorMinorPos
gmapQi :: Int -> (forall d. Data d => d -> u) -> MajorMinorPos -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MajorMinorPos -> u
gmapQ :: (forall d. Data d => d -> u) -> MajorMinorPos -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> MajorMinorPos -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MajorMinorPos -> r
gmapT :: (forall b. Data b => b -> b) -> MajorMinorPos -> MajorMinorPos
$cgmapT :: (forall b. Data b => b -> b) -> MajorMinorPos -> MajorMinorPos
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MajorMinorPos)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MajorMinorPos)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c MajorMinorPos)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MajorMinorPos)
dataTypeOf :: MajorMinorPos -> DataType
$cdataTypeOf :: MajorMinorPos -> DataType
toConstr :: MajorMinorPos -> Constr
$ctoConstr :: MajorMinorPos -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MajorMinorPos
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MajorMinorPos
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MajorMinorPos -> c MajorMinorPos
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MajorMinorPos -> c MajorMinorPos
$cp1Data :: Typeable MajorMinorPos
Data)
incMajor :: (Integral i) => i -> MajorMinorPos -> MajorMinorPos
incMajor :: i -> MajorMinorPos -> MajorMinorPos
incMajor i
i (MajorMinorPos Integer
maj Integer
min) = Integer -> Integer -> MajorMinorPos
MajorMinorPos (Integer
maj Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ (i -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral i
i)) Integer
0
incMinor :: (Integral i) => i -> MajorMinorPos -> MajorMinorPos
incMinor :: i -> MajorMinorPos -> MajorMinorPos
incMinor i
i (MajorMinorPos Integer
maj Integer
min) = Integer -> Integer -> MajorMinorPos
MajorMinorPos Integer
maj (Integer
min Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ (i -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral i
i))
instance Show MajorMinorPos where
show :: MajorMinorPos -> String
show (MajorMinorPos Integer
s Integer
c) = String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
c String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"