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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
module AST.PositionUtils where
import qualified AST.Ident as I
import AST.Span (Pos, Span, start, virtualPos)
import AST.SpanAST
import AST.Token
line :: Pos -> Int
line pos = fst pos
col :: Pos -> Int
col pos = snd pos
allColEq :: [Pos] -> Bool
allColEq xs = case xs of
[] -> True
_ -> all (== col (head xs)) (map col (tail xs))
allLinesEq :: [Pos] -> Bool
allLinesEq xs = case xs of
[] -> True
_ -> all (== line (head xs)) (map line (tail xs))
moveColBy :: Pos -> Int -> Pos
moveColBy (l,c) n = (l, c + n)
relocate :: Pos -> (Int, Int) -> Pos
relocate (l, c) (ml, mc) = (l + ml, c + mc)
qidPos :: I.QualIdent -> Pos
qidPos (I.QualIdent _ i) = idPos i
idPos :: I.Ident -> Pos
idPos (I.Ident sp _ _) = start sp
sidPos :: I.SymIdent -> Pos
sidPos (I.SymIdent mpl i _) = case mpl of
Just pl -> start pl
Nothing -> idPos i
sqidPos :: I.SymQualIdent -> Pos
sqidPos (I.SymQualIdent mpl qi _) = case mpl of
Just pl -> start pl
Nothing -> qidPos qi
exportPos :: Export -> Pos
exportPos e = case e of
Export qi -> sqidPos qi
ExportTypeWith qi _ _ _ _ -> qidPos qi
ExportTypeAll qi _ _ _ -> qidPos qi
ExportModule _ mi -> start (I.midSpan mi)
declPos :: Decl -> Pos
declPos d = case d of
PatternDecl pat _ -> patPos pat
_ -> virtualPos
declPosEq :: Decl -> Pos
declPosEq d = case d of
PatternDecl _ rhs -> rhsPos rhs
_ -> virtualPos
infPos :: Infix -> Pos
infPos i = case i of
InfixL s -> start s
InfixR s -> start s
Infix s -> start s
constrDeclPos :: ConstrDecl -> Pos
constrDeclPos c = case c of
ConstrDecl s _ _ _ _ i _ -> maybe (idPos i) start s
ConOpDecl s _ _ _ _ te _ _ -> maybe (typeExprPos te) start s
RecordDecl s _ _ _ _ i _ _ _ _ -> maybe (idPos i) start s
constrDeclConstrTypePos :: ConstrDecl -> [Pos]
constrDeclConstrTypePos cd = case cd of
ConstrDecl _ _ _ _ _ _ cts -> if null cts
then [virtualPos]
else map typeExprPos cts
RecordDecl _ _ _ _ _ _ _ fds _ _ -> if null fds
then [virtualPos]
else map fieldDeclTEPos fds
_ -> [virtualPos]
firstCDConstrTypePos :: ConstrDecl -> Pos
firstCDConstrTypePos cd = case cd of
ConstrDecl _ _ _ _ _ _ cts -> if null cts
then virtualPos
else typeExprPos $ head cts
_ -> virtualPos
fieldDeclCPos :: FieldDecl -> [Pos]
fieldDeclCPos (FieldDecl _ sps _ _) = map start sps
fieldDeclDCPos :: FieldDecl -> Pos
fieldDeclDCPos (FieldDecl _ _ sp _) = start sp
fieldDeclIDPos :: FieldDecl -> Pos
fieldDeclIDPos (FieldDecl ids _ _ _) = idPos $ head ids
fieldDeclTEPos :: FieldDecl -> Pos
fieldDeclTEPos (FieldDecl _ _ _ te) = typeExprPos te
typeExprPos :: TypeExpr -> Pos
typeExprPos te = case te of
ConstructorType qi -> qidPos qi
ApplyType te1 _ -> typeExprPos te1
VariableType i -> idPos i
TupleType sp _ _ _ -> start sp
ListType sp _ _ -> start sp
ArrowType te1 _ _ -> typeExprPos te1
ParenType sp _ _ -> start sp
rhsPos :: Rhs -> Pos
rhsPos rhs = case rhs of
SimpleRhs sp _ _ _ -> start sp
GuardedRhs sp _ _ _ _ -> start sp
lhsPos :: Lhs -> Pos
lhsPos lhs = case lhs of
FunLhs si _ -> sidPos si
OpLhs p _ _ -> patPos p
ApLhs l _ -> lhsPos l
condExprPos :: CondExpr -> Pos
condExprPos (CondExpr _ sp _) = start sp
litPos :: Literal -> Pos
litPos l = case l of
Char sp _ -> start sp
Int sp _ -> start sp
Float sp _ -> start sp
String sp _ -> start sp
patPos :: Pattern -> Pos
patPos p = case p of
LiteralPattern l -> litPos l
NegativePattern sp _ -> start sp
VariablePattern i -> idPos i
ConstructorPattern qi _ -> qidPos qi
InfixPattern pat _ _ -> patPos pat
ParenPattern _ pat _ -> patPos pat
RecordPattern qi _ _ _ _ -> qidPos qi
TuplePattern spl _ _ _ -> start spl
ListPattern spl _ _ _ -> start spl
AsPattern i _ _ -> idPos i
LazyPattern sp _ -> start sp
FunctionPattern qi _ -> qidPos qi
InfixFuncPattern pat _ _ -> patPos pat
exprPos :: Expression -> Pos
exprPos e = case e of
Literal l -> litPos l
Variable v -> sqidPos v
Constructor qi -> sqidPos qi
Paren spl _ _ -> start spl
Typed e1 _ _ -> exprPos e1
Record qi _ _ _ _ -> qidPos qi
RecordUpdate e1 _ _ _ _ -> exprPos e1
Tuple spl _ _ _ -> start spl
List spl _ _ _ -> start spl
ListCompr spl _ _ _ _ _ -> start spl
EnumFrom spl _ _ _ -> start spl
EnumFromThen spl _ _ _ _ _ -> start spl
EnumFromTo spl _ _ _ _ -> start spl
EnumFromThenTo spl _ _ _ _ _ _ -> start spl
UnaryMinus sp _ -> start sp
Apply e1 _ -> exprPos e1
InfixApply e1 _ _ -> exprPos e1
LeftSection spl _ _ _ -> start spl
RightSection spl _ _ _ -> start spl
Lambda sp _ _ _ -> start sp
Let sp _ _ _ -> start sp
Do sp _ _ -> start sp
IfThenElse spi _ _ _ _ _ -> start spi
Case _ sp _ _ _ -> start sp
stmtPos :: Statement -> Pos
stmtPos s = case s of
StmtExpr e -> exprPos e
StmtDecl sp _ -> start sp
StmtBind _ pat _ -> patPos pat
altPos :: Alt -> Pos
altPos (Alt _ rhs) = rhsPos rhs
|