Ocaml_parser
The file_type
and file_info
types are used to represent OCaml source files, and the module_info
type represents the metadata of an OCaml module. The collect_ocaml_files
function is used to collect OCaml source files from a directory and its subdirectories.
type parse_result = {
location : string;
module_path : string;
comments : string list;
contents : string;
ocaml_source : ocaml_source;
}
val traverse : traverse_input -> parse_result list
val parse :
Eio.Fs.dir_ty Eio.Path.t ->
string ->
ocaml_source ->
string ->
traverse_input
parse dir file ocaml_source module_name
parses the given file
with the specified ocaml_source
(either Interface
or Implementation
) and module name module_name
. It returns a list of parse_result
records containing the location, module path, comments, contents, and file type for each parsed item.
file_info
is a record type that contains the file_type and file_name.
Now, the file_type is encoded in the type system, and you can create file_info values with specific file types:
let mli_file = mli file_info { file_type = Mli; file_name = "example.mli" }
let ml_file : ml file_info = { file_type = Ml; file_name = "example.ml" }
module_info
is a record type representing the metadata of an OCaml module, combining the interface (mli) and implementation (ml) files.
val parse_module_info :
Eio.Fs.dir_ty Eio.Path.t ->
module_info ->
traverse_input option * traverse_input option
parse_module_info module_info
parses the given module_info
. It returns a list of parse_result
records containing the location, module path, comments, contents, and file type for each parsed item.
collect_ocaml_files dir path
recursively collects OCaml source files from the directory specified by path
and its subdirectories.
val collect_ocaml_files :
Eio.Fs.dir_ty Eio.Path.t ->
string ->
(module_info list, string) result
val format_parse_result : parse_result -> string * string
format_parse_result parse_result
formats the given parse_result
into a string.