@@ -33,18 +33,34 @@ let empty_body = []
3333
3434let empty : Odoc_model.Comment.docs = empty_body
3535
36- let load_payload = function
37- | Parsetree. PStr [{pstr_desc =
38- Pstr_eval ({pexp_desc =
36+ let load_constant_string = function
37+ | {Parsetree. pexp_desc =
3938#if OCAML_VERSION < (4 ,3 ,0 )
40- Pexp_constant (Const_string (text, _))
39+ Pexp_constant (Const_string (text, _))
4140#elif OCAML_VERSION < (4 ,11 ,0 )
42- Pexp_constant (Pconst_string (text, _))
41+ Pexp_constant (Pconst_string (text, _))
4342#else
44- Pexp_constant (Pconst_string (text, _, _))
43+ Pexp_constant (Pconst_string (text, _, _))
4544#endif
46- ; pexp_loc = loc; _}, _); _}] ->
47- Some (text, loc)
45+ ; pexp_loc = loc; _} ->
46+ Some (text , loc)
47+ | _ -> None
48+
49+ let load_payload = function
50+ | Parsetree. PStr [ { pstr_desc = Pstr_eval (constant_string, _); _ } ] ->
51+ load_constant_string constant_string
52+ | _ -> None
53+
54+ let load_alert_name name = (Longident. last name.Location. txt)
55+
56+ let load_alert_name_and_payload = function
57+ | Parsetree. PStr
58+ [ { pstr_desc = Pstr_eval ({ pexp_desc = expression; _ }, _); _ } ] -> (
59+ match expression with
60+ | Pexp_apply ({ pexp_desc = Pexp_ident name ; _ } , [ (_ , payload ) ]) ->
61+ Some (load_alert_name name, load_constant_string payload)
62+ | Pexp_ident name -> Some (load_alert_name name, None )
63+ | _ -> None )
4864 | _ -> None
4965
5066#if OCAML_VERSION > = (4 ,8 ,0 )
@@ -62,8 +78,8 @@ type parsed_attribute =
6278 [ `Text of payload (* * Standalone comment. *)
6379 | `Doc of payload (* * Attached comment. *)
6480 | `Stop of Location .t (* * [(* */**) ]. *)
65- | `Deprecated of payload option * Location .t
66- (* * [\[@@deprecated \]] attribute . *) ]
81+ | `Alert of string * payload option * Location .t
82+ (* * [`Alert (name, payload, loc)] is for [ \[@@alert name "payload" \]] attributes . *) ]
6783
6884(* * Recognize an attribute. *)
6985let parse_attribute : Parsetree.attribute -> parsed_attribute option =
@@ -80,7 +96,12 @@ let parse_attribute : Parsetree.attribute -> parsed_attribute option =
8096 | Some p -> Some (`Doc p)
8197 | None -> None )
8298 | "deprecated" | "ocaml.deprecated" ->
83- Some (`Deprecated ((load_payload attr_payload), attr_loc))
99+ Some (`Alert (" deprecated" , (load_payload attr_payload), attr_loc))
100+ | "alert" | "ocaml.alert" ->
101+ (match load_alert_name_and_payload attr_payload with
102+ Some (name , payload ) ->
103+ Some (`Alert (name, payload, attr_loc))
104+ | None -> None )
84105 | _ -> None
85106
86107let is_stop_comment attr =
@@ -110,8 +131,8 @@ let attached internal_tags parent attrs =
110131 |> Error. raise_parser_warnings
111132 in
112133 loop (List. rev_append ast_docs acc_docs) acc_alerts rest
113- | Some (`Deprecated ( p , loc )) ->
114- let elt = mk_alert_payload ~loc " deprecated " p in
134+ | Some (`Alert ( name , p , loc )) ->
135+ let elt = mk_alert_payload ~loc name p in
115136 loop acc_docs (elt :: acc_alerts) rest
116137 | Some (`Text _ | `Stop _ ) | None -> loop acc_docs acc_alerts rest)
117138 | [] -> (List. rev acc_docs, List. rev acc_alerts)
@@ -150,9 +171,9 @@ let standalone parent (attr : Parsetree.attribute) :
150171 let doc, () = read_string_comment Semantics. Expect_none parent loc str in
151172 Some (`Docs doc)
152173 | Some (`Doc _ ) -> None
153- | Some (`Deprecated ( _ , attr_loc )) ->
174+ | Some (`Alert ( name , _ , attr_loc )) ->
154175 let w =
155- Error. make " Deprecated attribute not expected here."
176+ Error. make " Alert %s not expected here." name
156177 (read_location attr_loc)
157178 in
158179 Error. raise_warning w;
@@ -186,10 +207,10 @@ let extract_top_comment internal_tags ~classify parent items =
186207 match parse_attribute attr with
187208 | Some (`Text _ as p ) -> p
188209 | Some (`Doc _ ) -> `Skip (* Unexpected, silently ignore *)
189- | Some (`Deprecated ( p , attr_loc )) ->
210+ | Some (`Alert ( name , p , attr_loc )) ->
190211 let p = match p with Some (p , _ ) -> Some p | None -> None in
191212 let attr_loc = read_location attr_loc in
192- `Alert (Location_. at attr_loc (`Tag (`Alert (" deprecated " , p))))
213+ `Alert (Location_. at attr_loc (`Tag (`Alert (name , p))))
193214 | Some (`Stop _ ) | None -> `Skip )
194215 | Some `Open -> `Skip
195216 | None -> `Return
0 commit comments