Skip to content

Commit b98b517

Browse files
committed
IR model: items, allow multiple "kind"s (part of #601).
We simply use the `attr` pattern already present in the IR model. This also slightly tweaks some of the "kinds": * `extension` becomes `type extension` * `type-subst` becomes `type subst` * `external` becomes `value external` * `instance-variable` becomes `value instance-variable` Fixes part of #601.
1 parent cae236a commit b98b517

File tree

5 files changed

+44
-45
lines changed

5 files changed

+44
-45
lines changed

src/document/generator.ml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,10 @@ module Make (Syntax : SYNTAX) = struct
540540
@ O.documentedSrc
541541
(if Syntax.Type.type_def_semicolon then O.txt ";" else O.noop)
542542
in
543-
let kind = Some "extension" in
543+
let attr = [ "type"; "extension" ] in
544544
let anchor = None in
545545
let doc = Comment.to_ir t.doc in
546-
Item.Declaration { kind; anchor; doc; content }
546+
Item.Declaration { attr; anchor; doc; content }
547547

548548
let exn (t : Odoc_model.Lang.Exception.t) =
549549
let cstr = constructor (t.id :> Paths.Identifier.t) t.args t.res in
@@ -553,10 +553,10 @@ module Make (Syntax : SYNTAX) = struct
553553
@ O.documentedSrc
554554
(if Syntax.Type.Exception.semicolon then O.txt ";" else O.noop)
555555
in
556-
let kind = Some "exception" in
556+
let attr = [ "exception" ] in
557557
let anchor = path_to_id t.id in
558558
let doc = Comment.to_ir t.doc in
559-
Item.Declaration { kind; anchor; doc; content }
559+
Item.Declaration { attr; anchor; doc; content }
560560

561561
let polymorphic_variant ~type_ident
562562
(t : Odoc_model.Lang.TypeExpr.Polymorphic_variant.t) =
@@ -748,10 +748,10 @@ module Make (Syntax : SYNTAX) = struct
748748
@ O.documentedSrc
749749
(if Syntax.Type.type_def_semicolon then O.txt ";" else O.noop)
750750
in
751-
let kind = Some (if is_substitution then "type-subst" else "type") in
751+
let attr = "type" :: (if is_substitution then [ "subst" ] else []) in
752752
let anchor = path_to_id t.id in
753753
let doc = Comment.to_ir t.doc in
754-
Item.Declaration { kind; anchor; doc; content }
754+
Item.Declaration { attr; anchor; doc; content }
755755
end
756756

757757
open Type_declaration
@@ -771,10 +771,10 @@ module Make (Syntax : SYNTAX) = struct
771771
++ type_expr t.type_
772772
++ if Syntax.Value.semicolon then O.txt ";" else O.noop )
773773
in
774-
let kind = Some "value" in
774+
let attr = [ "value" ] in
775775
let anchor = path_to_id t.id in
776776
let doc = Comment.to_ir t.doc in
777-
Item.Declaration { kind; anchor; doc; content }
777+
Item.Declaration { attr; anchor; doc; content }
778778

779779
let external_ (t : Odoc_model.Lang.External.t) =
780780
let name = Paths.Identifier.name t.id in
@@ -786,10 +786,10 @@ module Make (Syntax : SYNTAX) = struct
786786
++ type_expr t.type_
787787
++ if Syntax.Type.External.semicolon then O.txt ";" else O.noop )
788788
in
789-
let kind = Some "external" in
789+
let attr = [ "value"; "external" ] in
790790
let anchor = path_to_id t.id in
791791
let doc = Comment.to_ir t.doc in
792-
Item.Declaration { kind; anchor; doc; content }
792+
Item.Declaration { attr; anchor; doc; content }
793793
end
794794

795795
open Value
@@ -887,10 +887,10 @@ module Make (Syntax : SYNTAX) = struct
887887
++ O.txt Syntax.Type.annotation_separator
888888
++ type_expr t.type_ )
889889
in
890-
let kind = Some "method" in
890+
let attr = [ "method" ] in
891891
let anchor = path_to_id t.id in
892892
let doc = Comment.to_ir t.doc in
893-
Item.Declaration { kind; anchor; doc; content }
893+
Item.Declaration { attr; anchor; doc; content }
894894

895895
let instance_variable (t : Odoc_model.Lang.InstanceVariable.t) =
896896
let name = Paths.Identifier.name t.id in
@@ -906,26 +906,26 @@ module Make (Syntax : SYNTAX) = struct
906906
++ O.txt Syntax.Type.annotation_separator
907907
++ type_expr t.type_ )
908908
in
909-
let kind = Some "instance-variable" in
909+
let attr = [ "value"; "instance-variable" ] in
910910
let anchor = path_to_id t.id in
911911
let doc = Comment.to_ir t.doc in
912-
Item.Declaration { kind; anchor; doc; content }
912+
Item.Declaration { attr; anchor; doc; content }
913913

