LocationSource code locations (ranges of positions), used in parsetree.
Warning: this module is unstable and part of compiler-libs.
type t = Warnings.loc = {loc_start : Stdlib.Lexing.position;loc_end : Stdlib.Lexing.position;loc_ghost : bool;}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.
val none : tAn arbitrary value of type t; describes an empty ghost range.
val is_none : t -> boolTrue for Location.none, false any other location
val in_file : string -> tReturn an empty ghost range located in a given file.
val init : Stdlib.Lexing.lexbuf -> string -> unitSet the file name and line number of the lexbuf to be the start of the named file.
val curr : Stdlib.Lexing.lexbuf -> tGet the location of the current token from the lexbuf.
val symbol_rloc : unit -> tval symbol_gloc : unit -> tval rhs_loc : int -> trhs_loc n returns the location of the symbol at position n, starting at 1, in the current parser rule.
val rhs_interval : int -> int -> tval get_pos_info : Stdlib.Lexing.position -> string * int * intfile, line, char
val mknoloc : 'a -> 'a locval input_name : string refval input_lexbuf : Stdlib.Lexing.lexbuf option refval input_phrase_buffer : Stdlib.Buffer.t option refrewrite_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:
path.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
path does not exists, orpath in the mapping were found,Some target, means target exists and either
target = path, ortarget 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
dir is not an existing directory, ordir.Some dirs, means dirs are the directories found. Either
dirs = [dir], ordirs are the mapped existing directories.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 '..'.
In -absname mode, return the absolute path for this filename. Otherwise, returns the filename unchanged.
val print_filename : Stdlib.Format.formatter -> string -> unitval print_loc : Stdlib.Format.formatter -> t -> unitval print_locs : Stdlib.Format.formatter -> t list -> unitval separate_new_message : Stdlib.Format.formatter -> unitmodule Doc : sig ... endval highlight_terminfo :
Stdlib.Lexing.lexbuf ->
Stdlib.Format.formatter ->
t list ->
unittype msg = Format_doc.t locval msg : ?loc:t -> ('a, Format_doc.formatter, unit, msg) format4 -> 'atype report_printer = {pp : report_printer -> Stdlib.Format.formatter -> report -> unit;pp_report_kind : report_printer ->
report ->
Stdlib.Format.formatter ->
report_kind ->
unit;pp_main_loc : report_printer -> report -> Stdlib.Format.formatter -> t -> unit;pp_main_txt : report_printer ->
report ->
Stdlib.Format.formatter ->
Format_doc.t ->
unit;pp_submsgs : report_printer ->
report ->
Stdlib.Format.formatter ->
msg list ->
unit;pp_submsg : report_printer -> report -> Stdlib.Format.formatter -> msg -> unit;pp_submsg_loc : report_printer ->
report ->
Stdlib.Format.formatter ->
t ->
unit;pp_submsg_txt : report_printer ->
report ->
Stdlib.Format.formatter ->
Format_doc.t ->
unit;}A printer for reports, defined using open-recursion. The goal is to make it easy to define new printers by re-using code from existing ones.
val batch_mode_printer : report_printerval terminfo_toplevel_printer : Stdlib.Lexing.lexbuf -> report_printerval best_toplevel_printer : unit -> report_printerDetects the terminal capabilities and selects an adequate printer
reportval print_report : Stdlib.Format.formatter -> report -> unitDisplay an error or warning report.
val report_printer : (unit -> report_printer) refHook for redefining the printer of reports.
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.
val default_report_printer : unit -> report_printerOriginal report printer for use in hooks.
Warnings.t into a reportval report_warning : t -> Warnings.t -> report optionreport_warning loc w produces a report for the given warning w, or None if the warning is not to be printed.
val warning_reporter : (t -> Warnings.t -> report option) refHook for intercepting warnings.
val default_warning_reporter : t -> Warnings.t -> report optionOriginal warning reporter for use in hooks.
val formatter_for_warnings : Stdlib.Format.formatter refval print_warning : t -> Stdlib.Format.formatter -> Warnings.t -> unitPrints a warning. This is simply the composition of report_warning and print_report.
val prerr_warning : t -> Warnings.t -> unitSame as print_warning, but uses !formatter_for_warnings as output formatter.
Alert.t into a reportval report_alert : t -> Warnings.alert -> report optionreport_alert loc w produces a report for the given alert w, or None if the alert is not to be printed.
val alert_reporter : (t -> Warnings.alert -> report option) refHook for intercepting alerts.
val default_alert_reporter : t -> Warnings.alert -> report optionOriginal alert reporter for use in hooks.
val print_alert : t -> Stdlib.Format.formatter -> Warnings.alert -> unitPrints an alert. This is simply the composition of report_alert and print_report.
val prerr_alert : t -> Warnings.alert -> unitSame as print_alert, but uses !formatter_for_warnings as output formatter.
Prints an alert that -I +lib has been automatically added to the load path
deprecated_script_alert command prints an alert that command foo has been deprecated in favour of command ./foo
type error = reportAn error is a report which report_kind must be Report_error.
type delayed_msg = unit -> Format_doc.t optionval error : ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg -> string -> errorval errorf :
?loc:t ->
?sub:msg list ->
?footnote:delayed_msg ->
('a, Format_doc.formatter, unit, error) format4 ->
'aval error_of_printer :
?loc:t ->
?sub:msg list ->
?footnote:delayed_msg ->
(Format_doc.formatter -> 'a -> unit) ->
'a ->
errorval error_of_printer_file : (Format_doc.formatter -> 'a -> unit) -> 'a -> errorval register_error_of_exn : (exn -> error option) -> unitEach 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 ] optionexception Error of errorRaising Error e signals an error e; the exception will be caught and the error will be printed.
Raising Already_displayed_error signals an error which has already been printed. The exception will be caught, but nothing will be printed
val raise_errorf :
?loc:t ->
?sub:msg list ->
?footnote:delayed_msg ->
('a, Format_doc.formatter, unit, 'b) format4 ->
'aval report_exception : Stdlib.Format.formatter -> exn -> unitReraise the exception if it is unknown.