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
|
module ACSpans.SortSplit (sortSplitModule, lePos) where
import Sort (quickSortBy)
import ACSpans.AST
import ACSpans.Span (Pos)
import ACSpans.PositionUtils (line)
sortSplitModule :: Module -> Module
sortSplitModule (Module mps mi mesp ids ds) =
(Module mps mi mesp ids (quickSortBy lePos (concatMap splitFunctionDecl ds)))
sortSplitEq :: Equation -> Equation
sortSplitEq (Equation p lhs rhs) = (Equation p lhs (sortSplitRhs rhs))
sortSplitRhs :: Rhs -> Rhs
sortSplitRhs rhs = case rhs of
SimpleRhs p e ds -> SimpleRhs p e (qsDs ds)
GuardedRhs ces ds -> GuardedRhs ces (qsDs ds)
where qsDs ds = quickSortBy lePos $ concatMap splitFunctionDecl ds
splitFunctionDecl :: Decl -> [Decl]
splitFunctionDecl d = case d of
(FunctionDecl p i eqs) -> case eqs of
[] -> []
(eq : eqss) -> [(FunctionDecl (posEquation eq) i [sortSplitEq eq])]
++ (splitFunctionDecl (FunctionDecl p i eqss))
_ -> [d]
posEquation :: Equation -> Pos
posEquation (Equation p _ _) = p
lePos :: Decl -> Decl -> Bool
lePos d1 d2 = (line $ declPos d1) <= (line $ declPos d2)
declPos :: Decl -> Pos
declPos (InfixDecl p _ _ _ ) = p
declPos (DataDecl p _ _ _ ) = p
declPos (NewtypeDecl p _ _ _ ) = p
declPos (TypeDecl p _ _ _ ) = p
declPos (TypeSig p _ _ ) = p
declPos (FunctionDecl p _ _ ) = p
declPos (ForeignDecl p _ _ _ _) = p
declPos (ExternalDecl p _ ) = p
declPos (PatternDecl p _ _ ) = p
declPos (FreeDecl p _ ) = p
|