Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.15.0
version=0.17.0
4 changes: 2 additions & 2 deletions src/document/codefmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module State = struct
if Stack.is_empty state.context then List.rev state.current
else (
leave state;
flush state )
flush state)
end

(** Modern implementation using semantic tags, Only for 4.08+ *)
Expand Down Expand Up @@ -172,7 +172,7 @@ let rec list ?sep ~f = function
| x :: xs -> (
let hd = f x in
let tl = list ?sep ~f xs in
match sep with None -> hd ++ tl | Some sep -> hd ++ sep ++ tl )
match sep with None -> hd ++ tl | Some sep -> hd ++ sep ++ tl)

let render f = spf "%t" f

Expand Down
4 changes: 2 additions & 2 deletions src/document/comment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module Reference = struct
let s = source_of_code s in
[ inline @@ Inline.Source s ]
| Some s ->
[ inline @@ Inline.InternalLink (InternalLink.Unresolved s) ] )
[ inline @@ Inline.InternalLink (InternalLink.Unresolved s) ])
| `Dot (parent, s) -> unresolved ?text (parent :> t) s
| `Module (parent, s) ->
unresolved ?text (parent :> t) (ModuleName.to_string s)
Expand Down Expand Up @@ -145,7 +145,7 @@ module Reference = struct
| Error exn ->
(* FIXME: better error message *)
Printf.eprintf "Id.href failed: %S\n%!" (Url.Error.to_string exn);
txt )
txt)

and unresolved : ?text:Inline.t -> Reference.t -> string -> Inline.t =
fun ?text parent field ->
Expand Down
4 changes: 2 additions & 2 deletions src/document/doctree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Take = struct
| Rec x -> loop acc (x @ rest)
| Accum v -> loop (List.rev_append v acc) rest
| Stop_and_keep -> (List.rev acc, None, b :: rest)
| Stop_and_accum (v, e) -> (List.rev_append acc v, e, rest) )
| Stop_and_accum (v, e) -> (List.rev_append acc v, e, rest))
in
loop [] items
end
Expand All @@ -37,7 +37,7 @@ module Rewire = struct
if level > current_level then
let children, rest = loop level [] rest in
loop current_level (node h children :: acc) rest
else (List.rev acc, l) )
else (List.rev acc, l))
in
let trees, rest = loop (-1) [] items in
assert (rest = []);
Expand Down
99 changes: 49 additions & 50 deletions src/document/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module Make (Syntax : SYNTAX) = struct
| Error (Url.Error.Not_linkable _) -> O.txt txt
| Error exn ->
Printf.eprintf "Id.href failed: %S\n%!" (Url.Error.to_string exn);
O.txt txt )
O.txt txt)

let dot prefix suffix = prefix ^ "." ^ suffix

Expand Down Expand Up @@ -227,23 +227,23 @@ module Make (Syntax : SYNTAX) = struct
| _ ->
let arguments = style_arguments ~constant arguments in
O.span
( if Syntax.Type.Variant.parenthesize_params then
constr ++ arguments
else constr ++ O.txt " of " ++ arguments )
(if Syntax.Type.Variant.parenthesize_params then
constr ++ arguments
else constr ++ O.txt " of " ++ arguments)
in
if add_pipe then O.txt " " ++ res else res
in
first ++ style_elements ~add_pipe:true rest
in
let elements = style_elements ~add_pipe:false t.elements in
O.span
( match t.kind with
(match t.kind with
| Fixed -> O.txt "[ " ++ elements ++ O.txt " ]"
| Open -> O.txt "[> " ++ elements ++ O.txt " ]"
| Closed [] -> O.txt "[< " ++ elements ++ O.txt " ]"
| Closed lst ->
let constrs = String.concat " " lst in
O.txt "[< " ++ elements ++ O.txt (" " ^ constrs ^ " ]") )
O.txt "[< " ++ elements ++ O.txt (" " ^ constrs ^ " ]"))

