Module Sexplib.Path
Types
type el=|Pos of intPos ndenotesnth element in a tuple|Match of string * intMatch (tag, n)denotesnth argument of sum matchingtag|Rec of stringRec namedenotes the record field havingnameType of substitution elements
type t= el listType of substitution paths
High-level functions
val parse : string -> tparse str- returns
a substitution path represented by string
str.Syntax:
"." -> separates path elements; must be present at start of string.
"[4]" -> specifies the 4th element in a tuple.
"some_tag[4]" -> tries to match
some_tag, then denotes its 4th argument."name" -> denotes record field having
nameExample from test code:
".t.x.B
1" -> choose record field with namet, then subfieldx. Match this value againstB, and denote its first argument.
- raises Failure
if the path is syntactically invalid.
val get : ?path:t -> ?str:string -> Sexp.t -> Sexp.tget ?path ?str sexpifpathis provided, use it as path. Otherwise, ifstris provided, parse it as a path. If neither is provided, assume an empty path.- returns
the sub-expression from S-expression
sexpdenoted by the path.
- raises Failure
if path is syntactically invalid or if the path structure clashes with the structure of the data.
val replace : ?path:t -> ?str:string -> Sexp.t -> subst:Sexp.t -> Sexp.treplace ?path ?str sexp ~substlikeget, but does not extract a sub-expression but substitutes it withsubst.- returns
resulting S-expression.
- raises Failure
if path is syntactically invalid or if the path structure clashes with the structure of the data.
val replace_no_path : str:string -> Sexp.t -> subst:Sexp.t -> Sexp.treplace_no_path ~str sexp ~substlikereplace, but does not take optional arguments.strmust be specified.- raises Failure
if path is syntactically invalid or if the path structure clashes with the structure of the data.
val subst_path : Sexp.t -> t -> (Sexp.t -> Sexp.t) * Sexp.tsubst_path sexp path- returns
the tuple
(subst, sub), wheresubstis a function that returns an S-expression in which the subexpression denoted bypathinsexphas been substituted by its argument.subis the denoted subexpression. Note thatsubst sub = sexp.
- raises Failure
if path is syntactically invalid or if the path structure clashes with the structure of the data.
Low-level functions
val extract_pos : int -> Sexp.t -> (Sexp.t option -> Sexp.t) * Sexp.textract_pos n sexp- returns
the tuple
(subst, sub), wheresubstis a function that returns an S-expression in which the subexpression denoted at positionninsexp, which must be a list, has been substituted byvalueif the optional argument isSome value, or removes the denoted subexpression if the optional argument isNone.subis the denoted subexpression. Note thatsubst (Some sub) = sexp.
- raises Failure
if the position cannot be resolved within the given S-expression.
val extract_match : string -> int -> Sexp.t -> (Sexp.t option -> Sexp.t) * Sexp.textract_match tag n sexp- returns
the tuple
(subst, sub), wheresubstis a function that returns an S-expression in which the subexpression denoted by matchingtagand taking itsnth argument insexphas been substituted byvalueif the argument isSome value, or removes the denoted subexpression if the optional argument isNone.subis the denoted subexpression. Note thatsubst (Some sub) = sexp.
- raises Failure
if the S-expression does not represent a sum tag.
val extract_rec : string -> Sexp.t -> (Sexp.t -> Sexp.t) * Sexp.textract_rec name sexp- returns
the tuple
(subst, sub), wheresubstis a function that returns an S-expression in which the subexpression denoted by matching field namenameinsexphas been substituted by its argument.subis the denoted subexpression. Note thatsubst (Some sub) = sexp.
- raises Failure
if the S-expression does not represent a record.