jon.recoil.org

Module Component.FmtSource

Formatting functions for components

Pretty-printer for the Component representation. signature renders a Signature.t; what it prints is controlled by a config.

The examples below compile a fragment of .mli source into the Signature.t it denotes with sig_of (a helper from the component_fmt_prelude MDX prelude) and render it with signature. readable is default with short_paths enabled.

  # let example = {|
      module type S = sig type t end
      module M : S
      module F (X : S) : sig end
      include S
      module type Tsub = S with type t := int
    |};;
  val example : string =
    "\n    module type S = sig type t end\n    module M : S\n    module F (X : S) : sig end\n    include S\n    module type Tsub = S with type t := int\n  "

With readable the rendering stays close to source syntax: a module's expansion is shown after =>, and a destructively-removed item is flagged with (removed=...):

  # Format.printf "@[<v>%a@]@." (Component.Fmt.signature readable) (sig_of example);;
  module type S = sig type t end
  module M : S => sig type t end
  module F : (X : S) -> sig end
  include S => sig type t end
  module type Tsub = S with t := int => sig  (removed=type () t = (int)) end
  - : unit = ()

Each config field switches one of these off. short_paths = false is the raw internal view — unique name/NN idents and the r(...)/resolved(...) wrappers used while resolving paths:

  # Format.printf "@[<v>%a@]@."
      (Component.Fmt.signature { readable with short_paths = false })
      (sig_of example);;
  module type S/6 = sig type t/7 end
  module M/4 : r(S/6) => sig type t/8 end
  module F/3 : (X/9 : r(S/6)) -> sig end
  include r(S/6) => sig type t/2 end
  module type Tsub/5 = r(S/6) with resolved(root(S/6).t) := resolved(int)
    => sig  (removed=type () t = (resolved(int))) end
  - : unit = ()

show_expansions = false hides the => sig ... end expansions. Includes are governed separately by show_include_expansions, so the include keeps its expansion while M loses it:

  # Format.printf "@[<v>%a@]@."
      (Component.Fmt.signature { readable with show_expansions = false })
      (sig_of example);;
  module type S = sig type t end
  module M : S
  module F : (X : S) -> sig end
  include S => sig type t end
  module type Tsub = S with t := int
  - : unit = ()

show_removed = false hides items deleted by destructive substitution (here the t removed by Tsub, leaving an empty expansion):

  # Format.printf "@[<v>%a@]@."
      (Component.Fmt.signature { readable with show_removed = false })
      (sig_of example);;
  module type S = sig type t end
  module M : S => sig type t end
  module F : (X : S) -> sig end
  include S => sig type t end
  module type Tsub = S with t := int => sig  end
  - : unit = ()

The remaining two fields need inputs this self-contained example does not produce: show_canonical toggles the (canonical=...) note printed for a module carrying a @canonical tag, and identifier_name_only shortens paths that resolution has lifted to a single cross-unit Odoc_model.Paths.Identifier.t — which only arises across compilation units, not the in-unit signatures sig_of builds.

