package pacomb

  1. Overview
  2. Docs

Functions managing positions

type pos = {
  1. name : string;
    (*

    file's name

    *)
  2. line : int;
    (*

    line number

    *)
  3. col : int;
    (*

    column number

    *)
  4. phantom : bool;
    (*

    is the postion a "phantom", i.e. not really in the file

    *)
}

Type to represent position

type interval = {
  1. start : pos;
  2. end_ : pos;
}
type t = pos

Abbreviation

val phantom : pos

a phantom position, used for grammar accepting the empty input

val max_pos : pos -> pos -> pos

the max of to position (further in the file

val get_pos : Input.buffer -> Input.pos -> pos

Get a position from an input buffer and a column number

type style =
  1. | OCaml
    (*

    like OCaml

    *)
  2. | Short
    (*

    like gcc

    *)

Style for printing positions:

val print_pos : ?style:style -> unit -> Stdlib.out_channel -> pos -> unit

printting for position

val print_interval : ?style:style -> unit -> Stdlib.out_channel -> interval -> unit

and interval

val print_buf_pos : ?style:style -> unit -> Stdlib.out_channel -> (Input.buffer * Input.pos) -> unit

print_buf_pos () ch (buf,pos) = print_pos () ch (get_pos buf pos)

exception Parse_error of Input.buffer * Input.pos * string list

Exception raised by the function below 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.