package pacomb

  1. Overview
  2. Docs

Module Pacomb.PosSource

Functions managing positions

Sourcetype spos = Input.spos

short position

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

Type to represent an interval between two position

Sourceval phantom_pos : pos

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

Sourceval no_pos : pos
Sourceval has_pos : pos -> bool

return false on phantom_pos/no_pos

Sourceval merge : pos -> pos -> pos

build the smallest position containing both position

Sourcetype 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

Sourceexception 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.

Sourceexception File_changed
Sourceval pos_info : ?relocate:(string -> string) -> ?text:bool -> pos -> pos_info
Sourcetype 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

Sourceval default_quote : quote

default quote: ``` let ulined : string -> string = fun s -> "\0270m\027[4m" ^ s ^ "\027[0m" let default_quote = { numbers = true ; prefix = "" ; header = "" ; footer = "" ; enlight = ulined } '''

Sourcetype style =
  1. | OCaml
    (*

    like OCaml

    *)
  2. | Short
    (*

    like gcc

    *)

Style for printing positions:

Sourceval print_pos_info : ?style:style -> ?quote:quote -> unit -> out_channel -> 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.

Sourceval print_pos : ?style:style -> ?quote:quote -> unit -> out_channel -> 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.

Sourceval print_spos : ?style:style -> ?quote:quote -> unit -> out_channel -> spos -> unit
Sourceval print_buf_pos : ?style:style -> ?quote:quote -> unit -> out_channel -> (Input.buffer * Input.idx) -> unit
Sourceexception Parse_error of Input.buffer * Input.idx * string list

Exception raised when parsing fails

Sourceval 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.