package b0

  1. Overview
  2. Docs

Module names.

Module names

type t = string

The type for unqualified, capitalized, module names.

val v : string -> t

v n is a module name for n, the result is capitalized.

val of_filename : B00_std.Fpath.t -> t

of_filename f is the basename of f, without extension, capitalized. This assumes the basename of f follows the OCaml file naming convention mandated by the toolchain. If you know that may not be the case use of_mangled_filename.

val equal : t -> t -> bool

equal n0 n1 is true iff n0 and n1 are the same module name.

val compare : t -> t -> int

comare n0 n1 is a total order on module names compatiable with equal.

val pp : t B00_std.Fmt.t

pp formats a module name.

module Set = B00_std.String.Set

Module name sets.

module Map = B00_std.String.Map

Module name maps.

Filename mangling

val of_mangled_filename : string -> t

of_mangled_filename s is module name obtained by mangling the filename of s as follows:

  1. Remove any trailing .ml or .mli.
  2. Map any dash - (0x2D) or dot . (0x2E) to an underscore _ (0x5F).
  3. Map any byte not allowed in OCaml compilation unit names to its two digits capital hexadecimal encoding.
  4. If the result does not start with an US-ASCII letter, prefix the unit name with 'M'.
  5. Capitalize the first letter.

The transformation is consistent with of_filename on files that follows the OCaml toolchain convention. However the transformation is not injective. Here are a few examples:

           filename   Module name
 ----------------------------------------
    publish-website   Publish_website
    publish_website   Publish_website
     import-data.ml   Import_data
 import-data.xml.ml   Import_data_xml
 import-data.script   Import_data_script
          mix+match   Mix2Bmatch
        _release.ml   M_release
OCaml

Innovation. Community. Security.