package pacomb

  1. Overview
  2. Docs

Functions managing positions

type spos = Input.spos

short position

type pos = {
  1. offset_start : int;
  2. offset_end : int;
  3. infos : Input.infos;
}

Type to represent an interval between two position

val phantom_pos : pos

a phantom position, used for grammar accepting the empty input, and other reference initialisation

val no_pos : pos
val has_pos : pos -> bool

return false on phantom_pos/no_pos

val merge : pos -> pos -> pos

build the smallest position containing both position

type pos_info = {
  1. start_line : int;
  2. start_col : int;
  3. start_line_offset : int;
  4. start_byte : int;
  5. end_line : int;
  6. end_col : int;
  7. end_line_offset : int;
  8. end_byte : int;
  9. file_name : string;
  10. text : string;
}

Fully informed positions

exception No_detailed_position

Function to recover full position from the information stored in located data.

The optional paramater ~relocate, which is identity by default allows to deal with situation like a moved file since position was produced, or a file name stored with a relative position. The file_name in the pos_info is not affected by relocate which is only used to reopen the file.

The optionnal parameter ~text (false by default) will fill the text field within the position if it is true. Otherwise the text field is set to the empty string.

This function may raise No_detailled_position is the file can not be reopen or File_changed if the file is present but changed its last modification time of size.

exception File_changed
val pos_info : ?relocate:(string -> string) -> ?text:bool -> pos -> pos_info
type quote = {
  1. numbers : bool;
    (*

    includes line number

    *)
  2. prefix : string;
    (*

    prefix added after each newline but not added for the first printed line

    *)
  3. header : string;
    (*

    header, added as first line if non empty

    *)
  4. footer : string;
    (*

    footer, added as last line if non empty

    *)
  5. enlight : string -> string;
    (*

    used to transform the quoted part of the printed lines

    *)
}

configuration for quoting file

val default_quote : quote

default quote:

let ulined : string -> string =
  fun s -> "\027[0m\027[4m" ^ s ^ "\027[0m"

let default_quote =
  { numbers  = true
  ; prefix   = ""
  ; header   = ""
  ; footer   = ""
  ; enlight  = ulined }
type style =
  1. | OCaml
    (*

    like OCaml

    *)
  2. | Short
    (*

    like gcc

    *)

Style for printing positions:

val print_pos_info : ?style:style -> ?quote:quote -> unit -> Format.formatter -> pos_info -> unit

printing for the three kind of positions, and the current position of a buffer.

The three functions below will print only the byte_pos if the file cannot be reopenned. The exception File_changed is raised if the file changed since last openning.

If quote is given, the file is quoted.

val print_pos : ?style:style -> ?quote:quote -> unit -> Format.formatter -> pos -> unit

The three functions below will print only the byte_pos if the file cannot be reopenned. The exception File_changed is raised if the file changed since last openning.

If quote is given, the file is quoted.

val print_spos : ?style:style -> ?quote:quote -> unit -> Format.formatter -> spos -> unit
val print_buf_pos : ?style:style -> ?quote:quote -> unit -> Format.formatter -> (Input.buffer * Input.idx) -> unit
exception Parse_error of Input.buffer * Input.idx * string list

Exception raised when parsing fails

val handle_exception : ?error:(exn -> 'b) -> ?style:style -> ('a -> 'b) -> 'a -> 'b

handle_exception fn v applies the function fn to v and handles the Parse_error exception. In particular, a parse error message is presented to the user in case of a failure, then error e is called where e is the raised exception. The default error is fun _ -> exit 1. raise is another possibility.

OCaml

Innovation. Community. Security.