Module Bcfg.Txtloc

Txtloc locates the errors which may occur when manipulating a bcfg file. A location alone is rarely useful to a human, so the module also re-reads the source around it and gives back the lines to display, in the spirit of what a compiler prints. This is what bcfg validate uses.

type t

The location of an error: a line, and a range of columns in that line.

val pp : Format.formatter -> t -> unit

Prints a location as l<line>.<start>-<end>.

type line =
  1. | Errored_line of {
    1. err : string;
    2. around : string * string;
    }
    (*

    The line on which the error occurs, split into what precedes the error, the offending piece of text and what follows it.

    *)
  2. | Context_line of string
    (*

    A line printed only to give some context.

    *)
  3. | Eof of {
    1. errored : bool;
    }
    (*

    The end of the input, errored being true when this is where the error is (an unterminated block, for instance).

    *)
val lines_around_txtloc : ?ctx:int -> txtloc:t -> in_channel -> (int * line) list

If the error is located in txtloc, lines_around_txtloc ~txtloc ic contextualizes the error based on the file content available via ic. Note that the ic used must not be the same as the one used (and already consumed) to analyze the bcfg file.

val lines_around_txtloc_string : ?ctx:int -> txtloc:t -> string -> (int * line) list

Same as lines_around_txtloc but reads the lines from an in-memory string (the whole file content) instead of an in_channel. Useful when the input is not seekable (e.g. standard input).