File: typename.ml

package info (click to toggle)
ocaml-odoc 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,104 kB
  • sloc: ml: 59,291; javascript: 2,572; sh: 566; makefile: 31
file content (40 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Path = Odoc_model.Paths.Path
module Identifier = Odoc_model.Paths.Identifier
module TypeName = Odoc_model.Names.TypeName
module ModuleName = Odoc_model.Names.ModuleName

let rec show_ident_long h (r : Identifier.t_pv Identifier.id) =
  match r.iv with
  | `Type (md, n) -> Format.fprintf h "%a.%s" show_signature md (TypeName.to_string n)
  | _ -> Format.fprintf h "%S" (r |> Identifier.fullname |> String.concat ".")

and show_signature h sig_ =
  match sig_.iv with
  | `Root (_, name) -> Format.fprintf h "%s" (ModuleName.to_string name)
  | `Module (pt, mdl) ->
      Format.fprintf h "%a.%s" show_signature pt (ModuleName.to_string mdl)
  | `Parameter (_, p) -> Format.fprintf h "%s" (ModuleName.to_string p)
  | `Result t -> Format.fprintf h "%a" show_signature t
  | `ModuleType (_, p) ->
      Format.fprintf h "%s" (Odoc_model.Names.ModuleTypeName.to_string p)

let rec show_type_name_verbose h : Path.Type.t -> _ = function
  | `Resolved t ->
      (match Path.Resolved.(identifier (t :> t)) with
       | Some i -> Format.fprintf h "%a" show_ident_long i
       | None ->
           (match t with
            | `CoreType n -> Format.fprintf h "%s" (Odoc_model.Names.TypeName.to_string n)
            | _ -> Format.fprintf h "%s" "Core type"))
  | `Identifier (path, _hidden) ->
      let name = String.concat "." @@ Identifier.fullname path in
      Format.fprintf h "%s" name
  | `DotT (mdl, x) ->
      Format.fprintf
        h
        "%s.%s"
        (Odoc_document.Url.render_path (mdl :> Path.t))
        (Odoc_model.Names.TypeName.to_string x)
  | `SubstitutedT x -> show_type_name_verbose h x

let to_string t = Format.asprintf "%a" show_type_name_verbose t