and te_object (t : Odoc_model.Lang.TypeExpr.Object.t) =
let fields =
Expand Down Expand Up @@ -327,7 +327,7 @@ module Make (Syntax : SYNTAX) = struct
O.txt (String.concat " " polyvars ^ ". ") ++ type_expr t
| Package pkg ->
enclose ~l:"(" ~r:")"
( O.keyword "module" ++ O.txt " "
(O.keyword "module" ++ O.txt " "
++ Link.from_path (pkg.path :> Paths.Path.t)
++
match pkg.substitutions with
Expand All @@ -336,7 +336,7 @@ module Make (Syntax : SYNTAX) = struct
O.txt " " ++ O.keyword "with" ++ O.txt " "
++ O.list
~sep:(O.txt " " ++ O.keyword "and" ++ O.txt " ")
lst ~f:package_subst )
lst ~f:package_subst)

and package_subst
((frag_typ, te) : Paths.Fragment.Type.t * Odoc_model.Lang.TypeExpr.t) :
Expand Down Expand Up @@ -383,11 +383,11 @@ module Make (Syntax : SYNTAX) = struct
* [O.a ~a:[O.a_href ("#" ^ anchor); O.a_class ["anchor"]] []
* ; *)
O.code
( (if mutable_ then O.keyword "mutable" ++ O.txt " " else O.noop)
((if mutable_ then O.keyword "mutable" ++ O.txt " " else O.noop)
++ O.txt name
++ O.txt Syntax.Type.annotation_separator
++ type_expr typ
++ O.txt Syntax.Type.Record.field_separator )
++ O.txt Syntax.Type.Record.field_separator)
(* ] *)
in
(url, attrs, cell)
Expand Down Expand Up @@ -439,14 +439,14 @@ module Make (Syntax : SYNTAX) = struct
~f:(type_expr ~needs_parentheses:is_gadt)
in
O.documentedSrc
( cstr
++ ( if Syntax.Type.Variant.parenthesize_params then
O.txt "(" ++ params ++ O.txt ")"
(cstr
++ (if Syntax.Type.Variant.parenthesize_params then
O.txt "(" ++ params ++ O.txt ")"
else
( if is_gadt then O.txt Syntax.Type.annotation_separator
else O.txt " " ++ O.keyword "of" ++ O.txt " " )
++ params )
++ ret_type )
(if is_gadt then O.txt Syntax.Type.annotation_separator
else O.txt " " ++ O.keyword "of" ++ O.txt " ")
++ params)
++ ret_type)
| Record fields ->
if is_gadt then
O.documentedSrc (cstr ++ O.txt Syntax.Type.annotation_separator)
Expand Down Expand Up @@ -504,9 +504,9 @@ module Make (Syntax : SYNTAX) = struct
let extension (t : Odoc_model.Lang.Extension.t) =
let content =
O.documentedSrc
( O.keyword "type" ++ O.txt " "
(O.keyword "type" ++ O.txt " "
++ Link.from_path (t.type_path :> Paths.Path.t)
++ O.txt " += " )
++ O.txt " += ")
@ List.map extension_constructor t.constructors
@ O.documentedSrc
(if Syntax.Type.type_def_semicolon then O.txt ";" else O.noop)
Expand Down Expand Up @@ -539,7 +539,7 @@ module Make (Syntax : SYNTAX) = struct
| Constructor { constant; name; arguments; doc; _ } -> (
let cstr = "`" ^ name in
( "constructor",
( match arguments with
(match arguments with
| [] -> O.code (O.txt cstr)
| _ ->
(* Multiple arguments in a polymorphic variant constructor correspond
Expand All @@ -560,12 +560,11 @@ module Make (Syntax : SYNTAX) = struct
if constant then O.txt "& " ++ params else params
in
O.code
( O.txt cstr
(O.txt cstr
++
if Syntax.Type.Variant.parenthesize_params then params
else O.txt " " ++ O.keyword "of" ++ O.txt " " ++ params )
),
match doc with [] -> None | _ -> Some (Comment.to_ir doc) ) )
else O.txt " " ++ O.keyword "of" ++ O.txt " " ++ params)),
match doc with [] -> None | _ -> Some (Comment.to_ir doc) ))
in
try
let url = Url.Anchor.polymorphic_variant ~type_ident item in
Expand Down Expand Up @@ -617,14 +616,14 @@ module Make (Syntax : SYNTAX) = struct
String.concat "" final
in
O.txt
( match params with
(match params with
| [] -> ""
| [ x ] -> format_param x |> Syntax.Type.handle_format_params
| lst -> (
let params = String.concat ", " (List.map format_param lst) in
(match delim with `parens -> "(" | `brackets -> "[")
^ params
^ match delim with `parens -> ")" | `brackets -> "]" ) )
^ match delim with `parens -> ")" | `brackets -> "]"))

