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
{ major :: Integer
, minor :: Integer
}
deriving (Eq, Ord, Typeable, Data)
incMajor :: (Integral i) => i -> MajorMinorPos -> MajorMinorPos
incMajor i (MajorMinorPos maj min) = MajorMinorPos (maj + (fromIntegral i)) 0
incMinor :: (Integral i) => i -> MajorMinorPos -> MajorMinorPos
incMinor i (MajorMinorPos maj min) = MajorMinorPos maj (min + (fromIntegral i))
instance Show MajorMinorPos where
show (MajorMinorPos s c) = "(" ++ show s ++ ", " ++ show c ++ ")"