~jojo/Carth

ref: a759c3ab6935ef35702fe263f9c8aac8bc97c202 Carth/src/SrcPos.hs -rw-r--r-- 681 bytes
a759c3abJoJo Separate module SrcPos 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module SrcPos
    ( SourcePos(..)
    , WithPos(..)
    , onPosd
    , getPos
    , unpos
    , dummyPos
    , sourcePosPretty
    )
where

import Text.Megaparsec.Pos

import Misc

data WithPos a = WithPos SourcePos a

instance Show a => Show (WithPos a) where
    showsPrec p (WithPos _ a) = showsPrec p a
instance Eq a => Eq (WithPos a) where (WithPos _ a) == (WithPos _ b) = a == b
instance Pretty a => Pretty (WithPos a) where pretty' d = pretty' d . unpos

onPosd :: (a -> b) -> WithPos a -> b
onPosd f = f . unpos

getPos :: WithPos a -> SourcePos
getPos (WithPos p _) = p

unpos :: WithPos a -> a
unpos (WithPos _ a) = a

dummyPos :: SourcePos
dummyPos = initialPos "DUMMY"