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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
module Curry.Span (
Span(..),
start, end,
isSpan, isNoSpan, fromPosition, stripStart,
vertDist, isAfter, isBefore, isBeforeList
) where
import Curry.Position
data Span = Span Position Position
| NoSpan
deriving (Eq, Show, Read)
start :: Span -> Position
start NoSpan = NoPos
start (Span st _) = st
end :: Span -> Position
end NoSpan = NoPos
end (Span _ ed) = ed
isSpan :: Span -> Bool
isSpan (Span _ _) = True
isSpan NoSpan = False
isNoSpan :: Span -> Bool
isNoSpan (Span _ _) = False
isNoSpan NoSpan = True
fromPosition :: Position -> Span
fromPosition NoPos = NoSpan
fromPosition p@(Position _ _) = Span p p
stripStart :: Span -> Span
stripStart = fromPosition . end
vertDist :: Span -> Span -> Int
vertDist NoSpan NoSpan = 0
vertDist NoSpan (Span _ _ ) = 0
vertDist (Span _ _ ) NoSpan = 0
vertDist (Span s1 e1) (Span s2 e2) =
case rowDist e1 s2 of
x | x >= 0 -> x
| e1 <= e2 -> 0
| otherwise -> - (rowDist e2 s1)
isAfter :: Span -> Span -> Bool
isAfter NoSpan NoSpan = False
isAfter (Span _ _) NoSpan = False
isAfter NoSpan (Span _ _) = False
isAfter (Span s _) (Span _ e) = s >= e
isBefore :: Span -> Span -> Bool
isBefore NoSpan NoSpan = False
isBefore (Span _ _) NoSpan = False
isBefore NoSpan (Span _ _) = False
isBefore (Span _ e) (Span s _) = e <= s
isBeforeList :: Span -> [Span] -> Bool
isBeforeList _ [] = True
isBeforeList sp1 (sp2:_) = isBefore sp1 sp2
|