@@ -28,7 +28,7 @@ let empty : Odoc_model.Comment.docs = empty_body
2828
2929
3030
31- let load_payload : Parsetree.payload -> ( string * Location.t) option = function
31+ let load_payload : Parsetree.payload -> string * Location.t = function
3232 | PStr [{pstr_desc =
3333 Pstr_eval ({pexp_desc =
3434#if OCAML_MAJOR = 4 && OCAML_MINOR = 02
@@ -39,9 +39,21 @@ let load_payload : Parsetree.payload -> (string * Location.t) option = function
3939 Pexp_constant (Pconst_string (text, _, _))
4040#endif
4141 ; pexp_loc = loc; _}, _); _}] ->
42- Some (text, loc)
43- | _ ->
44- None
42+ (text, loc)
43+ | _ -> assert false
44+
45+
46+ let parse_attribute : Parsetree.attribute -> (string * Location.t) option = function
47+ #if OCAML_MAJOR = 4 && OCAML_MINOR > = 08
48+ | { attr_name = { Location. txt =
49+ (" text" | "ocaml.text" ); loc = _loc }; attr_payload ; _ } -> begin
50+ #else
51+ | ({Location. txt =
52+ (" text" | "ocaml.text" ); loc = _loc }, attr_payload ) -> begin
53+ #endif
54+ Some (load_payload attr_payload)
55+ end
56+ | _ -> None
4557
4658let attached parent attrs =
4759 let ocaml_deprecated = ref None in
@@ -56,7 +68,7 @@ let attached parent attrs =
5668 (" doc" | "ocaml.doc" ); loc = _loc }, attr_payload ) :: rest -> begin
5769#endif
5870 match load_payload attr_payload with
59- | Some (str , loc ) -> begin
71+ | (str , loc ) -> begin
6072 let start_pos = loc.Location. loc_start in
6173 let start_pos =
6274 {start_pos with pos_cnum = start_pos.pos_cnum + 3 } in
@@ -70,7 +82,6 @@ let attached parent attrs =
7082 in
7183 loop false 0 (acc @ parsed) rest
7284 end
73- | None -> (* TODO *) assert false
7485 end
7586 | _ :: rest -> loop first nb_deprecated acc rest
7687 | [] -> begin
@@ -96,32 +107,15 @@ let read_string parent loc str : Odoc_model.Comment.docs_or_stop =
96107
97108let page = read_string
98109
99- let standalone parent
100- : Parsetree.attribute -> Odoc_model.Comment.docs_or_stop option =
101-
102- function
103- #if OCAML_MAJOR = 4 && OCAML_MINOR > = 08
104- | { attr_name = { Location. txt =
105- (" text" | "ocaml.text" ); loc = _loc }; attr_payload ; _ } -> begin
106- #else
107- | ({Location. txt =
108- (" text" | "ocaml.text" ); loc = _loc }, attr_payload ) -> begin
109- #endif
110- match load_payload attr_payload with
111- | Some ("/*" , _loc ) -> Some `Stop
112- | Some (str , loc ) ->
113- let loc' =
114- { loc with
115- loc_start = { loc.loc_start with pos_cnum = loc.loc_start.pos_cnum + 3 } }
116- in
117- Some (read_string parent loc' str)
118- | None ->
119- (* TODO *)
120- assert false
121- (* let doc : Odoc_model.Comment.t =
122- Error (invalid_attribute_error parent loc) in
123- Some (Documentation doc) *)
124- end
110+ let standalone parent (attr : Parsetree.attribute ): Odoc_model.Comment.docs_or_stop option =
111+ match parse_attribute attr with
112+ | Some ("/*" , _loc ) -> Some `Stop
113+ | Some (str , loc ) ->
114+ let loc' =
115+ { loc with
116+ loc_start = { loc.loc_start with pos_cnum = loc.loc_start.pos_cnum + 3 } }
117+ in
118+ Some (read_string parent loc' str)
125119 | _ -> None
126120
127121let standalone_multiple parent attrs =
0 commit comments