The type for result paths. This is a sequence of indexing operations tupled with the source text location of the indexed s-expression in reverse order.
query_at_path q (s, p) is like query except it assumes s is at path p. Use to further query s-expressions obtained with sexp_with_path so that errors return the full path to errors.
val atom_to : kind:string ->(string ->('a, string)result)->'at
atom_to ~kind p queries an atom and parses it with p. In case of Error m fails with message m. kind is the kind of value parsed, used for the error in case a list is found.
TODO. Maybe combinators to devise an approriate parse function for atom_to are a better idea than the following two combinators.
enum_map ~pp_elt ~kind sm queries an atom for it's map in sm and fails if the atom is not bound in sm. kind is for the kind of elements in sm, it used for error reporting.
nth ?absent n q queries the nth index of a list with q. If n is negative counts from the end of the list, so -1 is the last list element. If the element does not exist this fails if absent is None and succeeds with v if absent is Some
v.
delete_nth ~must_exist n deletes the nth element of the list. If the element does not exist this fails when must_exist is true or returns the list unchanged when must_exist is false.
Dictionary queries
Queries for s-expression dictionaries. These queries fail on atoms.
key ?absent k q queries the value of key k of a dictionary with q. If k is not bound this fails if absent is None and succeeds with v if absent is Some v.
val delete_key : must_exist:bool ->string ->Sexp.tt
delete_key ~must_exist k deletes key k from the dictionary. If k is not bound this fails when must_exist is true or returns the dictionary unchanged when must_exist is false.
key_dom validate queries the key domain of a list of bindings. If validate is Some dom, the query fails if a key is not in dom. The query also fails if a binding is not well-formed. pp_key is used to format keys.
TODO. Not really happy about this function, we lose the key locations which is useful for further deconstruction. Also maybe we rather want binding folds.
atomic q queries an atom or the atom of a singleton list with q. It fails on empty lists or non-singleton lists.
This is useful for singleton dictionary bindings. In error reporting treats the list as if it doesn't exist syntactically which is the case in dictionary bindings.
delete_at_path ~must_exist p deletes the s-expression found by p from the queried s-expression. If the path does not exist this fails if must_exist is true and returns the s-expression itself if must_exist is false.
splice_at_path ?stub ~must_exist p ~rep replaces the s-expression found at p by splicing rep. If the path does not exist this fails if must_exist is true and the non-existing part of the path is created if must_exist is false. If elements need to be created stub (defaults to Sexp.atom "") is used.
splice_caret ?stub ~must_exist p rep splices the s-expression rep at the caret p of the s-expression. If path of the caret does not exist this fails if must_exist is true and the non-existing part of the path is created if must_exist is false. If atoms need to be create stub (defaults to Sexp.atom "") is used.