914914
let inherit_ cte =
915915
let content =
916916
O.documentedSrc (O.keyword "inherit" ++ O.txt " " ++ class_type_expr cte)
917917
in
918-
let kind = Some "inherit" in
918+
let attr = [ "inherit" ] in
919919
let anchor = None in
920920
let doc = [] in
921-
Item.Declaration { kind; anchor; doc; content }
921+
Item.Declaration { attr; anchor; doc; content }
922922

923923
let constraint_ t1 t2 =
924924
let content = O.documentedSrc (format_constraints [ (t1, t2) ]) in
925-
let kind = None in
925+
let attr = [] in
926926
let anchor = None in
927927
let doc = [] in
928-
Item.Declaration { kind; anchor; doc; content }
928+
Item.Declaration { attr; anchor; doc; content }
929929

930930
let class_signature (c : Lang.ClassSignature.t) =
931931
let rec loop l acc_items =
@@ -1002,10 +1002,10 @@ module Make (Syntax : SYNTAX) = struct
10021002
(O.keyword "class" ++ O.txt " " ++ virtual_ ++ params ++ O.txt " ")
10031003
@ cname @ cd
10041004
in
1005-
let kind = Some "class" in
1005+
let attr = [ "class" ] in
10061006
let anchor = path_to_id t.id in
10071007
let doc = Comment.first_to_ir t.doc in
1008-
Item.Declaration { kind; anchor; doc; content }
1008+
Item.Declaration { attr; anchor; doc; content }
10091009

10101010
let class_type (t : Odoc_model.Lang.ClassType.t) =
10111011
let name = Paths.Identifier.name t.id in
@@ -1034,10 +1034,10 @@ module Make (Syntax : SYNTAX) = struct
10341034
++ virtual_ ++ params ++ O.txt " " )
10351035
@ cname @ expr
10361036
in
1037-
let kind = Some "class-type" in
1037+
let attr = [ "class-type" ] in
10381038
let anchor = path_to_id t.id in
10391039
let doc = Comment.first_to_ir t.doc in
1040-
Item.Declaration { kind; anchor; doc; content }
1040+
Item.Declaration { attr; anchor; doc; content }
10411041
end
10421042

10431043
open Class
@@ -1166,10 +1166,10 @@ module Make (Syntax : SYNTAX) = struct
11661166
O.documentedSrc
11671167
(O.keyword "module" ++ O.txt " " ++ O.txt name ++ O.txt " := " ++ path)
11681168
in
1169-
let kind = Some "module-substitution" in
1169+
let attr = [ "module-substitution" ] in
11701170
let anchor = path_to_id t.id in
11711171
let doc = Comment.to_ir t.doc in
1172-
Item.Declaration { kind; anchor; doc; content }
1172+
Item.Declaration { attr; anchor; doc; content }
11731173

11741174
and simple_expansion :
11751175
Odoc_model.Lang.ModuleType.simple_expansion ->
@@ -1194,13 +1194,13 @@ module Make (Syntax : SYNTAX) = struct
11941194
let params =
11951195
Utils.flatmap params ~f:(fun arg ->
11961196
let content = functor_parameter arg in
1197-
let kind = Some "parameter" in
1197+
let attr = [ "parameter" ] in
11981198
let anchor =
11991199
Utils.option_of_result
12001200
@@ Url.Anchor.from_identifier (arg.id :> Paths.Identifier.t)
12011201
in
12021202
let doc = [] in
1203-
[ Item.Declaration { content; anchor; kind; doc } ])
1203+
[ Item.Declaration { content; anchor; attr; doc } ])
12041204
in
12051205
let prelude =
12061206
Item.Heading
@@ -1283,10 +1283,10 @@ module Make (Syntax : SYNTAX) = struct
12831283
@ O.documentedSrc
12841284
(if Syntax.Mod.close_tag_semicolon then O.txt ";" else O.noop)
12851285
in
1286-
let kind = Some "module" in
1286+
let attr = [ "module" ] in
12871287
let anchor = path_to_id t.id in
12881288
let doc = Comment.first_to_ir t.doc in
1289-
Item.Declaration { kind; anchor; doc; content }
1289+
Item.Declaration { attr; anchor; doc; content }
12901290

12911291
and simple_expansion_in_decl (base : Paths.Identifier.Module.t) se =
12921292
let rec ty_of_se :
@@ -1344,10 +1344,10 @@ module Make (Syntax : SYNTAX) = struct
13441344
@ O.documentedSrc
13451345
(if Syntax.Mod.close_tag_semicolon then O.txt ";" else O.noop)
13461346
in
1347-
let kind = Some "module-type" in
1347+
let attr = [ "module-type" ] in
13481348
let anchor = path_to_id t.id in
13491349
let doc = Comment.first_to_ir t.doc in
1350-
Item.Declaration { kind; anchor; doc; content }
1350+
Item.Declaration { attr; anchor; doc; content }
13511351

13521352
and umty_hidden : Odoc_model.Lang.ModuleType.U.expr -> bool = function
13531353
| Path p -> Paths.Path.(is_hidden (p :> t))
@@ -1528,10 +1528,10 @@ module Make (Syntax : SYNTAX) = struct
15281528
++ if Syntax.Mod.include_semicolon then O.keyword ";" else O.noop )
15291529
in
15301530
let content = { Include.content; status; summary } in
1531-
let kind = Some "include" in
1531+
let attr = [ "include" ] in
15321532
let anchor = None in
15331533
let doc = Comment.first_to_ir sg_doc in
1534-
Item.Include { kind; anchor; doc; content }
1534+
Item.Include { attr; anchor; doc; content }
15351535
end
15361536

