package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0
doc/b0.std/B0_sexp/Sexp/index.html
Module B0_sexp.Sexp
Source
S-expression definitions and codec.
Meta information
The type for formatting functions.
The type for source text locations.
loc_nil
is a source text location for non-parsed s-expressions.
The type for meta information about atoms.
The type for meta information about lists.
S-expressions
The type for generic s-expression representations. Either an atom or a list.
Accessors
to_atom s
extracts an atom from s
. If s
is a list an error with the location formatted according to Tloc.pp
is returned.
get_atom s
is like to_atom
but raises Invalid_argument
if s
is not an atom.
to_list s
extracts a list from s
. If s
is an atom an error with the location formatted according to Tloc.pp
is returned.
get_atom s
is like to_list
but raises Invalid_argument
if s
is not an list.
to_splice s
is the either the list of s
if s
is or or [s]
if s
is an atom.
Formatting
pp_seq
formats an s-expression but if it is a list the outer list separators are not formatted in the output.
Warning. Assumes all OCaml strings in the formatted value are UTF-8 encoded.
Codec
The type for kinds of decoding error.
pp_error_kind ()
formats an error kind.
The type for decoding errors.
val pp_error :
?pp_loc:loc fmt ->
?pp_error_kind:error_kind fmt ->
?pp_prefix:unit fmt ->
unit ->
error fmt
pp_error ~pp_loc ~pp_error_kind ~pp_prefix ()
formats errors using pp_loc
(defaults to pp_loc
), pp_error_kind
(defaults to pp_error_kind
) and pp_prefix
(defaults formats "Error: "
).
error_to_string r
converts an error to a string using pp_error
(defaults to pp_error
).
seq_of_string ?file s
parses a sequence of s-expressions from s
. file
is the file for locations, defaults to "-"
. The sequence is returned as a fake s-expression list that spans from the start of the first s-expression in s
to the end of the last one; note that this list does not exist syntactically in s
.
If there are no s-expression in s
the list is empty its location has both start and end positions at byte 0
(which may not exist).
Note. All OCaml strings returned by this function are UTF-8 encoded.
val seq_of_string' :
?pp_error:error fmt ->
?file:B0_text.Tloc.fpath ->
string ->
(t, string) result
seq_of_string'
s seq_of_string
composed with error_to_string
.
seq_to_string s
encodes s
to a sequence of s-expressions. If s
is an s-expression list this wrapping list is not syntactically represented in the output (see also seq_of_string
), use to_string (list [l])
if you want to output l
as a list.
Warning. Assumes all OCaml strings in s
are UTF-8 encoded.
S-expression indices
The type for s-expression indexing operations.
Nth n
, lookup zero-based elementn
in a list. Ifn
is negative, counts the number of elements from the end of the list, i.e.-1
is the last list element.Key k
, lookup bindingk
in an s-expression dictionary.
pp_key
formats a key, this is Format.pp_print_string
.
pp_index
formats indices. Keys are unbracketed and formatted with pp_key
, defaults to pp_key
.
S-expression paths
path_of_string
parses a path from s
according to the syntax given here.
pp_path ?pp_key ()
is a formatter for paths using pp_key
to format keys (defaults to pp_key
).
Carets
The type for caret locations.
The type for carets. A caret location and the path at which it applies.
caret_of_string s
parses a caret from s
according to the syntax given here.