module Language.Boogie.Position
(Pos (..)
,SourcePos
,sourceLine
,sourceColumn
,sourceName
,noPos
,attachPos
,gen
,attachPosBefore
,inheritPos
,inheritPos2
) where
import Control.Monad
import Text.ParserCombinators.Parsec
import Text.Parsec.Pos
data Pos a = Pos {
position :: SourcePos,
node :: a
}
instance Eq a => Eq (Pos a) where
(==) p1 p2 = node p1 == node p2
instance Show a => Show (Pos a) where
show p = show (node p)
instance Functor Pos where
fmap f (Pos s a) = Pos s (f a)
attachPos :: SourcePos -> a -> Pos a
attachPos = Pos
noPos = (initialPos "<no file name>")
gen = attachPos noPos
attachPosM :: Monad m => m SourcePos -> m a -> m (Pos a)
attachPosM = liftM2 attachPos
attachPosBefore :: Parser a -> Parser (Pos a)
attachPosBefore = attachPosM getPosition
inheritPos :: (Pos a -> b) -> Pos a -> Pos b
inheritPos f a = attachPos (position a) (f a)
inheritPos2 :: (Pos a -> Pos b -> c) -> Pos a -> Pos b -> Pos c
inheritPos2 f a b = attachPos (position a) (f a b)