Module Conv.Txt
Textual codecs
Textual encoders and decoders
type 'a enc
= Stdlib.Format.formatter -> 'a -> unit
The type for textual encoders.
enc ppf v
textually encodes the valuev
onppf
. RaisesError
in case of error.
type 'a dec
= string -> start:int -> int * 'a
The type for textual decoders.
dec s ~start
textually decodes a value atstart
ins
.start
is either the first textual input bytes to consider (which may be whitespace or a commenet) or the length ofs
. The function returns(i, v)
withv
the decoded value andi
the first index after the decoded value or the lenght ofs
if there is no such index. RaisesError
in case of error.XXX. In the end this signature is showing its limits for error reporting. Maybe we should have an abstraction here.
Encoding
val enc_err : kind:string -> ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'a
enc_err ~kind fmt
raises a textual encoding error message for kindkind
formatted according tofmt
.
Decoding
val dec_err : kind:string -> int -> ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'a
dec_err ~kind i fmt
raises a textual decoding error message for kindkind
at input byte indexi
formatted according tofmt
.
val dec_err_eoi : kind:string -> int -> 'a
dec_err_eoi ~kind i
raises a textual error message for kindkind
at input byte indexi
indicating an unexpected end of input.
val dec_err_lexeme : kind:string -> int -> lexeme -> exp:lexeme list -> 'a
dec_err_case ~kind i
raises a textual error message for kindkind
at input byte indexi
indicating one ofexp
was expected.
val dec_err_atom : kind:string -> int -> string -> exp:string list -> 'a
dec_err_atom ~kind i a exp
raises a textual error message for kindkind
at input byte indexi
and atoma
indicating one ofexp
atoms was expected.
val dec_skip : kind:string -> string -> start:int -> int
dec_skip ~kind s ~start
starting atstart
(which can be out of bounds) is the first non-white, non-comment, byte index or the length ofs
if there is no such index.
val dec_lexeme : kind:string -> (int * lexeme) dec
dec_case ~kind s ~start
starting atstart
(which can be out of bounds), skips whitespace and comment, looks for either a left parenthesis, right parenthesis or an atom and returns the index of their first position. Errors if end of input is is found.
val dec_ls : kind:string -> string -> start:int -> int
dec_ls ~kind s ~start
starting atstart
(which can be out of bounds), skips whitespace and comments, parses a list start and returns the index after it or the length ofs
.
val dec_le : kind:string -> string -> start:int -> int
dec_le ~kind s ~start
starting atstart
(which can be out of bounds), skips whitespace and comments, parses a list end and returns the index after it or the length ofs
.
val dec_atom : kind:string -> string dec
dec_atom ~kind s ~start
starting atstart
(which can be out of bounds), skips whitespace and comments, parses an atom and returns the index after it or the length ofs
.