package b0

  1. Overview
  2. Docs

Textual codecs

Textual encoders and decoders

type 'a enc = Format.formatter -> 'a -> unit

The type for textual encoders. enc ppf v textually encodes the value v on ppf. Raises Error in case of error.

type 'a dec = string -> start:int -> int * 'a

The type for textual decoders. dec s ~start textually decodes a value at start in s. start is either the first textual input bytes to consider (which may be whitespace or a commenet) or the length of s. The function returns (i, v) with v the decoded value and i the first index after the decoded value or the lenght of s if there is no such index. Raises Error 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, Format.formatter, unit, 'b) format4 -> 'a

enc_err ~kind fmt raises a textual encoding error message for kind kind formatted according to fmt.

val enc_atom : string enc

enc_atom ppf s encodes s as an atom on ppf quoting it as needed.

val enc_list : 'a enc -> 'a list enc

enc_list enc_v encodes a list of values encoded with enc_v.

Decoding

type lexeme = [
  1. | `Ls
  2. | `Le
  3. | `Atom of string
]

The type for s-expressions lexemes.

val dec_err : kind:string -> int -> ('a, Format.formatter, unit, 'b) format4 -> 'a

dec_err ~kind i fmt raises a textual decoding error message for kind kind at input byte index i formatted according to fmt.

val dec_err_eoi : kind:string -> int -> 'a

dec_err_eoi ~kind i raises a textual error message for kind kind at input byte index i 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 kind kind at input byte index i indicating one of exp 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 kind kind at input byte index i and atom a indicating one of exp atoms was expected.

val dec_skip : kind:string -> string -> start:int -> int

dec_skip ~kind s ~start starting at start (which can be out of bounds) is the first non-white, non-comment, byte index or the length of s if there is no such index.

val dec_lexeme : kind:string -> (int * lexeme) dec

dec_case ~kind s ~start starting at start (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 at start (which can be out of bounds), skips whitespace and comments, parses a list start and returns the index after it or the length of s.

val dec_le : kind:string -> string -> start:int -> int

dec_le ~kind s ~start starting at start (which can be out of bounds), skips whitespace and comments, parses a list end and returns the index after it or the length of s.

val dec_atom : kind:string -> string dec

dec_atom ~kind s ~start starting at start (which can be out of bounds), skips whitespace and comments, parses an atom and returns the index after it or the length of s.

val dec_list : 'a dec -> kind:string -> 'a list dec

dec_list dec_v ~kind decodes a list of values decoded with dec_v for the given kind.

val dec_list_tail : 'a dec -> kind:string -> ls:int -> 'a list dec

dec_list_tail dec_v ~kind ~lstart decodes list elements decoded with dec_v and an the end of list for the given kind, ls is the position of the list start.

OCaml

Innovation. Community. Security.