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
let ~source ~after_only (loc : Location.t) =
let lstart = loc.loc_start.pos_lnum in
let lend = loc.loc_end.pos_lnum in
let starts_its_line (cloc : Location.t) =
match source with
| None -> true
| Some source ->
let start = cloc.loc_start.pos_bol in
let stop = min cloc.loc_start.pos_cnum (String.length source) in
let rec only_blanks_from i =
if i >= stop then true
else
match source.[i] with
| ' ' | '\t' -> only_blanks_from (i + 1)
| _ -> false
in
only_blanks_from start
in
let =
List.filter_map
(fun (, (cloc : Location.t)) ->
let cstart = cloc.loc_start.pos_lnum in
let cend = cloc.loc_end.pos_lnum in
let processed =
cloc.loc_end.pos_cnum - cloc.loc_start.pos_cnum
= String.length comment + 5
in
if
cend < lstart - 1
|| cstart > lend + 1
|| (cstart < lend && after_only)
|| (cstart > lstart && cend < lend )
|| (cstart > lend && not (starts_its_line cloc))
|| String.length comment < 2
|| ((not processed) && (comment.[0] <> '*' || comment.[1] = '*'))
then None
else
let =
if processed then comment
else String.sub comment 1 (String.length comment - 1)
in
let = String.trim comment in
Some comment)
comments
in
match associated_comments with
| [] -> None
| -> Some (String.concat "\n" associated_comments)