• en

Module Sexplib

module Type : sig
type t =
| Atom of string
| List of t list
end
module Parser : sig
type token =
| STRING of string
| LPAREN
| RPAREN
| EOF
| HASH_SEMI
val sexp : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type.t
val sexp_opt : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type.t option
val sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type.t list
val rev_sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type.t list
end
module Src_pos : sig
module Relative : sig
type t = {
row : int;
col : int;
}
val sexp_of_t : t -> Type.t
val zero : t
val add : t -> t -> t
val sub : t -> t -> t
end
module Absolute : sig
type t = {
row : int;
col : int;
}
val sexp_of_t : t -> Type.t
val origin : t
val of_lexing : Lexing.position -> t
val diff : t -> t -> Relative.t
val add : t -> Relative.t -> t
val sub : t -> Relative.t -> t
val geq : t -> t -> bool
end
end
module Type_with_layout : sig
TODO: functor:sexplib.111.25.00/sexplib/Sexplib.Type_with_layout.Make
module Parsed : Make(Src_pos.Absolute).S
parsing produces absolute positions
type t =
| Atom of Src_pos.Relative.t * string * string option
| List of Src_pos.Relative.t * t_or_comment list * Src_pos.Relative.t
S-expressions annotated with relative source positions and comments
type t_or_comment =
| Sexp of t
| Comment of comment
type comment =
| Plain_comment of Src_pos.Relative.t * string
| Sexp_comment of Src_pos.Relative.t * comment list * t
val sexp_of_t : t -> Type.t
val sexp_of_comment : comment -> Type.t
val sexp_of_t_or_comment : t_or_comment -> Type.t
val relativize : Parsed.t_or_comment -> t_or_comment
end
module Parser_with_layout : sig
type token =
| STRING of (string * (Lexing.position * string) option)
| COMMENT of (string * Lexing.position option)
| LPAREN
| RPAREN
| EOF
| HASH_SEMI
val sexp : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.t_or_comment
val sexp_opt : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.t_or_comment option
val sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.t_or_comment list
val sexps_abs : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.Parsed.t_or_comment list
val rev_sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.t_or_comment list
end
module Lexer : sig
val main : ?buf:Buffer.t -> Lexing.lexbuf -> Parser.token
val main_with_layout : ?buf:Buffer.t -> Lexing.lexbuf -> Parser_with_layout.token
end
module Pre_sexp : sig
type t = Type.t =
| Atom of string
| List of t list
exception Of_sexp_error of exn * t
val default_indent : int Pervasives.ref
val must_escape : string -> bool
val esc_str : string -> bytes
val index_of_newline : string -> int -> int option
val get_substring : string -> int -> int option -> string
val is_one_line : string -> bool
val pp_hum_maybe_esc_str : Format.formatter -> string -> unit
val mach_maybe_esc_str : bytes -> bytes
val pp_hum_indent : int -> Format.formatter -> t -> unit
val pp_hum_rest : int -> Format.formatter -> t list -> unit
val pp_mach_internal : bool -> Format.formatter -> t -> bool
val pp_mach_rest : bool -> Format.formatter -> t list -> unit
val pp_hum : Format.formatter -> t -> unit
val pp_mach : Format.formatter -> t -> unit
val pp : Format.formatter -> t -> unit
val size_loop : (int * int) -> t -> (int * int)
val size : t -> (int * int)
val to_buffer_hum : buf:Buffer.t -> ?indent:int -> t -> unit
val to_buffer_mach : buf:Buffer.t -> t -> unit
val to_buffer : buf:Buffer.t -> t -> unit
val to_buffer_gen : buf:'a -> add_char:'a -> char -> unit -> add_string:'a -> bytes -> 'b -> t -> unit
val buffer : unit -> Buffer.t
val with_new_buffer : Pervasives.out_channel -> Buffer.t -> 'a -> unit
val output_hum : Pervasives.out_channel -> t -> unit
val output_hum_indent : int -> Pervasives.out_channel -> t -> unit
val output_mach : Pervasives.out_channel -> t -> unit
val output : Pervasives.out_channel -> t -> unit
module Tmp_file : sig
val prng : Random.State.t option Pervasives.ref
val temp_file_name : string -> string -> string
val open_temp_file : ?perm:int -> string -> string -> (string * Pervasives.out_channel)
end
val save_of_output : ?perm:int -> Pervasives.out_channel -> 'a -> 'b -> string -> 'a -> unit
val output_sexp_nl : Pervasives.out_channel -> 'a -> 'b -> Pervasives.out_channel -> 'a -> unit
val save_hum : ?perm:int -> string -> t -> unit
val save_mach : ?perm:int -> string -> t -> unit
val save : ?perm:int -> string -> t -> unit
val output_sexps_nl : Pervasives.out_channel -> 'a -> 'b -> Pervasives.out_channel -> 'a list -> unit
val save_sexps_hum : ?perm:int -> string -> t list -> unit
val save_sexps_mach : ?perm:int -> string -> t list -> unit
val save_sexps : ?perm:int -> string -> t list -> unit
val to_string_hum : ?indent:int -> t -> bytes
val to_string_mach : t -> bytes
val to_string : t -> bytes
val scan_sexp : ?buf:Buffer.t -> Lexing.lexbuf -> Type.t
val scan_sexp_opt : ?buf:Buffer.t -> Lexing.lexbuf -> Type.t option
val scan_sexps : ?buf:Buffer.t -> Lexing.lexbuf -> Type.t list
val scan_rev_sexps : ?buf:Buffer.t -> Lexing.lexbuf -> Type.t list
val get_main_buf : Buffer.t option -> Lexing.lexbuf -> Parser.token
val scan_fold_sexps : ?buf:Buffer.t -> f:'a -> Type.t -> 'a -> init:'a -> Lexing.lexbuf -> 'a
val scan_iter_sexps : ?buf:Buffer.t -> f:Type.t -> unit -> Lexing.lexbuf -> unit
val scan_sexps_conv : ?buf:Buffer.t -> f:Type.t -> 'a -> Lexing.lexbuf -> 'a list
module Annot : sig
type pos = {
line : int;
col : int;
offset : int;
}
type range = {
start_pos : pos;
end_pos : pos;
}
type t =
| Atom of range * Type.t
| List of range * t list * Type.t
type 'a conv = TODO: b
exception Conv_exn of string * exn
type stack = {
positions : pos list;
stack : t list list;
}
val get_sexp : t -> Type.t
val get_range : t -> range
exception Annot_sexp of t
val find_sexp : t -> Type.t -> t option
end
module Parse_pos : sig
type t = {
text_line : int;
text_char : int;
global_offset : int;
buf_pos : int;
}
val create : ?text_line:int -> ?text_char:int -> ?buf_pos:int -> ?global_offset:int -> unit -> t
val with_buf_pos : t -> int -> t
end
module Cont_state : sig
type t =
| Parsing_whitespace
| Parsing_atom
| Parsing_list
| Parsing_sexp_comment
| Parsing_block_comment
val to_string : t -> string
end
type ('a, 't) parse_result =
| Done of 't * Parse_pos.t
| Cont of Cont_state.t * ('a, 't) parse_fun
type ('a, 't) parse_fun = pos:int -> len:int -> 'a -> ('a, 't) parse_result
type 't parse_state = {
parse_pos : Parse_pos.t;
pstack : 't;
pbuf : Buffer.t;
}
type parse_error = {
location : string;
err_msg : string;
parse_state : TODO: a;
}
exception Parse_error of parse_error
val bump_text_line : 'a parse_state -> unit
val bump_text_pos : 'a parse_state -> unit
val bump_pos_cont : 'a parse_state -> 'b -> max_pos:'c -> pos:int -> 'a parse_state -> 'b -> max_pos:'c -> pos:int -> 'd -> 'd
val bump_line_cont : 'a parse_state -> 'b -> max_pos:'c -> pos:int -> 'a parse_state -> 'b -> max_pos:'c -> pos:int -> 'd -> 'd
val add_bump : 'a parse_state -> 'b -> 'a parse_state -> 'c -> max_pos:'d -> pos:int -> char -> 'a parse_state -> 'c -> max_pos:'d -> pos:int -> 'e -> 'e
val add_bump_pos : 'a parse_state -> 'b -> max_pos:'c -> pos:int -> char -> 'a parse_state -> 'b -> max_pos:'c -> pos:int -> 'd -> 'd
val add_bump_line : 'a parse_state -> 'b -> max_pos:'c -> pos:int -> char -> 'a parse_state -> 'b -> max_pos:'c -> pos:int -> 'd -> 'd
val set_parse_pos : Parse_pos.t -> int -> unit
val mk_parse_pos : 'a parse_state -> int -> Parse_pos.t
val raise_parse_error : TODO: a -> string -> int -> string -> 'b
val raise_unexpected_char : TODO: a -> string -> int -> char -> 'b
val mk_cont_parser : pos:int -> len:int -> 'a -> 'b -> 'c -> 'a -> max_pos:int -> pos:int -> 'b
val parse_str : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result
val get_glob_ofs : Parse_pos.t -> int -> int
val mk_annot_pos : Parse_pos.t -> int -> Annot.pos
val mk_annot_pos1 : Parse_pos.t -> int -> Annot.pos
val add_annot_pos : Annot.stack parse_state -> int -> unit
val add_annot_pos1 : Annot.stack parse_state -> int -> unit
val get_annot_range : Annot.stack parse_state -> int -> Annot.range
val mk_annot_atom : Annot.stack parse_state -> string -> int -> Annot.t
val mk_annot_list : Annot.stack parse_state -> Annot.t list -> int -> Annot.t
val init_annot_pstate : unit -> Annot.stack
val parse_str_annot : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, Annot.t) parse_result
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, t) parse_result
val bump_found_atom : Annot.stack parse_state -> 'a -> Annot.stack parse_state -> 'b -> max_pos:'c -> pos:int -> Annot.stack parse_state -> 'b -> max_pos:'c -> pos:int -> ('d, Annot.t) parse_result -> ('d, Annot.t) parse_result
val check_str_bounds : string -> pos:int -> len:int -> bigstring -> int
val mk_cont_state : string -> 'a -> bigstring -> max_pos:int -> pos:int -> (bigstring, 'b) parse_result -> 'a -> cont_state:Cont_state.t -> (bigstring, 'b) parse_result
val mk_cont : string -> Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, 'a) parse_result -> Annot.stack parse_state -> (bigstring, 'a) parse_result
val parse_nl : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_comment : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val maybe_parse_comment : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val maybe_parse_close_comment : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_sexp_comment : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_block_comment : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_atom : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val maybe_parse_bad_atom_pipe : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val maybe_parse_bad_atom_hash : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val reg_parse_quoted : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_quoted : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_escaped : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_skip_ws : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_skip_ws_nl : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> (bigstring, Annot.t) parse_result
val parse_dec : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> count:int -> d:int -> (bigstring, Annot.t) parse_result
val parse_hex : Annot.stack parse_state -> bigstring -> max_pos:int -> pos:int -> count:int -> d:int -> (bigstring, Annot.t) parse_result
val parse_bigstring_annot : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, Annot.t) parse_result
val mk_this_parse : ?parse_pos:Parse_pos.t -> ?parse_pos:Parse_pos.t -> ?len:'a -> 'b -> 'c -> pos:int -> len:'a -> 'b -> 'c
val gen_input_sexp : ?parse_pos:Parse_pos.t -> ?len:int -> bytes -> (bytes, 'a) parse_result -> ?parse_pos:Parse_pos.t -> Pervasives.in_channel -> 'a
val input_sexp : ?parse_pos:Parse_pos.t -> Pervasives.in_channel -> t
val gen_input_rev_sexps : ?parse_pos:Parse_pos.t -> ?len:int -> bytes -> (bytes, 'a) parse_result -> ?parse_pos:Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> 'a list
val input_rev_sexps : ?parse_pos:Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> t list
val input_sexps : ?parse_pos:Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> t list
val of_string_bigstring : string -> 'a -> ('b, 'c) parse_result -> 'b -> 'a -> int -> 'a -> int -> int -> string -> 'a -> 'c
val of_string : string -> t
val get_bstr_sub_str : (char, 'a, 'b) Bigarray.Array1.t -> int -> int -> bytes
val of_bigstring : bigstring -> t
val gen_load_rev_sexps : ?parse_pos:'a -> ?buf:'b -> Pervasives.in_channel -> 'c -> ?buf:'b -> string -> 'c
val load_rev_sexps : ?buf:bytes -> string -> t list
val load_sexps : ?buf:bytes -> string -> t list
val gen_load_sexp_loc : string
val gen_load_sexp : ?parse_pos:Parse_pos.t -> ?len:int -> bytes -> (bytes, 'a) parse_result -> ?strict:bool -> ?buf:bytes -> string -> 'a
val load_sexp : ?strict:bool -> ?buf:bytes -> string -> t
module Annotated : sig
type pos = Annot.pos = {
line : int;
col : int;
offset : int;
}
type range = Annot.range = {
start_pos : pos;
end_pos : pos;
}
type t = Annot.t =
| Atom of range * Type.t
| List of range * t list * Type.t
type 'a conv = TODO: b
exception Conv_exn of string * exn
type stack = Annot.stack = {
positions : pos list;
stack : t list list;
}
val get_sexp : t -> Type.t
val get_range : t -> range
exception Annot_sexp of t
val find_sexp : t -> Type.t -> t option
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, Annot.t) parse_result
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, Annot.t) parse_result
val input_rev_sexps : ?parse_pos:Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> Annot.t list
val input_sexp : ?parse_pos:Parse_pos.t -> Pervasives.in_channel -> Annot.t
val input_sexps : ?parse_pos:Parse_pos.t -> ?buf:bytes -> Pervasives.in_channel -> Annot.t list
val of_string : string -> Annot.t
val of_bigstring : bigstring -> Annot.t
val load_rev_sexps : ?buf:bytes -> string -> Annot.t list
val load_sexps : ?buf:bytes -> string -> Annot.t list
val load_sexp : ?strict:bool -> ?buf:bytes -> string -> Annot.t
val conv : Type.t -> 'a -> t -> TODO: b
val get_conv_exn : file:string -> exc:exn -> t -> exn
end
val load_sexp_conv : ?strict:bool -> ?buf:bytes -> string -> t -> 'a -> TODO: b
val raise_conv_exn : file:string -> TODO: a -> 'b
val load_sexp_conv_exn : ?strict:bool -> ?buf:bytes -> string -> t -> 'a -> 'a
val load_sexps_conv : ?buf:bytes -> string -> t -> 'a -> TODO: b list
val load_sexps_conv_exn : ?buf:bytes -> string -> t -> 'a -> 'a list
val gen_of_string_conv : 'a -> Type.t -> 'a -> Annotated.t -> 'a -> Type.t -> 'b -> TODO: c
val of_string_conv : string -> t -> 'a -> TODO: b
val of_bigstring_conv : bigstring -> t -> 'a -> TODO: b
module Of_string_conv_exn : sig
type t = {
exc : exn;
sexp : Type.t;
sub_sexp : Type.t;
}
exception E of t
end
val gen_of_string_conv_exn : 'a -> Type.t -> 'a -> Type.t -> 'b -> 'b
val of_string_conv_exn : string -> t -> 'a -> 'a
val of_bigstring_conv_exn : bigstring -> t -> 'a -> 'a
val unit : t
val sexp_of_t : t -> t
val t_of_sexp : t -> t
type found = TODO: a
type search_result = TODO: a
val search_physical : t -> contained:t -> TODO: a
val subst_found : t -> subst:t -> TODO: a -> t
end
module Sexp_intf : sig
module type S = sig
type t = Type.t =
| Atom of string
| List of t list
Type of S-expressions
type bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
Type of bigstrings
val default_indent : int Pervasives.ref
default_indent reference to default indentation level for human-readable conversions. Initialisation value: 2.
val size : t -> (int * int)
size sexp
Returns (n_atoms, n_chars), where n_atoms is the number of atoms in S-expression sexp, and n_chars is the number of characters in the atoms of the S-expression.
val scan_sexp : ?buf:Buffer.t -> Lexing.lexbuf -> t
scan_sexp ?buf lexbuf scans an S-expression from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
val scan_sexps : ?buf:Buffer.t -> Lexing.lexbuf -> t list
scan_sexps ?buf lexbuf reads a list of whitespace separated S-expressions from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
val scan_rev_sexps : ?buf:Buffer.t -> Lexing.lexbuf -> t list
scan_rev_sexps ?buf lexbuf same as scan_sexps, but returns the reversed list and is slightly more efficient.
val scan_sexp_opt : ?buf:Buffer.t -> Lexing.lexbuf -> t option
scan_sexp_opt ?buf lexbuf is equivalent to scan_sexp ?buf lexbuf except that it returns None when the eof is reached.
val scan_iter_sexps : ?buf:Buffer.t -> f:t -> unit -> Lexing.lexbuf -> unit
scan_iter_sexps ?buf ~f lexbuf iterates over all whitespace separated S-expressions scanned from lex buffer lexbuf using function f, and the optional string buffer buf for storing intermediate strings.
val scan_fold_sexps : ?buf:Buffer.t -> f:'a -> t -> 'a -> init:'a -> Lexing.lexbuf -> 'a
scan_fold_sexps ?buf ~f ~init lexbuf folds over all whitespace separated S-expressions scanned from lex buffer lexbuf using function f, initial state init, and the optional string buffer buf for storing intermediate strings.
val scan_sexps_conv : ?buf:Buffer.t -> f:t -> 'a -> Lexing.lexbuf -> 'a list
scan_sexps_conv ?buf ~f lexbuf maps all whitespace separated S-expressions scanned from lex buffer lexbuf to some list using function f, and the optional string buffer buf for storing intermediate strings.
module Parse_pos : sig
type t = Pre_sexp.Parse_pos.t = {
text_line : int; (* Line position in parsed text *)
text_char : int; (* Character position in parsed text *)
global_offset : int; (* Global/logical offset *)
buf_pos : int; (* Read position in string buffer *)
}
Position information after complete parse
val create : ?text_line:int -> ?text_char:int -> ?buf_pos:int -> ?global_offset:int -> unit -> t
create ?text_line ?text_char ?buf_pos ?global_offset ()
Returns a parse position with the given parameters.
text_line default = 1
text_char default = 0
global_offset default = 0
buf_pos default = 0
val with_buf_pos : t -> int -> t
with_buf_pos t pos
Returns a copy of the parse position t where buf_pos is set to pos.
end
module Cont_state : sig
type t = Pre_sexp.Cont_state.t =
| Parsing_whitespace
| Parsing_atom
| Parsing_list
| Parsing_sexp_comment
| Parsing_block_comment
State of parser continuations
val to_string : t -> string
to_string cont_state converts state of parser continuation cont_state to a string.
end
type ('a, 't) parse_result = ('a, 't) Pre_sexp.parse_result =
| Done of 't * Parse_pos.t (* Done (t, parse_pos) finished parsing an S-expression. Current parse position is parse_pos. *)
| Cont of Cont_state.t * ('a, 't) parse_fun (* Cont (cont_state, parse_fun) met the end of input before completely parsing an S-expression. The user has to call parse_fun to continue parsing the S-expression in another buffer. cont_state is the current parsing state of the continuation. NOTE: the continuation may only be called once and will raise Failure otherwise! *)
Type of result from calling Sexp.parse.
type ('a, 't) parse_fun = pos:int -> len:int -> 'a -> ('a, 't) parse_result
Type of parsing functions with given offsets and lengths.
module Annotated : sig
Module for parsing S-expressions annotated with location information
type pos = Pre_sexp.Annotated.pos = {
line : int;
col : int;
offset : int;
}
Position information for annotated S-expressions
type range = Pre_sexp.Annotated.range = {
start_pos : pos;
end_pos : pos;
}
Range information for annotated S-expressions
type t = Pre_sexp.Annotated.t =
| Atom of range * Type.t
| List of range * t list * Type.t
S-expression annotated with location information
type 'a conv = TODO: b
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 = Pre_sexp.Annotated.stack = {
positions : pos list;
stack : t list list;
}
Stack used by annotation parsers
val get_sexp : t -> 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 -> 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.
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result
parse ?parse_pos ?len str same as parse, but returns an S-expression annotated with location information.
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, t) 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: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:Parse_pos.t -> ?buf:string -> 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:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list
input_sexps ?parse_pos ?buf ic like input_rev_sexps, but returns a list of annotated S-expressions.
val load_sexp : ?strict:bool -> ?buf:string -> string -> t
load_sexp ?strict ?buf file like load_sexp, but returns an annotated S-expression.
val load_sexps : ?buf:string -> string -> t list
load_sexps ?buf file like load_sexps, but returns a list of annotated S-expressions.
val load_rev_sexps : ?buf:string -> string -> t list
load_rev_sexps ?buf file like load_rev_sexps, but returns a list of annotated S-expressions.
val of_string : string -> t
of_string str same as of_string, but returns an annotated S-expression.
val of_bigstring : bigstring -> t
of_bigstring bstr same as of_string, but operates on bigstrings.
val conv : 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"
end
type 't parse_state = 't Pre_sexp.parse_state = {
parse_pos : Parse_pos.t; (* Current parse position *)
pstack : 't; (* Stack of found S-expression lists *)
pbuf : Buffer.t; (* Current atom buffer *)
}
Type of state maintained during parsing
type parse_error = Pre_sexp.parse_error = {
location : string; (* Function in which the parse failed *)
err_msg : string; (* Reason why parsing failed *)
parse_state : TODO: a; (* State of parser *)
}
Type of parse errors
exception Parse_error of parse_error
Exception raised during partial parsing
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result
parse ?parse_pos ?len str (partially) parses an S-expression in string buffer str starting out with position information provided in parse_pos and reading at most len characters. To parse a single atom that is not delimited by whitespace it is necessary to call this function a second time with the returned continuation, and a dummy buffer that contains whitespace.
parse starts parsing str at position parse_pos.buf_pos. Each subsequent parse_fun from a Cont uses the buf and pos that is supplied to it. The final parse_fun that returns Done mutates the buf_pos in the originally supplied parse_pos, and then returns it.
parse_pos default = Parse_pos.create ()
len default = String.length str - parse_pos.Parse_pos.buf_pos
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, t) parse_result
parse_bigstring ?parse_pos ?len str same as parse, but operates on bigstrings.
val input_sexp : ?parse_pos:Parse_pos.t -> Pervasives.in_channel -> t
input_sexp ?parse_pos ic parses an S-expression from input channel ic using initial position information in parse_pos. NOTE: this function is not as fast on files as Sexp.load_sexp, and is also slightly slower than the scan-functions. But it is guaranteed that input_sexp is only going to read data parseable as an S-expression. Thus, subsequent input functions will see the data immediately following it.
parse_pos default = Parse_pos.create ()
val input_sexps : ?parse_pos:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list
input_sexps ?parse_pos ?buf ic parses whitespace separated S-expressions from input channel ic until EOF is reached. Faster than the scan-functions.
parse_pos default = Parse_pos.create ()
val input_rev_sexps : ?parse_pos:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list
input_rev_sexps ?parse_pos ?buf ic same as Sexp.input_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.
val load_sexp : ?strict:bool -> ?buf:string -> string -> t
load_sexp ?strict ?buf file reads one S-expression from file using buffer buf for storing intermediate data. Faster than the scan-functions.
Raises Parse_error if the S-expression is unparseable.
Raises Failure if parsing reached the end of file before one S-expression could be read.
Raises Failure if strict is true and there is more than one S-expression in the file.
strict default = true
val load_sexps : ?buf:string -> string -> t list
load_sexps ?buf file reads a list of whitespace separated S-expressions from file using buffer buf for storing intermediate data. Faster than the scan-functions.
Raises Parse_error if there is unparseable data in the file.
Raises Failure if parsing reached the end of file before the last S-expression could be fully read.
val load_rev_sexps : ?buf:string -> string -> t list
load_rev_sexps ?buf file same as Sexp.load_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.
val load_sexp_conv : ?strict:bool -> ?buf:string -> string -> t -> 'a -> 'a Annotated.conv
load_sexp_conv ?strict ?buf file f like Sexp.load_sexp, but performs a conversion on the fly using f. Performance is equivalent to executing Sexp.load_sexp and performing conversion when there are no errors. In contrast to the plain S-expression loader, this function not only performs the conversion, it will give exact error ranges for conversion errors.
Raises Parse_error if there is unparseable data in the file.
Raises Failure if parsing reached the end of file before the last S-expression could be fully read.
val load_sexp_conv_exn : ?strict:bool -> ?buf:string -> string -> t -> 'a -> 'a
load_sexp_conv_exn ?strict ?buf file f like load_sexp_conv, but returns the converted value or raises Of_sexp_error with exact location information in the case of a conversion error.
val load_sexps_conv : ?buf:string -> string -> t -> 'a -> 'a Annotated.conv list
load_sexps_conv ?buf file f like Sexp.load_sexps, but performs a conversion on the fly using f. Performance is equivalent to executing Sexp.load_sexps and performing conversion when there are no errors. In contrast to the plain S-expression loader, this function not only performs the conversion, it will give exact error ranges for conversion errors.
Raises Parse_error if there is unparseable data in the file.
Raises Failure if parsing reached the end of file before the last S-expression could be fully read.
val load_sexps_conv_exn : ?buf:string -> string -> t -> 'a -> 'a list
load_sexps_conv_exn ?buf file f like load_sexps_conv, but returns the converted value or raises Of_sexp_error with exact location information in the case of a conversion error.
val output_hum : Pervasives.out_channel -> t -> unit
output_hum oc sexp outputs S-expression sexp to output channel oc in human readable form.
val output_hum_indent : int -> Pervasives.out_channel -> t -> unit
output_hum_indent indent oc sexp outputs S-expression sexp to output channel oc in human readable form using indentation level indent.
val output_mach : Pervasives.out_channel -> t -> unit
output_mach oc sexp outputs S-expression sexp to output channel oc in machine readable (i.e. most compact) form.
val output : Pervasives.out_channel -> t -> unit
output oc sexp same as output_mach.
val save_hum : ?perm:int -> string -> t -> unit
save_hum ?perm file sexp outputs S-expression sexp to file in human readable form.
perm default = umask
val save_mach : ?perm:int -> string -> t -> unit
save_mach ?perm file sexp outputs S-expression sexp to file in machine readable (i.e. most compact) form.
perm default = umask
val save : ?perm:int -> string -> t -> unit
save ?perm file sexp same as save_mach.
val save_sexps_hum : ?perm:int -> string -> t list -> unit
save_sexps_hum ?perm file sexps outputs S-expression list sexps to file in human readable form, each sexp being followed by a newline.
perm default = umask
val save_sexps_mach : ?perm:int -> string -> t list -> unit
save_sexps_mach ?perm file sexps outputs S-expression list sexps to file in machine readable form, each sexp being followed by a newline.
perm default = umask
val save_sexps : ?perm:int -> string -> t list -> unit
save_sexps ?perm file sexp same as save_sexps_mach.
val pp_hum : Format.formatter -> t -> unit
pp_hum ppf sexp outputs S-expression sexp to formatter ppf in human readable form.
val pp_hum_indent : int -> Format.formatter -> t -> unit
pp_hum_indent n ppf sexp outputs S-expression sexp to formatter ppf in human readable form and indentation level n.
val pp_mach : Format.formatter -> t -> unit
pp_mach ppf sexp outputs S-expression sexp to formatter ppf in machine readable (i.e. most compact) form.
val pp : Format.formatter -> t -> unit
pp ppf sexp same as pp_mach.
module Of_string_conv_exn : sig
Module encapsulating the exception raised by string converters when type conversions fail.
type t = {
exc : exn;
sexp : Type.t;
sub_sexp : Type.t;
}
exception E of t
end
val of_string : string -> t
of_string str converts string str to an S-expression. NOTE: trailing whitespace is considered an error, which may be overly strict for some applications. Either strip the string of trailing whitespace first, or, even cheaper, use parse instead.
val of_string_conv : string -> t -> 'a -> 'a Annotated.conv
of_string_conv str conv like of_string, but performs type conversion with conv.
Returns conversion result.
val of_string_conv_exn : string -> t -> 'a -> 'a
of_string_conv_exn str conv like of_string_conv, but raises Of_string_conv_exn.E if type conversion fails.
Returns converted value.
val of_bigstring : bigstring -> t
of_bigstring bstr same as of_string, but operates on bigstrings.
val of_bigstring_conv : bigstring -> t -> 'a -> 'a Annotated.conv
of_bigstring_conv bstr conv like of_bigstring, but performs type conversion with conv.
Returns conversion result.
val of_bigstring_conv_exn : bigstring -> t -> 'a -> 'a
of_bigstring_conv_exn bstr conv like of_bigstring_conv, but raises Of_string_conv_exn.E if type conversion fails.
Returns converted value.
val to_string_hum : ?indent:int -> t -> string
to_string_hum ?indent sexp converts S-expression sexp to a string in human readable form with indentation level indent.
indent default = !default_indent
val to_string_mach : t -> string
to_string_mach sexp converts S-expression sexp to a string in machine readable (i.e. most compact) form.
val to_string : t -> string
to_string sexp same as to_string_mach.
val to_buffer_hum : buf:Buffer.t -> ?indent:int -> t -> unit
to_buffer_hum ~buf ?indent sexp outputs the S-expression sexp converted to a string in human readable form to buffer buf.
indent default = !default_indent
val to_buffer_mach : buf:Buffer.t -> t -> unit
to_buffer_mach ~buf sexp outputs the S-expression sexp converted to a string in machine readable (i.e. most compact) form to buffer buf.
val to_buffer : buf:Buffer.t -> t -> unit
to_buffer ~buf sexp same as to_buffer_mach.
val to_buffer_gen : buf:'buffer -> add_char:'buffer -> char -> unit -> add_string:'buffer -> string -> unit -> t -> unit
to_buffer_gen ~buf ~add_char ~add_string sexp outputs the S-expression sexp converted to a string to buffer buf using the output functions add_char and add_string.
val unit : t
unit the unit-value as expressed by an S-expression.
val sexp_of_t : t -> t
sexp_of_t sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.
val t_of_sexp : t -> t
t_of_sexp sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.
type found = TODO: a
Type of successful search results. `Found means that an S-expression was found at the immediate position, and `Pos (pos, found) indicates that it was found at position pos within a structure (= S-expression list) where found describes recursively where it was found in that structure.
type search_result = TODO: a
Type of search results. `Not_found means that an S-expression was not found within another S-expression.
val search_physical : t -> contained:t -> search_result
search_physical sexp ~contained
Returns the search result indicating whether, and if, where the S-expression contained was found within S-expression sexp.
val subst_found : t -> subst:t -> found -> t
subst_found sexp ~subst found
Returns the S-expression that results from substituting subst within S-expression sexp at the location described by found.
module With_layout : sig
S-expressions annotated with relative source positions and comments
type pos = Src_pos.Relative.t = {
row : int;
col : int;
}
val sexp_of_pos : pos -> Type.t
type t =
| Atom of pos * string * string option
| List of pos * t_or_comment list * pos
S-expressions annotated with relative source positions and comments
type t_or_comment =
| Sexp of t
| Comment of comment
type comment =
| Plain_comment of pos * string
| Sexp_comment of pos * comment list * t
val sexp_of_t : t -> Type.t
val sexp_of_comment : comment -> Type.t
val sexp_of_t_or_comment : t_or_comment -> Type.t
module Forget : sig
val t : t -> Type.t
val t_or_comment : t_or_comment -> Type.t option
val t_or_comments : t_or_comment list -> Type.t list
end
module Render : sig
type 'a t
val return : 'a -> 'a t
val bind : 'a t -> 'a -> 'b t -> 'b t
val sexp : t_or_comment -> unit t
val run : char -> unit -> unit t -> unit
end
module Parser : sig
type token
val sexp : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment
val sexp_opt : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment option
val sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment list
val rev_sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment list
val sexps_abs : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.Parsed.t_or_comment list
end
module Lexer : sig
val main : ?buf:Buffer.t -> Lexing.lexbuf -> Parser.token
end
end
end
end
module Sexp_with_layout : sig
module List : sig
val iter : 'a list -> f:'a -> unit -> unit
val map : 'a list -> f:'a -> 'b -> 'b list
end
module Make = Type_with_layout.Make
module Parsed = Type_with_layout.Parsed
parsing produces absolute positions
type t = Type_with_layout.t =
| Atom of Src_pos.Relative.t * string * string option
| List of Src_pos.Relative.t * t_or_comment list * Src_pos.Relative.t
S-expressions annotated with relative source positions and comments
type t_or_comment = Type_with_layout.t_or_comment =
| Sexp of t
| Comment of comment
type comment = Type_with_layout.comment =
| Plain_comment of Src_pos.Relative.t * string
| Sexp_comment of Src_pos.Relative.t * comment list * t
val sexp_of_t : t -> Type.t
val sexp_of_comment : comment -> Type.t
val sexp_of_t_or_comment : t_or_comment -> Type.t
val relativize : Parsed.t_or_comment -> t_or_comment
type pos = Src_pos.Relative.t = {
row : int;
col : int;
}
val sexp_of_pos : Src_pos.Relative.t -> Type.t
module Lexer : sig
val main : ?buf:Buffer.t -> Lexing.lexbuf -> Parser_with_layout.token
end
module Parser = Parser_with_layout
module Render : sig
module Rel_pos = Src_pos.Relative
module Abs_pos = Src_pos.Absolute
type last_atom = {
immed_after : Abs_pos.t;
unescaped : bool;
}
type state = {
row_shift : Rel_pos.t;
current : Abs_pos.t;
last_atom : last_atom option;
}
type 'a t = char -> unit -> state -> 'a
val return : 'a -> 'b -> 'c -> 'a
val bind : 'a -> 'b -> 'c -> 'c -> 'a -> 'b -> 'd -> 'a -> 'b -> 'd
val run : 'a -> 'a -> state -> 'b -> 'b
val emit_char : char -> 'a -> state -> char -> unit
val emit_string : char -> 'a -> state -> string -> unit
val emit_chars : char -> 'a -> state -> char -> n:int -> unit
val advance : char -> 'a -> anchor:Abs_pos.t -> state -> by:Src_pos.Relative.t -> unescaped_atom:bool -> unit
val render_t : char -> 'a -> anchor:Abs_pos.t -> state -> t -> unit
val render_toc : char -> 'a -> anchor:Abs_pos.t -> state -> t_or_comment -> unit
val render_c : char -> 'a -> anchor:Abs_pos.t -> state -> comment -> unit
val render : t_or_comment -> char -> 'a -> state -> unit
val sexp : t_or_comment -> char -> 'a -> state -> unit
end
module Forget : sig
module Cps : sig
val forget_t : t -> Type.t -> 'r -> 'r
val forget_toc : t_or_comment -> Type.t option -> 'r -> 'r
val forget_tocs : t_or_comment list -> Type.t list -> 'r -> 'r
end
val t : t -> Type.t
val t_or_comment : t_or_comment -> Type.t option
val t_or_comments : t_or_comment list -> Type.t list
end
end
module Sexp : sig
type t = Type.t =
| Atom of string
| List of t list
Type of S-expressions
type bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
Type of bigstrings
val default_indent : int Pervasives.ref
default_indent reference to default indentation level for human-readable conversions. Initialisation value: 2.
val size : t -> (int * int)
size sexp
Returns (n_atoms, n_chars), where n_atoms is the number of atoms in S-expression sexp, and n_chars is the number of characters in the atoms of the S-expression.
val scan_sexp : ?buf:Buffer.t -> Lexing.lexbuf -> t
scan_sexp ?buf lexbuf scans an S-expression from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
val scan_sexps : ?buf:Buffer.t -> Lexing.lexbuf -> t list
scan_sexps ?buf lexbuf reads a list of whitespace separated S-expressions from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
val scan_rev_sexps : ?buf:Buffer.t -> Lexing.lexbuf -> t list
scan_rev_sexps ?buf lexbuf same as scan_sexps, but returns the reversed list and is slightly more efficient.
val scan_sexp_opt : ?buf:Buffer.t -> Lexing.lexbuf -> t option
scan_sexp_opt ?buf lexbuf is equivalent to scan_sexp ?buf lexbuf except that it returns None when the eof is reached.
val scan_iter_sexps : ?buf:Buffer.t -> f:t -> unit -> Lexing.lexbuf -> unit
scan_iter_sexps ?buf ~f lexbuf iterates over all whitespace separated S-expressions scanned from lex buffer lexbuf using function f, and the optional string buffer buf for storing intermediate strings.
val scan_fold_sexps : ?buf:Buffer.t -> f:'a -> t -> 'a -> init:'a -> Lexing.lexbuf -> 'a
scan_fold_sexps ?buf ~f ~init lexbuf folds over all whitespace separated S-expressions scanned from lex buffer lexbuf using function f, initial state init, and the optional string buffer buf for storing intermediate strings.
val scan_sexps_conv : ?buf:Buffer.t -> f:t -> 'a -> Lexing.lexbuf -> 'a list
scan_sexps_conv ?buf ~f lexbuf maps all whitespace separated S-expressions scanned from lex buffer lexbuf to some list using function f, and the optional string buffer buf for storing intermediate strings.
module Parse_pos : sig
type t = Pre_sexp.Parse_pos.t = {
text_line : int; (* Line position in parsed text *)
text_char : int; (* Character position in parsed text *)
global_offset : int; (* Global/logical offset *)
buf_pos : int; (* Read position in string buffer *)
}
Position information after complete parse
val create : ?text_line:int -> ?text_char:int -> ?buf_pos:int -> ?global_offset:int -> unit -> t
create ?text_line ?text_char ?buf_pos ?global_offset ()
Returns a parse position with the given parameters.
text_line default = 1
text_char default = 0
global_offset default = 0
buf_pos default = 0
val with_buf_pos : t -> int -> t
with_buf_pos t pos
Returns a copy of the parse position t where buf_pos is set to pos.
end
module Cont_state : sig
type t = Pre_sexp.Cont_state.t =
| Parsing_whitespace
| Parsing_atom
| Parsing_list
| Parsing_sexp_comment
| Parsing_block_comment
State of parser continuations
val to_string : t -> string
to_string cont_state converts state of parser continuation cont_state to a string.
end
type ('a, 't) parse_result = ('a, 't) Pre_sexp.parse_result =
| Done of 't * Parse_pos.t (* Done (t, parse_pos) finished parsing an S-expression. Current parse position is parse_pos. *)
| Cont of Cont_state.t * ('a, 't) parse_fun (* Cont (cont_state, parse_fun) met the end of input before completely parsing an S-expression. The user has to call parse_fun to continue parsing the S-expression in another buffer. cont_state is the current parsing state of the continuation. NOTE: the continuation may only be called once and will raise Failure otherwise! *)
Type of result from calling Sexp.parse.
type ('a, 't) parse_fun = pos:int -> len:int -> 'a -> ('a, 't) parse_result
Type of parsing functions with given offsets and lengths.
module Annotated : sig
Module for parsing S-expressions annotated with location information
type pos = Pre_sexp.Annotated.pos = {
line : int;
col : int;
offset : int;
}
Position information for annotated S-expressions
type range = Pre_sexp.Annotated.range = {
start_pos : pos;
end_pos : pos;
}
Range information for annotated S-expressions
type t = Pre_sexp.Annotated.t =
| Atom of range * Type.t
| List of range * t list * Type.t
S-expression annotated with location information
type 'a conv = TODO: b
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 = Pre_sexp.Annotated.stack = {
positions : pos list;
stack : t list list;
}
Stack used by annotation parsers
val get_sexp : t -> 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 -> 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.
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result
parse ?parse_pos ?len str same as parse, but returns an S-expression annotated with location information.
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, t) 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: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:Parse_pos.t -> ?buf:string -> 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:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list
input_sexps ?parse_pos ?buf ic like input_rev_sexps, but returns a list of annotated S-expressions.
val load_sexp : ?strict:bool -> ?buf:string -> string -> t
load_sexp ?strict ?buf file like load_sexp, but returns an annotated S-expression.
val load_sexps : ?buf:string -> string -> t list
load_sexps ?buf file like load_sexps, but returns a list of annotated S-expressions.
val load_rev_sexps : ?buf:string -> string -> t list
load_rev_sexps ?buf file like load_rev_sexps, but returns a list of annotated S-expressions.
val of_string : string -> t
of_string str same as of_string, but returns an annotated S-expression.
val of_bigstring : bigstring -> t
of_bigstring bstr same as of_string, but operates on bigstrings.
val conv : 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"
end
type 't parse_state = 't Pre_sexp.parse_state = {
parse_pos : Parse_pos.t; (* Current parse position *)
pstack : 't; (* Stack of found S-expression lists *)
pbuf : Buffer.t; (* Current atom buffer *)
}
Type of state maintained during parsing
type parse_error = Pre_sexp.parse_error = {
location : string; (* Function in which the parse failed *)
err_msg : string; (* Reason why parsing failed *)
parse_state : TODO: a; (* State of parser *)
}
Type of parse errors
exception Parse_error of parse_error
Exception raised during partial parsing
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result
parse ?parse_pos ?len str (partially) parses an S-expression in string buffer str starting out with position information provided in parse_pos and reading at most len characters. To parse a single atom that is not delimited by whitespace it is necessary to call this function a second time with the returned continuation, and a dummy buffer that contains whitespace.
parse starts parsing str at position parse_pos.buf_pos. Each subsequent parse_fun from a Cont uses the buf and pos that is supplied to it. The final parse_fun that returns Done mutates the buf_pos in the originally supplied parse_pos, and then returns it.
parse_pos default = Parse_pos.create ()
len default = String.length str - parse_pos.Parse_pos.buf_pos
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, t) parse_result
parse_bigstring ?parse_pos ?len str same as parse, but operates on bigstrings.
val input_sexp : ?parse_pos:Parse_pos.t -> Pervasives.in_channel -> t
input_sexp ?parse_pos ic parses an S-expression from input channel ic using initial position information in parse_pos. NOTE: this function is not as fast on files as Sexp.load_sexp, and is also slightly slower than the scan-functions. But it is guaranteed that input_sexp is only going to read data parseable as an S-expression. Thus, subsequent input functions will see the data immediately following it.
parse_pos default = Parse_pos.create ()
val input_sexps : ?parse_pos:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list
input_sexps ?parse_pos ?buf ic parses whitespace separated S-expressions from input channel ic until EOF is reached. Faster than the scan-functions.
parse_pos default = Parse_pos.create ()
val input_rev_sexps : ?parse_pos:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list
input_rev_sexps ?parse_pos ?buf ic same as Sexp.input_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.
val load_sexp : ?strict:bool -> ?buf:string -> string -> t
load_sexp ?strict ?buf file reads one S-expression from file using buffer buf for storing intermediate data. Faster than the scan-functions.
Raises Parse_error if the S-expression is unparseable.
Raises Failure if parsing reached the end of file before one S-expression could be read.
Raises Failure if strict is true and there is more than one S-expression in the file.
strict default = true
val load_sexps : ?buf:string -> string -> t list
load_sexps ?buf file reads a list of whitespace separated S-expressions from file using buffer buf for storing intermediate data. Faster than the scan-functions.
Raises Parse_error if there is unparseable data in the file.
Raises Failure if parsing reached the end of file before the last S-expression could be fully read.
val load_rev_sexps : ?buf:string -> string -> t list
load_rev_sexps ?buf file same as Sexp.load_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.
val load_sexp_conv : ?strict:bool -> ?buf:string -> string -> t -> 'a -> 'a Annotated.conv
load_sexp_conv ?strict ?buf file f like Sexp.load_sexp, but performs a conversion on the fly using f. Performance is equivalent to executing Sexp.load_sexp and performing conversion when there are no errors. In contrast to the plain S-expression loader, this function not only performs the conversion, it will give exact error ranges for conversion errors.
Raises Parse_error if there is unparseable data in the file.
Raises Failure if parsing reached the end of file before the last S-expression could be fully read.
val load_sexp_conv_exn : ?strict:bool -> ?buf:string -> string -> t -> 'a -> 'a
load_sexp_conv_exn ?strict ?buf file f like load_sexp_conv, but returns the converted value or raises Of_sexp_error with exact location information in the case of a conversion error.
val load_sexps_conv : ?buf:string -> string -> t -> 'a -> 'a Annotated.conv list
load_sexps_conv ?buf file f like Sexp.load_sexps, but performs a conversion on the fly using f. Performance is equivalent to executing Sexp.load_sexps and performing conversion when there are no errors. In contrast to the plain S-expression loader, this function not only performs the conversion, it will give exact error ranges for conversion errors.
Raises Parse_error if there is unparseable data in the file.
Raises Failure if parsing reached the end of file before the last S-expression could be fully read.
val load_sexps_conv_exn : ?buf:string -> string -> t -> 'a -> 'a list
load_sexps_conv_exn ?buf file f like load_sexps_conv, but returns the converted value or raises Of_sexp_error with exact location information in the case of a conversion error.
val output_hum : Pervasives.out_channel -> t -> unit
output_hum oc sexp outputs S-expression sexp to output channel oc in human readable form.
val output_hum_indent : int -> Pervasives.out_channel -> t -> unit
output_hum_indent indent oc sexp outputs S-expression sexp to output channel oc in human readable form using indentation level indent.
val output_mach : Pervasives.out_channel -> t -> unit
output_mach oc sexp outputs S-expression sexp to output channel oc in machine readable (i.e. most compact) form.
val output : Pervasives.out_channel -> t -> unit
output oc sexp same as output_mach.
val save_hum : ?perm:int -> string -> t -> unit
save_hum ?perm file sexp outputs S-expression sexp to file in human readable form.
perm default = umask
val save_mach : ?perm:int -> string -> t -> unit
save_mach ?perm file sexp outputs S-expression sexp to file in machine readable (i.e. most compact) form.
perm default = umask
val save : ?perm:int -> string -> t -> unit
save ?perm file sexp same as save_mach.
val save_sexps_hum : ?perm:int -> string -> t list -> unit
save_sexps_hum ?perm file sexps outputs S-expression list sexps to file in human readable form, each sexp being followed by a newline.
perm default = umask
val save_sexps_mach : ?perm:int -> string -> t list -> unit
save_sexps_mach ?perm file sexps outputs S-expression list sexps to file in machine readable form, each sexp being followed by a newline.
perm default = umask
val save_sexps : ?perm:int -> string -> t list -> unit
save_sexps ?perm file sexp same as save_sexps_mach.
val pp_hum : Format.formatter -> t -> unit
pp_hum ppf sexp outputs S-expression sexp to formatter ppf in human readable form.
val pp_hum_indent : int -> Format.formatter -> t -> unit
pp_hum_indent n ppf sexp outputs S-expression sexp to formatter ppf in human readable form and indentation level n.
val pp_mach : Format.formatter -> t -> unit
pp_mach ppf sexp outputs S-expression sexp to formatter ppf in machine readable (i.e. most compact) form.
val pp : Format.formatter -> t -> unit
pp ppf sexp same as pp_mach.
module Of_string_conv_exn : sig
Module encapsulating the exception raised by string converters when type conversions fail.
type t = {
exc : exn;
sexp : Type.t;
sub_sexp : Type.t;
}
exception E of t
end
val of_string : string -> t
of_string str converts string str to an S-expression. NOTE: trailing whitespace is considered an error, which may be overly strict for some applications. Either strip the string of trailing whitespace first, or, even cheaper, use parse instead.
val of_string_conv : string -> t -> 'a -> 'a Annotated.conv
of_string_conv str conv like of_string, but performs type conversion with conv.
Returns conversion result.
val of_string_conv_exn : string -> t -> 'a -> 'a
of_string_conv_exn str conv like of_string_conv, but raises Of_string_conv_exn.E if type conversion fails.
Returns converted value.
val of_bigstring : bigstring -> t
of_bigstring bstr same as of_string, but operates on bigstrings.
val of_bigstring_conv : bigstring -> t -> 'a -> 'a Annotated.conv
of_bigstring_conv bstr conv like of_bigstring, but performs type conversion with conv.
Returns conversion result.
val of_bigstring_conv_exn : bigstring -> t -> 'a -> 'a
of_bigstring_conv_exn bstr conv like of_bigstring_conv, but raises Of_string_conv_exn.E if type conversion fails.
Returns converted value.
val to_string_hum : ?indent:int -> t -> string
to_string_hum ?indent sexp converts S-expression sexp to a string in human readable form with indentation level indent.
indent default = !default_indent
val to_string_mach : t -> string
to_string_mach sexp converts S-expression sexp to a string in machine readable (i.e. most compact) form.
val to_string : t -> string
to_string sexp same as to_string_mach.
val to_buffer_hum : buf:Buffer.t -> ?indent:int -> t -> unit
to_buffer_hum ~buf ?indent sexp outputs the S-expression sexp converted to a string in human readable form to buffer buf.
indent default = !default_indent
val to_buffer_mach : buf:Buffer.t -> t -> unit
to_buffer_mach ~buf sexp outputs the S-expression sexp converted to a string in machine readable (i.e. most compact) form to buffer buf.
val to_buffer : buf:Buffer.t -> t -> unit
to_buffer ~buf sexp same as to_buffer_mach.
val to_buffer_gen : buf:'buffer -> add_char:'buffer -> char -> unit -> add_string:'buffer -> string -> unit -> t -> unit
to_buffer_gen ~buf ~add_char ~add_string sexp outputs the S-expression sexp converted to a string to buffer buf using the output functions add_char and add_string.
val unit : t
unit the unit-value as expressed by an S-expression.
val sexp_of_t : t -> t
sexp_of_t sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.
val t_of_sexp : t -> t
t_of_sexp sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.
type found = TODO: a
Type of successful search results. `Found means that an S-expression was found at the immediate position, and `Pos (pos, found) indicates that it was found at position pos within a structure (= S-expression list) where found describes recursively where it was found in that structure.
type search_result = TODO: a
Type of search results. `Not_found means that an S-expression was not found within another S-expression.
val search_physical : t -> contained:t -> search_result
search_physical sexp ~contained
Returns the search result indicating whether, and if, where the S-expression contained was found within S-expression sexp.
val subst_found : t -> subst:t -> found -> t
subst_found sexp ~subst found
Returns the S-expression that results from substituting subst within S-expression sexp at the location described by found.
module With_layout : sig
S-expressions annotated with relative source positions and comments
type pos = Src_pos.Relative.t = {
row : int;
col : int;
}
val sexp_of_pos : pos -> Type.t
type t =
| Atom of pos * string * string option
| List of pos * t_or_comment list * pos
S-expressions annotated with relative source positions and comments
type t_or_comment =
| Sexp of t
| Comment of comment
type comment =
| Plain_comment of pos * string
| Sexp_comment of pos * comment list * t
val sexp_of_t : t -> Type.t
val sexp_of_comment : comment -> Type.t
val sexp_of_t_or_comment : t_or_comment -> Type.t
module Forget : sig
val t : t -> Type.t
val t_or_comment : t_or_comment -> Type.t option
val t_or_comments : t_or_comment list -> Type.t list
end
module Render : sig
type 'a t
val return : 'a -> 'a t
val bind : 'a t -> 'a -> 'b t -> 'b t
val sexp : t_or_comment -> unit t
val run : char -> unit -> unit t -> unit
end
module Parser : sig
type token
val sexp : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment
val sexp_opt : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment option
val sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment list
val rev_sexps : Lexing.lexbuf -> token -> Lexing.lexbuf -> t_or_comment list
val sexps_abs : Lexing.lexbuf -> token -> Lexing.lexbuf -> Type_with_layout.Parsed.t_or_comment list
end
module Lexer : sig
val main : ?buf:Buffer.t -> Lexing.lexbuf -> Parser.token
end
end
end
module Conv : sig
type sexp_bool = bool
Dummy definitions for "optional" options, lists, and for opaque types
type 'a sexp_option = 'a option
type 'a sexp_list = 'a list
type 'a sexp_array = 'a array
type 'a sexp_opaque = 'a
type bigstring = Sexp.bigstring
type vec = float64_vec
type mat = float64_mat
val default_string_of_float : float -> string Pervasives.ref
default_string_of_float reference to the default function used to convert floats to strings.
Initially set to fun n -> sprintf "%.20G" n.
val write_old_option_format : bool Pervasives.ref
write_old_option_format reference for the default option format used to write option values. If set to true, the old-style option format will be used, the new-style one otherwise.
Initially set to true.
val read_old_option_format : bool Pervasives.ref
read_old_option_format reference for the default option format used to read option values. Of_sexp_error will be raised with old-style option values if this reference is set to false. Reading new-style option values is always supported. Using a global reference instead of changing the converter calling conventions is the only way to avoid breaking old code with the standard macros.
Initially set to true.
val list_map : 'a -> 'b -> 'a list -> 'b list
We re-export a tail recursive map function, because some modules override the standard library functions (e.g. StdLabels) which wrecks havoc with the camlp4 extension.
val sexp_of_unit : unit -> Sexp.t
sexp_of_unit () converts a value of type unit to an S-expression.
val sexp_of_bool : bool -> Sexp.t
sexp_of_bool b converts the value x of type bool to an S-expression.
val sexp_of_string : string -> Sexp.t
sexp_of_bool str converts the value str of type string to an S-expression.
val sexp_of_char : char -> Sexp.t
sexp_of_char c converts the value c of type char to an S-expression.
val sexp_of_int : int -> Sexp.t
sexp_of_int n converts the value n of type int to an S-expression.
val sexp_of_float : float -> Sexp.t
sexp_of_float n converts the value n of type float to an S-expression.
val sexp_of_int32 : int32 -> Sexp.t
sexp_of_int32 n converts the value n of type int32 to an S-expression.
val sexp_of_int64 : int64 -> Sexp.t
sexp_of_int64 n converts the value n of type int64 to an S-expression.
val sexp_of_nativeint : nativeint -> Sexp.t
sexp_of_nativeint n converts the value n of type nativeint to an S-expression.
val sexp_of_ref : 'a -> Sexp.t -> 'a Pervasives.ref -> Sexp.t
sexp_of_ref conv r converts the value r of type 'a ref to an S-expression. Uses conv to convert values of type 'a to an S-expression.
val sexp_of_lazy_t : 'a -> Sexp.t -> 'a lazy_t -> Sexp.t
sexp_of_lazy_t conv l converts the value l of type 'a lazy_t to an S-expression. Uses conv to convert values of type 'a to an S-expression.
val sexp_of_option : 'a -> Sexp.t -> 'a option -> Sexp.t
sexp_of_option conv opt converts the value opt of type 'a option to an S-expression. Uses conv to convert values of type 'a to an S-expression.
val sexp_of_pair : 'a -> Sexp.t -> 'b -> Sexp.t -> ('a * 'b) -> Sexp.t
sexp_of_pair conv1 conv2 pair converts a pair to an S-expression. It uses its first argument to convert the first element of the pair, and its second argument to convert the second element of the pair.
val sexp_of_triple : 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> ('a * 'b * 'c) -> Sexp.t
sexp_of_triple conv1 conv2 conv3 triple converts a triple to an S-expression using conv1, conv2, and conv3 to convert its elements.
val sexp_of_list : 'a -> Sexp.t -> 'a list -> Sexp.t
sexp_of_list conv lst converts the value lst of type 'a list to an S-expression. Uses conv to convert values of type 'a to an S-expression.
val sexp_of_array : 'a -> Sexp.t -> 'a array -> Sexp.t
sexp_of_array conv ar converts the value ar of type 'a array to an S-expression. Uses conv to convert values of type 'a to an S-expression.
val sexp_of_hashtbl : 'a -> Sexp.t -> 'b -> Sexp.t -> ('a, 'b) Hashtbl.t -> Sexp.t
sexp_of_hashtbl conv_key conv_value htbl converts the value htbl of type ('a, 'b) Hashtbl.t to an S-expression. Uses conv_key to convert the hashtable keys of type 'a, and conv_value to convert hashtable values of type 'b to S-expressions.
val sexp_of_bigstring : bigstring -> Sexp.t
sexp_of_bigstring bstr converts a bigstring (character bigarray in C-layout) to an S-expression.
val sexp_of_float32_vec : float32_vec -> Sexp.t
sexp_of_float32_vec vec converts the one-dimensional bigarray vec of 32-bit floats in Fortran-layout to an S-expression.
val sexp_of_float64_vec : float64_vec -> Sexp.t
sexp_of_float64_vec vec converts the one-dimensional bigarray vec of 64-bit floats in Fortran-layout to an S-expression.
val sexp_of_vec : vec -> Sexp.t
sexp_of_vec vec same as Conv.sexp_of_float64_vec.
val sexp_of_float32_mat : float32_mat -> Sexp.t
sexp_of_float32_mat mat converts the two-dimensional bigarray mat of 32-bit floats in Fortran-layout to an S-expression.
val sexp_of_float64_mat : float64_mat -> Sexp.t
sexp_of_float64_mat mat converts the two-dimensional bigarray mat of 64-bit floats in Fortran-layout to an S-expression.
val sexp_of_mat : mat -> Sexp.t
sexp_of_mat mat same as Conv.sexp_of_float64_mat.
val sexp_of_opaque : 'a -> Sexp.t
sexp_of_opaque x converts the value x of opaque type to an S-expression. This means the user need not provide converters, but the result cannot be interpreted.
val sexp_of_fun : 'a -> 'b -> Sexp.t
sexp_of_fun f converts the value f of function type to a dummy S-expression. Functions cannot be serialized as S-expressions, but at least a placeholder can be generated for pretty-printing.
val string_of__of__sexp_of : 'a -> Sexp.t -> 'a -> string
string_of__of__sexp_of conv x converts the OCaml-value x to an S-expression represented as a string by using conversion function conv.
exception Of_sexp_error of exn * Sexp.t
Of_sexp_error (exn, sexp) the exception raised when an S-expression could not be successfully converted to an OCaml-value.
val record_check_extra_fields : bool Pervasives.ref
record_check_extra_fields checks for extra (= unknown) fields in record S-expressions.
val of_sexp_error : string -> Sexp.t -> 'a
of_sexp_error reason sexp
Raises Of_sexp_error (Failure reason, sexp).
val of_sexp_error_exn : exn -> Sexp.t -> 'a
of_sexp_error exc sexp
Raises Of_sexp_error (exc, sexp).
val unit_of_sexp : Sexp.t -> unit
unit_of_sexp sexp converts S-expression sexp to a value of type unit.
val bool_of_sexp : Sexp.t -> bool
bool_of_sexp sexp converts S-expression sexp to a value of type bool.
val string_of_sexp : Sexp.t -> string
string_of_sexp sexp converts S-expression sexp to a value of type string.
val char_of_sexp : Sexp.t -> char
char_of_sexp sexp converts S-expression sexp to a value of type char.
val int_of_sexp : Sexp.t -> int
int_of_sexp sexp converts S-expression sexp to a value of type int.
val float_of_sexp : Sexp.t -> float
float_of_sexp sexp converts S-expression sexp to a value of type float.
val int32_of_sexp : Sexp.t -> int32
int32_of_sexp sexp converts S-expression sexp to a value of type int32.
val int64_of_sexp : Sexp.t -> int64
int64_of_sexp sexp converts S-expression sexp to a value of type int64.
val nativeint_of_sexp : Sexp.t -> nativeint
nativeint_of_sexp sexp converts S-expression sexp to a value of type nativeint.
val ref_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a Pervasives.ref
ref_of_sexp conv sexp converts S-expression sexp to a value of type 'a ref using conversion function conv, which converts an S-expression to a value of type 'a.
val lazy_t_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a lazy_t
lazy_t_of_sexp conv sexp converts S-expression sexp to a value of type 'a lazy_t using conversion function conv, which converts an S-expression to a value of type 'a.
val option_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a option
option_of_sexp conv sexp converts S-expression sexp to a value of type 'a option using conversion function conv, which converts an S-expression to a value of type 'a.
val pair_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'b -> Sexp.t -> ('a * 'b)
pair_of_sexp conv1 conv2 sexp converts S-expression sexp to a pair of type 'a * 'b using conversion functions conv1 and conv2, which convert S-expressions to values of type 'a and 'b respectively.
val triple_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> ('a * 'b * 'c)
triple_of_sexp conv1 conv2 conv3 sexp converts S-expression sexp to a triple of type 'a * 'b * 'c using conversion functions conv1, conv2, and conv3, which convert S-expressions to values of type 'a, 'b, and 'c respectively.
val list_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a list
list_of_sexp conv sexp converts S-expression sexp to a value of type 'a list using conversion function conv, which converts an S-expression to a value of type 'a.
val array_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a array
array_of_sexp conv sexp converts S-expression sexp to a value of type 'a array using conversion function conv, which converts an S-expression to a value of type 'a.
val hashtbl_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'b -> Sexp.t -> ('a, 'b) Hashtbl.t
hashtbl_of_sexp conv_key conv_value sexp converts S-expression sexp to a value of type ('a, 'b) Hashtbl.t using conversion function conv_key, which converts an S-expression to hashtable key of type 'a, and function conv_value, which converts an S-expression to hashtable value of type 'b.
val bigstring_of_sexp : Sexp.t -> bigstring
bigstring_of_sexp sexp converts S-expression sexp to a bigstring (character bigarray in C-layout).
val float32_vec_of_sexp : Sexp.t -> float32_vec
float32_vec_of_sexp sexp converts S-expression sexp to a one-dimensional bigarray of 32-bit floats in Fortran-layout.
val float64_vec_of_sexp : Sexp.t -> float64_vec
float64_vec_of_sexp sexp converts S-expression sexp to a one-dimensional bigarray of 64-bit floats in Fortran-layout.
val vec_of_sexp : Sexp.t -> vec
vec_of_sexp sexp same as float64_vec_of_sexp.
val float32_mat_of_sexp : Sexp.t -> float32_mat
float32_mat_of_sexp sexp converts S-expression sexp to a two-dimensional bigarray of 32-bit floats in Fortran-layout.
val float64_mat_of_sexp : Sexp.t -> float64_mat
float64_mat_of_sexp sexp converts S-expression sexp to a two-dimensional bigarray of 64-bit floats in Fortran-layout.
val mat_of_sexp : Sexp.t -> mat
mat_of_sexp sexp same as Conv.float64_mat_of_sexp.
val opaque_of_sexp : Sexp.t -> 'a
opaque_of_sexp sexp
Raises Of_sexp_error when attempting to convert an S-expression to an opaque value.
val fun_of_sexp : Sexp.t -> 'a
fun_of_sexp sexp
Raises Of_sexp_error when attempting to convert an S-expression to a function.
val of_string__of__of_sexp : Sexp.t -> 'a -> string -> 'a
of_string__of__of_sexp conv str converts the S-expression str represented as a string to an OCaml-value by using conversion function conv.
val sexp_of_exn : exn -> Sexp.t
sexp_of_exn exc converts exception exc to an S-expression. If no suitable converter is found, the standard converter in Printexc will be used to generate an atomic S-expression.
val sexp_of_exn_opt : exn -> Sexp.t option
sexp_of_exn_opt exc converts exception exc to Some sexp. If no suitable converter is found, None is returned instead.
module Exn_converter : sig
type t
Type of handles for exception S-expression converters
val set_max_exn_tags : int -> unit
set_max_exn_tags n sets the maximum number of converters for exceptions with the same template to n. If already existing handlers exceed this number, they will remain at their current number until this number is reduced due to garbage collection. New handlers will not be added until n will not be exceeded.
val get_max_exn_tags : unit -> int
set_max_exn_tags () return the maximum number of converters for exceptions with the same template.
val add_auto : ?finalise:bool -> exn -> exn -> Sexp.t -> unit
add_auto ?finalise templ sexp_of_exn registers exception S-expression converter sexp_of_exn for exceptions having same constructor as template templ, unless the number of stored handlers for the given template exceeds get_max_exn_tags (), in which case the handler will never be called. When sexp_of_exn is called, the passed exception is guaranteed to match the template.
NOTE: if the exception belongs to a transient module, e.g. local modules (including functor instantiations), first-class modules, etc., a manually written sexp_of_exn must use Obj.magic internally to avoid matching or creating the exception, otherwise the handler can never be reclaimed once the exception ceases to exist. If finalise is true, then the exception will be automatically registered for removal with the GC (default). Finalisation will not work with exceptions that have been allocated outside the heap, which is the case for some standard ones e.g. Sys_error.
NOTE: Use with great caution, this function is primarily intended for automated use! If unsure, use add_slow instead.
finalise default = true
val add_slow : exn -> Sexp.t option -> t
add_slow sexp_of_exn registers exception S-expression converter sexp_of_exn and returns a handle. Exception converters registered this way are much slower than with add, but this function does not require an exception template. NOTE: if you call this function explicitly, or the "sexp"-macro for exceptions from within local modules, you will eventually have to unregister it manually with del, otherwise there is a space leak!
val del_slow : t -> unit
del_slow handle unregisters exception S-expression converter with handle handle. In multi-threaded contexts it is not guaranteed that the unregistered converter will not be called after this function returns.
end
end
module Conv_error : sig
val tuple_of_size_n_expected : string -> int -> Sexp.t -> 'a
val stag_no_args : string -> Sexp.t -> 'a
val stag_incorrect_n_args : string -> string -> Sexp.t -> 'a
val stag_takes_args : string -> Sexp.t -> 'a
val nested_list_invalid_sum : string -> Sexp.t -> 'a
val empty_list_invalid_sum : string -> Sexp.t -> 'a
val unexpected_stag : string -> Sexp.t -> 'a
val record_only_pairs_expected : string -> Sexp.t -> 'a
val record_superfluous_fields : what:string -> loc:string -> string list -> Sexp.t -> 'a
val record_duplicate_fields : string -> string list -> Sexp.t -> 'a
val record_extra_fields : string -> string list -> Sexp.t -> 'a
val record_get_undefined_loop : string list -> (bool * string) list -> string
val record_undefined_elements : string -> Sexp.t -> (bool * string) list -> 'a
val record_list_instead_atom : string -> Sexp.t -> 'a
val record_poly_field_value : string -> Sexp.t -> 'a
exception No_variant_match of string * Sexp.t
val no_variant_match : string -> Sexp.t -> 'a
val no_matching_variant_found : string -> Sexp.t -> 'a
val ptag_no_args : string -> Sexp.t -> 'a
val ptag_incorrect_n_args : string -> string -> Sexp.t -> 'a
val ptag_takes_args : string -> Sexp.t -> 'a
val nested_list_invalid_poly_var : string -> Sexp.t -> 'a
val empty_list_invalid_poly_var : string -> Sexp.t -> 'a
val silly_type : string -> Sexp.t -> 'a
val empty_type : string -> Sexp.t -> 'a
end
module Exn_magic : sig
val register : exn -> string -> unit
val register1 : 'a -> exn -> string -> 'a -> Sexp.t -> unit
val register2 : 'a -> 'b -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> unit
val register3 : 'a -> 'b -> 'c -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> unit
val register4 : 'a -> 'b -> 'c -> 'd -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> unit
val register5 : 'a -> 'b -> 'c -> 'd -> 'e -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> 'e -> Sexp.t -> unit
val register6 : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> 'e -> Sexp.t -> 'f -> Sexp.t -> unit
val register7 : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> 'e -> Sexp.t -> 'f -> Sexp.t -> 'g -> Sexp.t -> unit
val register8 : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> 'e -> Sexp.t -> 'f -> Sexp.t -> 'g -> Sexp.t -> 'h -> Sexp.t -> unit
val register9 : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> 'e -> Sexp.t -> 'f -> Sexp.t -> 'g -> Sexp.t -> 'h -> Sexp.t -> 'i -> Sexp.t -> unit
val register10 : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> exn -> string -> 'a -> Sexp.t -> 'b -> Sexp.t -> 'c -> Sexp.t -> 'd -> Sexp.t -> 'e -> Sexp.t -> 'f -> Sexp.t -> 'g -> Sexp.t -> 'h -> Sexp.t -> 'i -> Sexp.t -> 'j -> Sexp.t -> unit
end
module Macro : sig
type 'a conv = TODO: b
type 'a annot_conv = 'a Sexp.Annotated.conv
val load_sexp : string -> Sexp.t
load_sexp file like {!Sexp.load_sexp} file, but resolves the macros contained in file.
val load_sexps : string -> Sexp.t list
load_sexps file like {!Sexp.load_sexps} file, but resolves the macros contained in file.
val load_sexp_conv : string -> Sexp.t -> 'a -> 'a annot_conv
load_sexp_conv file f uses load_sexp and converts the result using f.
val load_sexps_conv : string -> Sexp.t -> 'a -> 'a annot_conv list
load_sexps_conv file f uses load_sexps and converts the result using f.
val load_sexp_conv_exn : string -> Sexp.t -> 'a -> 'a
load_sexp_conv_exn file f like load_sexp_conv, but raises an exception in case of conversion error.
val load_sexps_conv_exn : string -> Sexp.t -> 'a -> 'a list
load_sexps_conv_exn file f like load_sexps_conv, but raises an exception in case of conversion error.
val expand_local_macros : Sexp.t list -> Sexp.t list conv
expand_local_macros sexps takes a list of sexps and performs macro-expansion on them, except that an error will be returned if an :include macro is found.
module type Sexp_loader = sig
A version of load_sexps that is functorized with respect to the functions that load the sexps from files and the corresponding monad.
module Monad : sig
type 'a t
val return : 'a -> 'a t
module Monad_infix : sig
val (>>=) : 'a t -> 'a -> 'b t -> 'b t
end
module List : sig
val iter : 'a list -> f:'a -> unit t -> unit t
val map : 'a list -> f:'a -> 'b t -> 'b list t
end
end
val load_sexps : string -> Sexp.t list Monad.t
val load_annotated_sexps : string -> Sexp.Annotated.t list Monad.t
end
TODO: functor:sexplib.111.25.00/sexplib/Sexplib.Macro.Loader
val add_error_location : string -> exn -> exn
end
module Path : sig
type el =
| Pos of int (* Pos n denotes nth element in a tuple *)
| Match of string * int (* Match (tag, n) denotes nth argument of sum matching tag *)
| Rec of string (* Rec name denotes the record field having name *)
Type of substitution elements
type t = el list
Type of substitution paths
val parse : string -> t
parse str
Returns a substitution path represented by string str.
Syntax:
"." -> separates path elements; must be present at start of string.
"[4]" -> specifies the 4th element in a tuple.
"some_tag[4]" -> tries to match some_tag, then denotes its 4th argument.
"name" -> denotes record field having name
Example from test code:
".t.x.B1" -> choose record field with name t, then subfield x. Match this value against B, and denote its first argument.
Raises Failure if the path is syntactically invalid.
val get : ?path:t -> ?str:string -> Sexp.t -> Sexp.t
get ?path ?str sexp if path is provided, use it as path. Otherwise, if str is provided, parse it as a path. If neither is provided, assume an empty path.
Returns the sub-expression from S-expression sexp denoted by the path.
Raises Failure if path is syntactically invalid or if the path structure clashes with the structure of the data.
val replace : ?path:t -> ?str:string -> Sexp.t -> subst:Sexp.t -> Sexp.t
replace ?path ?str sexp ~subst like get, but does not extract a sub-expression but substitutes it with subst.
Returns resulting S-expression.
Raises Failure if path is syntactically invalid or if the path structure clashes with the structure of the data.
val replace_no_path : str:string -> Sexp.t -> subst:Sexp.t -> Sexp.t
replace_no_path ~str sexp ~subst like replace, but does not take optional arguments. str must be specified.
Raises Failure if path is syntactically invalid or if the path structure clashes with the structure of the data.
val subst_path : Sexp.t -> t -> (Sexp.t -> Sexp.t * Sexp.t)
subst_path sexp path
Returns the tuple (subst, sub), where subst is a function that returns an S-expression in which the subexpression denoted by path in sexp has been substituted by its argument. sub is the denoted subexpression. Note that subst sub = sexp.
Raises Failure if path is syntactically invalid or if the path structure clashes with the structure of the data.
val extract_pos : int -> Sexp.t -> (Sexp.t option -> Sexp.t * Sexp.t)
extract_pos n sexp
Returns the tuple (subst, sub), where subst is a function that returns an S-expression in which the subexpression denoted at position n in sexp, which must be a list, has been substituted by value if the optional argument is Some value, or removes the denoted subexpression if the optional argument is None. sub is the denoted subexpression. Note that subst (Some sub) = sexp.
Raises Failure if the position cannot be resolved within the given S-expression.
val extract_match : string -> int -> Sexp.t -> (Sexp.t option -> Sexp.t * Sexp.t)
extract_match tag n sexp
Returns the tuple (subst, sub), where subst is a function that returns an S-expression in which the subexpression denoted by matching tag and taking its nth argument in sexp has been substituted by value if the argument is Some value, or removes the denoted subexpression if the optional argument is None. sub is the denoted subexpression. Note that subst (Some sub) = sexp.
Raises Failure if the S-expression does not represent a sum tag.
val extract_rec : string -> Sexp.t -> (Sexp.t -> Sexp.t * Sexp.t)
extract_rec name sexp
Returns the tuple (subst, sub), where subst is a function that returns an S-expression in which the subexpression denoted by matching field name name in sexp has been substituted by its argument. sub is the denoted subexpression. Note that subst (Some sub) = sexp.
Raises Failure if the S-expression does not represent a record.
end
module Std : sig
module Hashtbl : sig
type ('a, 'b) t = ('a, 'b) Hashtbl.t
val create : ?random:bool -> int -> ('a, 'b) t
val clear : ('a, 'b) t -> unit
val reset : ('a, 'b) t -> unit
val copy : ('a, 'b) t -> ('a, 'b) t
val add : ('a, 'b) t -> 'a -> 'b -> unit
val find : ('a, 'b) t -> 'a -> 'b
val find_all : ('a, 'b) t -> 'a -> 'b list
val mem : ('a, 'b) t -> 'a -> bool
val remove : ('a, 'b) t -> 'a -> unit
val replace : ('a, 'b) t -> 'a -> 'b -> unit
val iter : 'a -> 'b -> unit -> ('a, 'b) t -> unit
val fold : 'a -> 'b -> 'c -> 'c -> ('a, 'b) t -> 'c -> 'c
val length : ('a, 'b) t -> int
val randomize : unit -> unit
type statistics = Hashtbl.statistics = {
num_bindings : int;
num_buckets : int;
max_bucket_length : int;
bucket_histogram : int array;
}
val stats : ('a, 'b) t -> statistics
module type HashedType = sig
type t
val equal : t -> t -> bool
val hash : t -> int
end
module type S = sig
type key
type 'a t
val create : int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : key -> 'a -> unit -> 'a t -> unit
val fold : key -> 'a -> 'b -> 'b -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats : 'a t -> statistics
end
module Make = Hashtbl.Make
module type SeededHashedType = sig
type t
val equal : t -> t -> bool
val hash : int -> t -> int
end
module type SeededS = sig
type key
type 'a t
val create : ?random:bool -> int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : key -> 'a -> unit -> 'a t -> unit
val fold : key -> 'a -> 'b -> 'b -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats : 'a t -> statistics
end
module MakeSeeded = Hashtbl.MakeSeeded
val hash : 'a -> int
val seeded_hash : int -> 'a -> int
val hash_param : int -> int -> 'a -> int
val seeded_hash_param : int -> int -> int -> 'a -> int
val sexp_of_t : 'a -> Sexp.t -> 'b -> Sexp.t -> ('a, 'b) Hashtbl.t -> Sexp.t
val t_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'b -> Sexp.t -> ('a, 'b) Hashtbl.t
end
module Lazy : sig
type 'a t = 'a lazy_t
exception Undefined
val force : 'a t -> 'a
val force_val : 'a t -> 'a
val from_fun : unit -> 'a -> 'a t
val from_val : 'a -> 'a t
val is_val : 'a t -> bool
val lazy_from_fun : unit -> 'a -> 'a t
val lazy_from_val : 'a -> 'a t
val lazy_is_val : 'a t -> bool
val t_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a lazy_t
val sexp_of_t : 'a -> Sexp.t -> 'a lazy_t -> Sexp.t
end
module Sexp_macro = Macro
val sexp_of_unit : unit -> Sexp.t
val unit_of_sexp : Sexp.t -> unit
val sexp_of_bool : bool -> Sexp.t
val bool_of_sexp : Sexp.t -> bool
val sexp_of_string : string -> Sexp.t
val string_of_sexp : Sexp.t -> string
val sexp_of_char : char -> Sexp.t
val char_of_sexp : Sexp.t -> char
val sexp_of_int : int -> Sexp.t
val int_of_sexp : Sexp.t -> int
val sexp_of_float : float -> Sexp.t
val float_of_sexp : Sexp.t -> float
val sexp_of_int32 : int32 -> Sexp.t
val int32_of_sexp : Sexp.t -> int32
val sexp_of_int64 : int64 -> Sexp.t
val int64_of_sexp : Sexp.t -> int64
val sexp_of_nativeint : nativeint -> Sexp.t
val nativeint_of_sexp : Sexp.t -> nativeint
val sexp_of_ref : 'a -> Sexp.t -> 'a Pervasives.ref -> Sexp.t
val ref_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a Pervasives.ref
val sexp_of_lazy_t : 'a -> Sexp.t -> 'a lazy_t -> Sexp.t
val lazy_t_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a lazy_t
val sexp_of_option : 'a -> Sexp.t -> 'a option -> Sexp.t
val option_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a option
val sexp_of_list : 'a -> Sexp.t -> 'a list -> Sexp.t
val list_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a list
val sexp_of_array : 'a -> Sexp.t -> 'a array -> Sexp.t
val array_of_sexp : Sexp.t -> 'a -> Sexp.t -> 'a array
val sexp_of_exn : exn -> Sexp.t
end