on 104faf1 help sign in
elk/compiler/Model/Context.hs
43 lines 1.0 kB history raw
2module Context where
4import Text.Parsec.Pos
7data SrcPos = Pos Int Int
8 deriving (Eq,Ord)
10data SrcSpan = Span SrcPos SrcPos | NoSpan
11 deriving (Eq,Ord)
13data Context e = C (Maybe String) SrcSpan e deriving (Eq,Ord)
16instance Show SrcPos where
17 show (Pos r c) = "Line " ++ show r ++ ", Column " ++ show c
19instance Show SrcSpan where
20 show span =
21 case span of
22 Span start end -> show start
23 NoSpan -> ""
25instance Show e => Show (Context e) where
26 show (C _ _ e) = show e
30noContext = C Nothing NoSpan
32pos start end = C Nothing
33 (Span (Pos (sourceLine start) (sourceColumn start))
34 (Pos (sourceLine end ) (sourceColumn end )))
36epos (C _ s1 _) (C _ s2 _) = C Nothing span
37 where span = case (s1,s2) of
38 (Span start _, Span _ end) -> Span start end
39 (_, NoSpan) -> s1
40 (NoSpan, _) -> s2
42addCtx x (C Nothing span e) = C (Just (show x)) span e
43addCtx x (C txt span e) = C txt span e