package merlin-lib
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=2cea46f12397fa6e31ef0c0d4f5e11c1cfd916ee49420694005c95ebb3aa24bc
sha512=e94abb9ae38149245337db033e2c3891c7ec772168e99abf1bda0216a894c0854e7170b56fe88eba83ec98f2ebc0f5c7c723e8db14f59eeb6dd348bec12c6d62
doc/merlin-lib.ocaml_parsing/Ocaml_parsing/Unit_info/index.html
Module Ocaml_parsing.Unit_info
Source
This module centralize the handling of compilation files and their metadata.
Maybe more importantly, this module provides functions for deriving module names from strings or filenames.
Module name convention and computation
normalize s
uncapitalizes the first letter of s
.
modname_from_source filename
is modulize stem
where stem
is the basename of the filename filename
stripped from all its extensions. For instance, modname_from_source "/pa.th/x.ml.pp"
is "X"
.
Module name validation function
is_unit_name ~strict name
is true only if name
can be used as a valid module name.
Metadata for compilation unit
Metadata for a compilation unit:
- the module name associated to the unit
- the filename prefix (dirname + basename with all extensions stripped) for compilation artifacts
- the input source file For instance, when calling
ocamlopt dir/x.mli -o target/y.cmi
, - the input source file is
dir/x.mli
- the module name is
Y
- the prefix is
target/y
prefix u
is the filename prefix of the unit.
modname u
or artifact_modname a
is the module name of the unit or compilation artifact.
check_unit_name u
prints a warning if the derived module name modname u
should not be used as a module name as specified by is_unit_name
~strict:true
.
make ~check ~source_file prefix
associates both the source_file
and the module name modname_from_source
target_prefix
to the prefix filesystem path prefix
.
If check_modname=true
, this function emits a warning if the derived module name is not valid according to check_unit_name
.
Derived build artifact metadata
Those functions derive a specific artifact
metadata from an unit
metadata.
The functions below change the type of an artifact by updating the extension of its filename. Those functions purposefully do not cover all artifact kinds because we want to track which artifacts are assumed to be bundled together.
Beware that companion_cmi a
strips all extensions from the filename of a
before adding the ".cmi"
suffix contrarily to the other functions which only remove the rightmost extension. In other words, the companion cmi of a file something.d.cmo
is something.cmi
and not something.d.cmi
.
Mli and cmi derived from implementation files
The compilation of module implementation changes in presence of mli and cmi files, the function belows help to handle this.
mli_from_source u
is the interface source filename associated to the unit u
. The actual suffix depends on Config.interface_suffix
.
mli_from_artifact t
is the name of the interface source file derived from the artifact t
. This variant is necessary when handling artifacts derived from an unknown source files (e.g. packed modules).
Check if the artifact is a cmi
find_normalized_cmi u
finds in the load_path a file matching the module name modname u
.