15371537
open Module
@@ -1556,9 +1556,9 @@ module Make (Syntax : SYNTAX) = struct
15561556
Utils.option_of_result
15571557
@@ Url.Anchor.from_identifier (id :> Paths.Identifier.t)
15581558
in
1559-
let kind = Some "modules" in
1559+
let attr = [ "modules" ] in
15601560
let doc = [] in
1561-
let decl = { Item.anchor; content; kind; doc } in
1561+
let decl = { Item.anchor; content; attr; doc } in
15621562
Item.Declaration decl
15631563
in
15641564
List.map f t

src/document/types.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ end =
128128

129129
and Item : sig
130130
type 'a item = {
131-
kind : string option;
131+
attr : Class.t;
132132
anchor : Url.Anchor.t option;
133133
content : 'a;
134134
doc : Block.t;

src/html/generator.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ let div : ([< Html_types.div_attrib ], [< item ], [> Html_types.div ]) Html.star
204204
=
205205
Html.Unsafe.node "div"
206206

207-
let class_of_kind kind =
208-
match kind with Some spec -> class_ [ "spec"; spec ] | None -> []
207+
let spec_class = function [] -> [] | attr -> class_ ("spec" :: attr)
209208

210209
let spec_doc_div ~resolve = function
211210
| [] -> []
@@ -280,7 +279,7 @@ and items ~resolve l : item Html.elt list =
280279
content |> (continue_with [@tailcall]) rest
281280
| Heading h :: rest ->
282281
[ heading ~resolve h ] |> (continue_with [@tailcall]) rest
283-
| Include { kind; anchor; doc; content = { summary; status; content } }
282+
| Include { attr; anchor; doc; content = { summary; status; content } }
284283
:: rest ->
285284
let doc = spec_doc_div ~resolve doc in
286285
let included_html = (items content :> any Html.elt list) in
@@ -289,7 +288,7 @@ and items ~resolve l : item Html.elt list =
289288
let open' = if open' then [ Html.a_open () ] else [] in
290289
let summary =
291290
let anchor_attrib, anchor_link = mk_anchor anchor in
292-
let a = class_of_kind kind @ anchor_attrib in
291+
let a = spec_class attr @ anchor_attrib in
293292
Html.summary ~a @@ anchor_link @ source (inline ~resolve) summary
294293
in
295294
[ Html.details ~a:open' summary included_html ]
@@ -304,9 +303,9 @@ and items ~resolve l : item Html.elt list =
304303
[ Html.div ~a:[ Html.a_class [ "odoc-include" ] ] (doc @ content) ]
305304
in
306305
(continue_with [@tailcall]) rest inc
307-
| Declaration { Item.kind; anchor; content; doc } :: rest ->
306+
| Declaration { Item.attr; anchor; content; doc } :: rest ->
308307
let anchor_attrib, anchor_link = mk_anchor anchor in
309-
let a = class_of_kind kind @ anchor_attrib in
308+
let a = spec_class attr @ anchor_attrib in
310309
let content = anchor_link @ documentedSrc ~resolve content in
311310
let spec =
312311
let doc = spec_doc_div ~resolve doc in

src/latex/generator.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,14 @@ and items l =
397397
elts |> continue_with rest
398398
| Heading h :: rest -> heading h |> continue_with rest
399399
| Include
400-
{ kind = _; anchor; doc; content = { summary; status = _; content } }
400+
{ attr = _; anchor; doc; content = { summary; status = _; content } }
401401
:: rest ->
402402
let included = items content in
403403
let docs = block ~in_source:true doc in
404404
let summary = source (inline ~verbatim:false ~in_source:true) summary in
405405
let content = included in
406406
label anchor @ docs @ summary @ content |> continue_with rest
407-
| Declaration { Item.kind = _; anchor; content; doc } :: rest ->
407+
| Declaration { Item.attr = _; anchor; content; doc } :: rest ->
408408
let content = label anchor @ documentedSrc content in
409409
let elts =
410410
match doc with

src/manpage/generator.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ and item ~nested (l : Item.t list) =
450450
| Heading h ->
451451
let h = heading ~nested h in
452452
vspace ++ h ++ vspace ++ item ~nested rest
453-
| Declaration { kind = _; anchor = _; content; doc } ->
453+
| Declaration { attr = _; anchor = _; content; doc } ->
454454
let decl = documentedSrc content in
455455
let doc =
456456
match doc with
@@ -459,7 +459,7 @@ and item ~nested (l : Item.t list) =
459459
in
460460
decl ++ doc ++ continue rest
461461
| Include
462-
{ kind = _; anchor = _; content = { summary; status; content }; doc }
462+
{ attr = _; anchor = _; content = { summary; status; content }; doc }
463463
->
464464
let d =
465465
if inline_subpage status then item ~nested content

0 commit comments

Comments
 (0)