Sourcetype config = {
  1. short_paths : bool;
    (*

    Render short, source-like names instead of the raw name/NN idents and r(...)/resolved(...) path wrappers.

    *)
  2. show_canonical : bool;
    (*

    Print the (canonical=...) note for a module with a @canonical target.

    *)
  3. show_removed : bool;
    (*

    Print items removed by destructive substitution, flagged (removed=...).

    *)
  4. show_expansions : bool;
    (*

    Print module and module-type expansions after =>.

    *)
  5. show_include_expansions : bool;
    (*

    Print the expansion of included signatures, even when show_expansions is off.

    *)
  6. identifier_name_only : bool;
    (*

    Print Identifiers using only the leaf name (as the HTML renderer does).

    *)
}
Sourceval default : config
Sourceval signature : config -> Format.formatter -> Signature.t -> unit
Sourceval removed_item : config -> Format.formatter -> Signature.removed_item -> unit
Sourceval removed_item_list : config -> Format.formatter -> Signature.removed_item list -> unit
Sourceval class_ : config -> Format.formatter -> Class.t -> unit
Sourceval class_type : config -> Format.formatter -> ClassType.t -> unit
Sourceval include_ : config -> Format.formatter -> Include.t -> unit
Sourceval value : config -> Format.formatter -> Value.t -> unit
Sourceval module_decl : config -> Format.formatter -> Module.decl -> unit
Sourceval include_decl : config -> Format.formatter -> Include.decl -> unit
Sourceval module_ : config -> Format.formatter -> Module.t -> unit
Sourceval module_type : config -> Format.formatter -> ModuleType.t -> unit
Sourceval simple_expansion : config -> bool -> Format.formatter -> ModuleType.simple_expansion -> unit
Sourceval module_type_type_of_desc : config -> Format.formatter -> ModuleType.type_of_desc -> unit
Sourceval u_module_type_expr : config -> Format.formatter -> ModuleType.U.expr -> unit
Sourceval module_type_expr : config -> Format.formatter -> ModuleType.expr -> unit
Sourceval functor_parameter : config -> Format.formatter -> FunctorParameter.t -> unit
Sourceval functor_parameter_parameter : config -> Format.formatter -> FunctorParameter.parameter -> unit
Sourceval type_decl : config -> Format.formatter -> TypeDecl.t -> unit
Sourceval type_equation : ?sep:string -> config -> Format.formatter -> TypeDecl.Equation.t -> unit
Sourceval exception_ : config -> Format.formatter -> Exception.t -> unit
Sourceval extension : config -> Format.formatter -> Extension.t -> unit
Sourceval substitution : config -> Format.formatter -> ModuleType.substitution -> unit
Sourceval substitution_list : config -> Format.formatter -> ModuleType.substitution list -> unit
Sourceval type_expr_list : config -> Format.formatter -> TypeExpr.t list -> unit
Sourceval type_object : config -> Format.formatter -> TypeExpr.Object.t -> unit
Sourceval type_class : config -> Format.formatter -> (Cpath.class_type * TypeExpr.t list) -> unit
Sourceval type_package : config -> Format.formatter -> TypeExpr.Package.t -> unit
Sourceval type_expr_polymorphic_variant : config -> Format.formatter -> TypeExpr.Polymorphic_variant.t -> unit
Sourceval type_expr : config -> Format.formatter -> TypeExpr.t -> unit
Sourceval resolved_module_path : config -> Format.formatter -> Cpath.Resolved.module_ -> unit
Sourceval module_path : config -> Format.formatter -> Cpath.module_ -> unit
Sourceval resolved_module_type_path : config -> Format.formatter -> Cpath.Resolved.module_type -> unit
Sourceval module_type_path : config -> Format.formatter -> Cpath.module_type -> unit
Sourceval resolved_type_path : config -> Format.formatter -> Cpath.Resolved.type_ -> unit
Sourceval resolved_value_path : config -> Format.formatter -> Cpath.Resolved.value -> unit
Sourceval resolved_parent_path : config -> Format.formatter -> Cpath.Resolved.parent -> unit
Sourceval type_path : config -> Format.formatter -> Cpath.type_ -> unit
Sourceval value_path : config -> Format.formatter -> Cpath.value -> unit
Sourceval resolved_class_type_path : config -> Format.formatter -> Cpath.Resolved.class_type -> unit
Sourceval class_type_path : config -> Format.formatter -> Cpath.class_type -> unit
Sourceval model_resolved_path : config -> Format.formatter -> Odoc_model.Paths.Path.Resolved.t -> unit
Sourceval model_identifier : config -> Format.formatter -> Odoc_model.Paths.Identifier.t -> unit
Sourceval model_fragment : config -> Format.formatter -> Odoc_model.Paths.Fragment.t -> unit
Sourceval model_resolved_fragment : config -> Format.formatter -> Odoc_model.Paths.Fragment.Resolved.t -> unit
Sourceval resolved_root_fragment : config -> Format.formatter -> Cfrag.root -> unit
Sourceval resolved_signature_fragment : config -> Format.formatter -> Cfrag.resolved_signature -> unit
Sourceval resolved_module_fragment : config -> Format.formatter -> Cfrag.resolved_module -> unit
Sourceval resolved_type_fragment : config -> Format.formatter -> Cfrag.resolved_type -> unit
Sourceval signature_fragment : config -> Format.formatter -> Cfrag.signature -> unit
Sourceval module_fragment : config -> Format.formatter -> Cfrag.module_ -> unit
Sourceval module_type_fragment : config -> Format.formatter -> Cfrag.module_type -> unit
Sourceval type_fragment : config -> Format.formatter -> Cfrag.type_ -> unit
Sourceval model_resolved_reference : config -> Format.formatter -> Odoc_model.Paths.Reference.Resolved.t -> unit
Sourceval model_reference : config -> Format.formatter -> Odoc_model.Paths.Reference.t -> unit