Note on the use of Lexing.position in this module. If pos_fname = "", then use !input_name instead. If pos_lnum = -1, then pos_bol = 0. Use pos_cnum and re-parse the file to get the line and character numbers. Else all fields are correct.
rewrite_absolute_path path rewrites path to honor the BUILD_PATH_PREFIX_MAP variable if it is set. It does not check whether path is absolute or not. The result is as follows:
If BUILD_PATH_PREFIX_MAP is not set, just return path.
otherwise, rewrite using the mapping (and if there are no matching prefixes that will just return path).
rewrite_find_first_existing path uses a BUILD_PATH_PREFIX_MAP mapping and tries to find a source in mapping that maps to a result that exists in the file system. There are the following return values:
None, means either
BUILD_PATH_PREFIX_MAP is not set and path does not exists, or
no source prefixes of path in the mapping were found,
Some target, means target exists and either
BUILD_PATH_PREFIX_MAP is not set and target = path, or
target is the first file (in priority order) that path mapped to that exists in the file system.
Not_found raised, means some source prefixes in the map were found that matched path, but none of them existed in the file system. The caller should catch this and issue an appropriate error message.
rewrite_find_all_existing_dirs dir accumulates a list of existing directories, dirs, that are the result of mapping a potentially abstract directory, dir, over all the mapping pairs in the BUILD_PATH_PREFIX_MAP environment variable, if any. The list dirs will be in priority order (head as highest priority).
The possible results are:
[], means either
BUILD_PATH_PREFIX_MAP is not set and dir is not an existing directory, or
if set, then there were no matching prefixes of dir.
Some dirs, means dirs are the directories found. Either
BUILD_PATH_PREFIX_MAP is not set and dirs = [dir], or
it was set and dirs are the mapped existing directories.
Not_found raised, means some source prefixes in the map were found that matched dir, but none of mapping results were existing directories (possibly due to misconfiguration). The caller should catch this and issue an appropriate error message.
absolute_path path first makes an absolute path, s from path, prepending the current working directory if path was relative. Then s is rewritten using rewrite_absolute_path. Finally the result is normalized by eliminating instances of '.' or '..'.
Printing locations
val show_filename : string -> string
In -absname mode, return the absolute path for this filename. Otherwise, returns the filename unchanged.
The hook is a unit -> report_printer and not simply a report_printer: this is useful so that it can detect the type of the output (a file, a terminal, ...) and select a printer accordingly.
Automatically reporting errors for raised exceptions
val register_error_of_exn : (exn ->error option)-> unit
Each compiler module which defines a custom type of exception which can surface as a user-visible error should register a "printer" for this exception using register_error_of_exn. The result of the printer is an error value containing a location, a message, and optionally sub-messages (each of them being located as well).
val error_of_exn : exn ->[ `Ok of error| `Already_displayed ] option