1
1
{-# LANGUAGE ImportQualifiedPost #-}
2
+ {-# LANGUAGE LambdaCase #-}
2
3
3
4
{-
4
5
<TEST>
@@ -35,18 +36,23 @@ directives = words $
35
36
36
37
data Comments = Comments
37
38
{ commPragma :: ! [LEpaComment ]
39
+ , commBlockHaddocks :: ! [LEpaComment ]
38
40
, commBlocks :: ! [LEpaComment ]
39
41
-- TODO: Process the different types of block comments; [" |",""].
40
42
-- * Haddock comments
41
43
-- * Simple comments
44
+ , commRunHaddocks :: ! [[LEpaComment ]]
42
45
, commRuns :: ! [[LEpaComment ]]
46
+ , commLineHaddocks :: ! [LEpaComment ]
43
47
, commLines :: ! [LEpaComment ]
44
48
}
45
49
46
50
classifyComments :: [LEpaComment ] -> Comments
47
- classifyComments xs = Comments pragmas blocks runs lines where
48
- (partition isCommentPragma -> (pragmas, blocks), singles) = partition isCommentMultiline xs
49
- (concat -> lines , runs) = partition ((== 1 ) . length ) $ commentRuns singles
51
+ classifyComments xs = Comments pragmas blockHaddocks blocks runHaddocks runs lineHaddocks lines where
52
+ (partition isCommentPragma -> (pragmas, partition isCommentHaddock -> (blockHaddocks, blocks)), singles) = partition isCommentMultiline xs
53
+ (concat -> singles', rawRuns) = partition ((== 1 ) . length ) $ commentRuns singles
54
+ (runHaddocks, runs) = partition (\ case x : _ -> isCommentHaddock x; _ -> False ) rawRuns
55
+ (lineHaddocks, lines ) = partition isCommentHaddock singles'
50
56
51
57
commentRuns :: [LEpaComment ] -> [[LEpaComment ]]
52
58
commentRuns comments =
@@ -114,11 +120,14 @@ commentHint _ m =
114
120
-- c) single-line comments
115
121
-- TODO: Remove (True, _) runs and then run the other checks on the rest.
116
122
traceShow (" pragmas" , commentText <$> pragmas) $
123
+ traceShow (" blockHaddocks" , commentText <$> blockHaddocks) $
117
124
traceShow (" blocks" , commentText <$> blocks) $
118
- traceShow (" runs" , fmap commentText <$> rawRuns) $
125
+ traceShow (" runHaddocks" , fmap commentText <$> runHaddocks) $
126
+ traceShow (" runs" , fmap commentText <$> runs) $
127
+ traceShow (" lineHaddocks" , commentText <$> lineHaddocks) $
119
128
traceShow (" lines" , commentText <$> lines ) $
120
- if any fst runs
121
- then concatMap snd runs
129
+ if any fst runReplacements
130
+ then concatMap snd runReplacements
122
131
else concatMap (check singleLines someLines) comments
123
132
where
124
133
-- Comments need to be sorted by line number for detecting runs of single
@@ -130,9 +139,12 @@ commentHint _ m =
130
139
singleLines = sort $ commentLine <$> filter isSingle comments
131
140
someLines = sort $ commentLine <$> filter isSingleSome comments
132
141
133
- Comments pragmas blocks rawRuns lines = classifyComments comments
142
+ Comments pragmas blockHaddocks blocks runHaddocks runs lineHaddocks lines = classifyComments comments
134
143
135
- runs = dropBlankLinesHint <$> rawRuns
144
+ runReplacements =
145
+ (dropBlankLinesHint <$> runHaddocks)
146
+ ++
147
+ (dropBlankLinesHint <$> runs)
136
148
137
149
-- | Does the commment start with "--"? Can be empty. Excludes haddock single
138
150
-- line comments, "-- |" and "-- ^".
0 commit comments