let format_constraints constraints =
O.list constraints ~f:(fun (t1, t2) ->
Expand All @@ -644,9 +643,9 @@ module Make (Syntax : SYNTAX) = struct
| Some t ->
let manifest =
O.txt (if is_substitution then " := " else " = ")
++ ( if private_ then
O.keyword Syntax.Type.private_keyword ++ O.txt " "
else O.noop )
++ (if private_ then
O.keyword Syntax.Type.private_keyword ++ O.txt " "
else O.noop)
++ type_expr t
in
(manifest, false)
Expand All @@ -665,11 +664,11 @@ module Make (Syntax : SYNTAX) = struct
in
let manifest =
O.documentedSrc
( O.txt (if is_substitution then " := " else " = ")
(O.txt (if is_substitution then " := " else " = ")
++
if t.equation.private_ then
O.keyword Syntax.Type.private_keyword ++ O.txt " "
else O.noop )
else O.noop)
@ code
in
(manifest, false)
Expand All @@ -690,11 +689,11 @@ module Make (Syntax : SYNTAX) = struct
| Record fields -> record fields
in
O.documentedSrc
( O.txt " = "
(O.txt " = "
++
if need_private then
O.keyword Syntax.Type.private_keyword ++ O.txt " "
else O.noop )
else O.noop)
@ content
in
let tconstr =
Expand Down Expand Up @@ -734,11 +733,11 @@ module Make (Syntax : SYNTAX) = struct
let name = Paths.Identifier.name t.id in
let content =
O.documentedSrc
( O.keyword Syntax.Value.variable_keyword
(O.keyword Syntax.Value.variable_keyword
++ O.txt " " ++ O.txt name
++ O.txt Syntax.Type.annotation_separator
++ type_expr t.type_
++ if Syntax.Value.semicolon then O.txt ";" else O.noop )
++ if Syntax.Value.semicolon then O.txt ";" else O.noop)
in
let kind = Some "value" in
let anchor = path_to_id t.id in
Expand All @@ -749,11 +748,11 @@ module Make (Syntax : SYNTAX) = struct
let name = Paths.Identifier.name t.id in
let content =
O.documentedSrc
( O.keyword Syntax.Value.variable_keyword
(O.keyword Syntax.Value.variable_keyword
++ O.txt " " ++ O.txt name
++ O.txt Syntax.Type.annotation_separator
++ type_expr t.type_
++ if Syntax.Type.External.semicolon then O.txt ";" else O.noop )
++ if Syntax.Type.External.semicolon then O.txt ";" else O.noop)
in
let kind = Some "external" in
let anchor = path_to_id t.id in
Expand Down Expand Up @@ -801,7 +800,7 @@ module Make (Syntax : SYNTAX) = struct
take_until_heading_or_end (element :: input_comment)
in
let item = Item.Text content in
loop input_comment (item :: acc) )
loop input_comment (item :: acc))
in
loop input0 []

