Module B0_sexp.Sexpl

S-expression locators.

Locators provide a way for end users to address specific locations in s-expressions. A location is either before, after or onto an s-expression.

ocaml.deps        # value of key 'deps' of dictionary 'ocaml'
ocaml.v[deps]     # before key binding
ocaml.[deps]v     # after key binding

ocaml.deps.[0]    # first element of key 'deps' of dictionary 'ocaml'
ocaml.deps.v[0]   # before first element
ocaml.deps.[0]v   # after first element

ocaml.deps.[-1]   # last element of key 'deps' of dictionary 'ocaml'
ocaml.deps.v[-1]  # before last element
ocaml.deps.[-1]v  # after last element

More formally a locator is a . separated list of indices ended by a location. A location is either an index or an index prefixed or suffixed by the character v to respectively denote insertion before or after.

An index is written [i] with i either a zero-based list index (with negative indices counting from the end of the list) or a dictionary key key; in the latter case if there is no ambiguity, the surrounding brackets can be dropped.

Note. There's no form of quoting at the moment this means key names can't contain, , , or be numbers.

Paths

FIXME we likely want to move that to Sexpq.

type path

The type for paths. A sequence of indexing operations.

val start : path

start is the starting s-expression to index.

val key : string -> path -> path

key k p indexes the s-expression at path p using key k.

val nth : int -> path -> path

nth i p indexes the s-expression at path p with i. If i is negative counts the number of element from the end of the list, i.e. -1 is the last list element.

val query_path : path -> 'a Sexpq.t -> 'a Sexpq.t

query_path p q queries the value indexed by p using q.

val query_path_opt : path -> 'a Sexpq.t -> 'a option Sexpq.t

query_path p q queries the value indexed by p using q, the query succeeds with None if the path doesn't exist.

val path_of_string : string -> (path, string) Stdlib.result

Locators

type t =
| Before of path

The void before the path.

| Onto of path

The value at the path.

| After of path

The void after the path.

The type for locators.

val path : t -> path

path l is the locator's path.

val edit_loc : t -> Sexp.loc * string list Sexpq.t

edit_loc t is a query that returns a text location where the locator t should perform an edition and a list of nested key bindings that need to be created.

val of_string : string -> (t, string) Stdlib.result

of_string s parses a locator s according to the syntax defined in the preamble.