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
|
module Check.AST.Indent.Data where
import Types
import Curry.SpanInfo
import Curry.Span
import Curry.Position
import Curry.Types
import Curry.Ident
import Text.Pretty
import List (last)
checkData :: Decl a -> Int -> CSM ()
checkData e _ =
case e of
(DataDecl sI _ _ constr@(l:ls) _) -> checkData' sI constr
_ -> return ()
checkData' :: SpanInfo -> [ConstrDecl] -> CSM ()
checkData' sI (l:ls) = case l of
(ConstrDecl _ _ _ _ _) -> checkCData sI (l:ls)
(RecordDecl _ _ _ _ _) -> checkRecord sI (l:ls)
_ -> return ()
checkCData :: SpanInfo -> [ConstrDecl] -> CSM ()
checkCData (SpanInfo (Span (Position ls cs) (Position le ce)) sp@(k:(Span (Position l c) _):ks)) (con:cons) =
unlessM (ls == (getLi (getSpanInfo (last (con:cons)))))
(if (ls == l)
then
(if (not (null (cons)))
then
(if (spanAlign (take (length cons) ks))
then
(if ((null ks) || ((getFirstBar ks) == (cs+2)) || (getFirstBar ks == c))
then
(unlessM (checkAlign getCol (getCol (getSpanInfo con)) cons)
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "data declaration constructors"<+> text "not aligned")
( text "align"
<+> colorizeKey "constructors"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "data declaration" <+> text "body wrong indention")
( text "indent by 2"
<+> colorizeKey "from declaration"
<+> text "or write"
<+> colorizeKey "="
<+> text "in line with data"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "|" <+> text "of data declaration not aligned")
( text "align"
<+> colorizeKey "|"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "data declaration" <+> text "wrong formatting")
( text "if only one constructor, write in one line"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position l c))
(colorizeKey "data declaration" <+> text "wrong formatting")
( text "write"
<+> colorizeKey "data"
<+> text "till"
<+> colorizeKey "="
<+> text "in one line"
)
)
)
)
getFirstBar :: [Span] -> Int
getFirstBar ((Span (Position _ c) _):ks) = c
getFirstBar [] = -1
checkRecord :: SpanInfo -> [ConstrDecl] -> CSM ()
checkRecord (SpanInfo (Span (Position ls cs) (Position le ce)) _)
((RecordDecl (SpanInfo _ symbs@((Span (Position _ c) _):_)) _ _ ident fs):_)
= if (ls == (getLi (getSpanInfo ident)))
then
(if (spanAlign symbs)
then
(if ((c == (cs + 2))||(c == (getCol (getSpanInfo ident)) + 2))
then
(if (spanAlign (gatherSpanFromFieldDecls getNameSpan fs))
then
(if (spanAlign (gatherSpanFromFieldDecls getSigSpan fs))
then
(unlessM (spanAlign (gatherSpanFromFieldDecls getTypeSpan fs))
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "Type" <+> text "of record fields not aligned")
( text "align"
<+> colorizeKey "types"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "::" <+> text "of records fields not aligned")
( text "align"
<+> colorizeKey "::"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "names :" <+> text "of record fields not aligned")
( text "align"
<+> colorizeKey "names"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "record body" <+> text "wrong indentation")
( text "indent by"
<+> colorizeKey "2"
<+> text "from record declaration or name of record"
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "record body" <+> text "not aligned")
( text "align"
<+> colorizeKey "{"
<+> text ","
<+> colorizeKey "}"
<+> text "and"
<+> colorizeKey ","
)
)
)
)
else
(report (Message (Span (Position ls cs) (Position le ce))
(colorizeKey "record declaration" <+> text "wrong formatting")
( text "write"
<+> colorizeKey "data"
<+> text "till name of record in one line"
)
)
)
getSigSpan :: FieldDecl -> Span
getSigSpan (FieldDecl (SpanInfo _ (s:_)) _ _) = s
getNameSpan :: FieldDecl -> Span
getNameSpan (FieldDecl _ ((Ident (SpanInfo s _ ) _ _):_) _) = s
getTypeSpan :: FieldDecl -> Span
getTypeSpan (FieldDecl _ _ (ConstructorType (SpanInfo s _) _)) = s
gatherSpanFromFieldDecls :: (FieldDecl -> Span) -> [FieldDecl] -> [Span]
gatherSpanFromFieldDecls _ [] = []
gatherSpanFromFieldDecls fun (f:fs) = [(fun f)]++(gatherSpanFromFieldDecls fun fs)
|