-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPos.hs
More file actions
36 lines (27 loc) · 1018 Bytes
/
Pos.hs
File metadata and controls
36 lines (27 loc) · 1018 Bytes
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
34
35
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module Pos(Pos,
WithPos(..),
spos,
nopos,
posInside) where
import Text.Parsec.Pos
type Pos = (SourcePos,SourcePos)
class WithPos a where
pos :: a -> Pos
atPos :: a -> Pos -> a
instance WithPos Pos where
pos = id
atPos _ p = p
spos :: (WithPos a) => a -> String
spos x = let p = fst $ pos x
in sourceName p ++ ":" ++ (show $ sourceLine p) ++ ":" ++ (show $ sourceColumn p)
nopos::Pos
nopos = (initialPos "",initialPos "")
posInside :: SourcePos -> Pos -> Bool
posInside p (p1, p2) = sourceLine p >= sourceLine p1 && sourceLine p <= sourceLine p2 &&
(if sourceLine p == sourceLine p1
then sourceColumn p >= sourceColumn p1
else True) &&
(if sourceLine p == sourceLine p2
then sourceColumn p <= sourceColumn p2
else True)