-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathProcessAttributes.ml
50 lines (47 loc) · 1.21 KB
/
ProcessAttributes.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
open SharedTypes
(* TODO should I hang on to location? *)
let rec findDocAttribute attributes =
let open Parsetree in
match attributes with
| [] -> None
| ( {Asttypes.txt = "ocaml.doc" | "ocaml.text" | "ns.doc" | "res.doc"},
PStr
[
{
pstr_desc =
Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (doc, _))}, _);
};
] )
:: _ ->
Some doc
| _ :: rest -> findDocAttribute rest
let rec findDeprecatedAttribute attributes =
let open Parsetree in
match attributes with
| [] -> None
| ( {Asttypes.txt = "deprecated"},
PStr
[
{
pstr_desc =
Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (msg, _))}, _);
};
] )
:: _ ->
Some msg
| ({Asttypes.txt = "deprecated"}, _) :: _ -> Some ""
| _ :: rest -> findDeprecatedAttribute rest
let newDeclared ~item ~extent ~name ~stamp ~modulePath isExported attributes =
{
Declared.name;
stamp;
extentLoc = extent;
isExported;
modulePath;
deprecated = findDeprecatedAttribute attributes;
docstring =
(match findDocAttribute attributes with
| None -> []
| Some d -> [d]);
item;
}