package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Module for parsing S-expressions annotated with location information

Module for parsing S-expressions annotated with location information

type pos = Sexplib.Pre_sexp.Annotated.pos = {
  1. line : int;
  2. col : int;
  3. offset : int;
}

Position information for annotated S-expressions

type range = Sexplib.Pre_sexp.Annotated.range = {
  1. start_pos : pos;
  2. end_pos : pos;
}

Range information for annotated S-expressions

type t = Sexplib.Pre_sexp.Annotated.t =
  1. | Atom of range * Sexplib.Type.t
  2. | List of range * t list * Sexplib.Type.t

S-expression annotated with location information

type 'a conv = [
  1. | `Result of 'a
  2. | `Error of exn * t
]

Type of conversion results of annotated S-expressions.

exception Conv_exn of string * exn

Exception associated with conversion errors. First argument describes the location, the second the reason.

type stack = Sexplib.Pre_sexp.Annotated.stack = {
  1. mutable positions : pos list;
  2. mutable stack : t list list;
}

Stack used by annotation parsers

val get_sexp : t -> Sexplib.Type.t

get_sexp annot_sexp

  • returns

    S-expression associated with annotated S-expression annot_sexp.

val get_range : t -> range

get_range annot_sexp

  • returns

    the range associated with annotated S-expression annot_sexp.

val find_sexp : t -> Sexplib.Type.t -> t option

find_sexp annot_sexp sexp

  • returns

    Some res where res is the annotated S-expression that is physically equivalent to sexp in annot_sexp, or None if there is no such S-expression.

Annotated (partial) parsing
val parse : ?parse_pos:Sexp.Parse_pos.t -> ?len:int -> string -> (string, t) Sexp.parse_result

parse ?parse_pos ?len str same as parse, but returns an S-expression annotated with location information.

val parse_bigstring : ?parse_pos:Sexp.Parse_pos.t -> ?len:int -> Sexp.bigstring -> (Sexp.bigstring, t) Sexp.parse_result

parse_bigstring ?parse_pos ?len str same as parse_bigstring, but returns an S-expression annotated with location information.

val input_sexp : ?parse_pos:Sexp.Parse_pos.t -> Pervasives.in_channel -> t

input_sexp ?parse_pos ic like input_sexp, but returns an annotated S-expression instead.

val input_sexps : ?parse_pos:Sexp.Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> t list

input_sexps ?parse_pos ?buf ic like input_sexps, but returns a list of annotated S-expressions.

val input_rev_sexps : ?parse_pos:Sexp.Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> t list

input_sexps ?parse_pos ?buf ic like input_rev_sexps, but returns a list of annotated S-expressions.

Loading of annotated S-expressions

NOTE: these functions should only be used if an annotated S-expression is required.

val load_sexp : ?strict:bool -> ?buf:bytes -> string -> t

load_sexp ?strict ?buf file like load_sexp, but returns an annotated S-expression.

val load_sexps : ?buf:bytes -> string -> t list

load_sexps ?buf file like load_sexps, but returns a list of annotated S-expressions.

val load_rev_sexps : ?buf:bytes -> string -> t list

load_rev_sexps ?buf file like load_rev_sexps, but returns a list of annotated S-expressions.

String and bigstring conversions
val of_string : string -> t

of_string str same as of_string, but returns an annotated S-expression.

val of_bigstring : Sexp.bigstring -> t

of_bigstring bstr same as of_string, but operates on bigstrings.

Converters using annotations for determining error locations

val conv : (Sexplib.Type.t -> 'a) -> t -> 'a conv

conv f annot_sexp converts the S-expression associated with annotated S-expression annot_sexp using f.

  • returns

    `Result res on success, or `Error (exn, sub_annot_sexp) otherwise, where exn is the exception associated with the conversion error, and sub_annot_sexp is the annotated S-expression on which conversion failed.

val get_conv_exn : file:string -> exc:exn -> t -> exn

get_conv_exn ~file ~exc annot_sexp

  • returns

    the exception that would be raised for a given file and exception exc if conversion had failed on annotated S-expression annot_sexp. The format of the exception message is "file:line:col"

OCaml

Innovation. Community. Security.