Expand Down Expand Up @@ -852,9 +851,9 @@ module Make (Syntax : SYNTAX) = struct
in
let content =
O.documentedSrc
( O.keyword "method" ++ O.txt " " ++ private_ ++ virtual_ ++ O.txt name
(O.keyword "method" ++ O.txt " " ++ private_ ++ virtual_ ++ O.txt name
++ O.txt Syntax.Type.annotation_separator
++ type_expr t.type_ )
++ type_expr t.type_)
in
let kind = Some "method" in
let anchor = path_to_id t.id in
Expand All @@ -871,9 +870,9 @@ module Make (Syntax : SYNTAX) = struct
in
let content =
O.documentedSrc
( O.keyword "val" ++ O.txt " " ++ mutable_ ++ virtual_ ++ O.txt name
(O.keyword "val" ++ O.txt " " ++ mutable_ ++ virtual_ ++ O.txt name
++ O.txt Syntax.Type.annotation_separator
++ type_expr t.type_ )
++ type_expr t.type_)
in
let kind = Some "instance-variable" in
let anchor = path_to_id t.id in
Expand Down Expand Up @@ -917,7 +916,7 @@ module Make (Syntax : SYNTAX) = struct
loop rest acc_items
| Comment (`Docs c) ->
let items = Sectioning.comment_items c in
loop rest (List.rev_append items acc_items) )
loop rest (List.rev_append items acc_items))
in
(* FIXME: use [t.self] *)
loop c.items []
Expand Down Expand Up @@ -991,8 +990,8 @@ module Make (Syntax : SYNTAX) = struct
let expr = attach_expansion (" = ", "object", "end") expansion summary in
let content =
O.documentedSrc
( O.keyword "class" ++ O.txt " " ++ O.keyword "type" ++ O.txt " "
++ virtual_ ++ params ++ O.txt " " )
(O.keyword "class" ++ O.txt " " ++ O.keyword "type" ++ O.txt " "
++ virtual_ ++ params ++ O.txt " ")
@ cname @ expr
in
let kind = Some "class-type" in
Expand Down Expand Up @@ -1067,7 +1066,7 @@ module Make (Syntax : SYNTAX) = struct
loop rest acc_items
| Comment (`Docs c) ->
let items = Sectioning.comment_items c in
loop rest (List.rev_append items acc_items) )
loop rest (List.rev_append items acc_items))
in
loop s []

Expand Down Expand Up @@ -1191,7 +1190,7 @@ module Make (Syntax : SYNTAX) = struct
| Functor (f_parameter, e) -> (
match simple_expansion_of e with
| Some e -> Some (Functor (f_parameter, e))
| None -> None )
| None -> None)
in
match simple_expansion_of t with
| None -> None
Expand Down Expand Up @@ -1441,7 +1440,7 @@ module Make (Syntax : SYNTAX) = struct
++
match td.Lang.TypeDecl.Equation.manifest with
| None -> assert false (* cf loader/cmti *)
| Some te -> type_expr te )
| Some te -> type_expr te)

and include_ (t : Odoc_model.Lang.Include.t) =
let decl_hidden =
Expand Down Expand Up @@ -1472,8 +1471,8 @@ module Make (Syntax : SYNTAX) = struct
let content = signature t.expansion.content in
let summary =
O.render
( O.keyword "include" ++ O.txt " " ++ include_decl
++ if Syntax.Mod.include_semicolon then O.keyword ";" else O.noop )
(O.keyword "include" ++ O.txt " " ++ include_decl
++ if Syntax.Mod.include_semicolon then O.keyword ";" else O.noop)
in
let content = { Include.content; status; summary } in
let kind = Some "include" in
Expand Down
2 changes: 1 addition & 1 deletion src/document/targets.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and signature (t : Odoc_model.Lang.Signature.t) =
| Open _ | ModuleSubstitution _ | TypeSubstitution _ | Type _ | TypExt _
| Exception _ | Value _ | External _ | Class _ | ClassType _
| Comment (`Docs _) ->
add_items ~don't acc is )
add_items ~don't acc is)
in
add_items ~don't:false [] t.items

Expand Down
4 changes: 2 additions & 2 deletions src/document/url.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ module Anchor = struct
| { page; anchor = _; kind } ->
(* Really ad-hoc and shitty, but it works. *)
if kind = "page" then Ok { page; anchor; kind }
else Ok { page; anchor; kind = "" } )
else Ok { page; anchor; kind = "" })

(* | _ ->
Error (Unexpected_anchor ("label " ^ anchor)) *)
Expand All @@ -259,7 +259,7 @@ module Anchor = struct
| Constructor { name; _ } ->
let kind = "constructor" in
let suffix = name in
add_suffix ~kind url suffix )
add_suffix ~kind url suffix)
end

type t = Anchor.t
Expand Down
2 changes: 1 addition & 1 deletion src/document/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let rec flatmap ?sep ~f = function
| x :: xs -> (
let hd = f x in
let tl = flatmap ?sep ~f xs in
match sep with None -> hd @ tl | Some sep -> hd @ sep @ tl )
match sep with None -> hd @ tl | Some sep -> hd @ sep @ tl)

let rec skip_until ~p = function
| [] -> []
Expand Down
Loading