Library
Module
Module type
Parameter
Class
Class type
type error =
| Decoder_error of string * Sexplib0.Sexp.t option
| Decoder_errors of error list
| Decoder_tag of string * error
type 'a t = Sexplib0.Sexp.t -> ('a, error) Spin_std.Result.t
Error handling
val pp_error : Format.formatter -> error -> unit
Pretty-print an error
.
val string_of_error : error -> string
Convert an error
to a string
.
Loading s-expressions
val of_string : string -> (Sexplib0.Sexp.t, error) Spin_std.Result.t
Load an s-expression from a string.
val of_sexps_string : string -> (Sexplib0.Sexp.t, error) Spin_std.Result.t
Load a list of s-expression from a string.
val of_file : string -> (Sexplib0.Sexp.t, error) Spin_std.Result.t
Load an s-expression from a file.
val of_sexps_file : string -> (Sexplib0.Sexp.t, error) Spin_std.Result.t
Load a list of s-expression from a file.
Decoding primitives
val string : string t
Decode a string
.
val int : int t
Decode an int
.
val float : float t
Decode a float
.
val bool : bool t
Decode a bool
.
val null : unit t
Decode a null
.
Helpers
val string_matching : regex:string -> err:string -> string t
Decoding lists
Decoding records
Decode a record from the field with the given name.
This will fail with an error if the field could not be found. It will also fail if several fields exist with the same name. Use fields
if you want to decode a list of fields.
Decode a list of record from the fields with the given name.
It returns an empty list if no fields with the given name exist.
Decode a record from the field with the given name.
This will return None
if the field could not be found. It will fail if several fields exist with the same name. Use fields
if you want to decode a list of fields.
Inconsistent structure
Try a sequence of different decoders and return an error if none of them worked.
Monadic operations
val return : 'a -> 'a t
Lift decoder from a value.
Try two decoders and then combine the Result.t. We can use this to decode objects with many fields
module Infix : sig ... end
module Syntax : sig ... end
Running decoders
val decode_sexp : Sexplib0.Sexp.t -> 'a t -> ('a, error) Spin_std.Result.t
Run a decoder on some input.
val decode_string : string -> 'a t -> ('a, error) Spin_std.Result.t
Run a decoder on a string.
val decode_sexps_string : string -> 'a t -> ('a, error) Spin_std.Result.t
Run a decoder on a string containing a list of s-expression.
val decode_file : string -> 'a t -> ('a, error) Spin_std.Result.t
Run a decoder on a file.
val decode_sexps_file : string -> 'a t -> ('a, error) Spin_std.Result.t
Run a decoder on a file containing a list of s-expression.