Source file reason_comment.ml
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
open Location
type category =
| EndOfLine
| SingleLine
| Regular
let string_of_category = function
| Regular -> "Regular"
| EndOfLine -> "End of Line"
| SingleLine -> "SingleLine"
type t = {
location: Location.t;
category: category;
text: string;
}
let category t = t.category
let location t = t.location
let dump ppf t =
Format.fprintf ppf "%d (%d:%d)-%d (%d:%d) -- %s:||%s||"
t.location.loc_start.pos_cnum
t.location.loc_start.pos_lnum
(t.location.loc_start.pos_cnum - t.location.loc_start.pos_bol)
t.location.loc_end.pos_cnum
t.location.loc_end.pos_lnum
(t.location.loc_end.pos_cnum - t.location.loc_end.pos_bol)
(string_of_category t.category)
t.text
let dump_list ppf list =
List.iter (Format.fprintf ppf "%a\n" dump) list
let wrap t =
match t.text with
| "" | "*" -> "/***/"
| txt when Reason_syntax_util.isLineComment txt ->
"//"
^ (String.sub txt 0 (String.length txt - 1))
^ Reason_syntax_util.EOLMarker.string
| txt when txt.[0] = '*' && txt.[1] <> '*' ->
"/**" ^ txt ^ "*/"
| txt -> "/*" ^ txt ^ "*/"
let is_doc t =
String.length t.text > 0 && t.text.[0] == '*'
let make ~location category text =
{ text; category; location }
let {category; text} = match category with
| SingleLine -> Reason_syntax_util.isLineComment text
| EndOfLine | Regular -> false