Module Sexplib.Path

Path: Module for Substitutions within S-expressions

Types
type el =
| Pos of int

(** Pos n denotes nth element in a tuple *)

| Match of string * int

(** Match (tag, n) denotes nth argument of sum matching tag *)

| Rec of string

(** Rec name denotes the record field having name *)

Type of substitution elements

type t = el list

Type of substitution paths

High-level functions
val parse : string ‑> t

parse str

val get : ?⁠path:t ‑> ?⁠str:string ‑> Sexp.t ‑> Sexp.t

get ?path ?str sexp if path is provided, use it as path. Otherwise, if str is provided, parse it as a path. If neither is provided, assume an empty path.

val replace : ?⁠path:t ‑> ?⁠str:string ‑> Sexp.t ‑> subst:Sexp.t ‑> Sexp.t

replace ?path ?str sexp ~subst like get, but does not extract a sub-expression but substitutes it with subst.

val replace_no_path : str:string ‑> Sexp.t ‑> subst:Sexp.t ‑> Sexp.t

replace_no_path ~str sexp ~subst like replace, but does not take optional arguments. str must be specified.

val subst_path : Sexp.t ‑> t ‑> (Sexp.t ‑> Sexp.t) * Sexp.t

subst_path sexp path

Low-level functions
val extract_pos : int ‑> Sexp.t ‑> (Sexp.t option ‑> Sexp.t) * Sexp.t

extract_pos n sexp

val extract_match : string ‑> int ‑> Sexp.t ‑> (Sexp.t option ‑> Sexp.t) * Sexp.t

extract_match tag n sexp

val extract_rec : string ‑> Sexp.t ‑> (Sexp.t ‑> Sexp.t) * Sexp.t

extract_rec name sexp