Ocamlformat_ocaml_common.LocationSourceSource code locations (ranges of positions), used in parsetree.
Warning: this module is unstable and part of compiler-libs.
t represents a range of characters in the source code.
loc_ghost=false whenever the AST described by the location can be parsed from the location. In all other cases, loc_ghost must be true. Most locations produced by the parser have loc_ghost=false. When loc_ghost=true, the location is usually a best effort approximation.
This info is used by tools like merlin that want to relate source code with parsetrees or later asts. ocamlprof skips instrumentation of ghost nodes.
Example: in `let f x = x`, we have:
Parser.expression (Lexing.from_string "x = x") would fail to parse. By contrast, in `let f = fun x -> x`, every node has loc_ghost=false.Line directives can modify the filenames and line numbers arbitrarily, which is orthogonal to loc_ghost, which describes the range of characters from loc_start.pos_cnum to loc_end.pos_cnum in the parsed string.
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.
Set the file name and line number of the lexbuf to be the start of the named file.
rhs_loc n returns the location of the symbol at position n, starting at 1, in the current parser rule.
file, line, char
In -absname mode, return the absolute path for this filename. Otherwise, returns the filename unchanged.
val msg :
?loc:t ->
('a, Ocamlformat_parser_shims.Format_doc.formatter, unit, msg) Stdlib.format4 ->
'atype report = {kind : report_kind;main : msg;sub : msg list;footnote : Ocamlformat_parser_shims.Format_doc.t option;}type 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 ->
Ocamlformat_parser_shims.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 ->
Ocamlformat_parser_shims.Format_doc.t ->
unit;}A printer for reports, defined using open-recursion. The goal is to make it easy to define new printers by reusing code from existing ones.
Detects the terminal capabilities and selects an adequate printer
reportDisplay an error or warning report.
Hook 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.
Original report printer for use in hooks.
Warnings.t into a reportreport_warning loc w produces a report for the given warning w, or None if the warning is not to be printed.
Hook for intercepting warnings.
Original warning reporter for use in hooks.
Prints a warning. This is simply the composition of report_warning and print_report.
Same as print_warning, but uses !formatter_for_warnings as output formatter.
Alert.t into a reportreport_alert loc w produces a report for the given alert w, or None if the alert is not to be printed.
Hook for intercepting alerts.
Original alert reporter for use in hooks.
Prints an alert. This is simply the composition of report_alert and print_report.
Same 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
val errorf :
?loc:t ->
?sub:msg list ->
?footnote:delayed_msg ->
('a, Ocamlformat_parser_shims.Format_doc.formatter, unit, error)
Stdlib.format4 ->
'aval error_of_printer :
?loc:t ->
?sub:msg list ->
?footnote:delayed_msg ->
(Ocamlformat_parser_shims.Format_doc.formatter -> 'a -> unit) ->
'a ->
errorval error_of_printer_file :
(Ocamlformat_parser_shims.Format_doc.formatter -> 'a -> unit) ->
'a ->
errorEach 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).
Raising 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, Ocamlformat_parser_shims.Format_doc.formatter, unit, 'b) Stdlib.format4 ->
'aReraise the exception if it is unknown.