dune/src/string_with_vars.mli

73 lines
2.0 KiB
OCaml

(** String with variables of the form ${...} or $(...)
Variables cannot contain "${", "$(", ")" or "}". For instance in "$(cat
${x})", only "${x}" will be considered a variable, the rest is text. *)
open Import
type t
(** A sequence of text and variables. *)
val t : t Sexp.Of_sexp.t
(** [t ast] takes an [ast] sexp and returns a string-with-vars. This
function distinguishes between unquoted variables — such as ${@} —
and quoted variables — such as "${@}". *)
val loc : t -> Loc.t
(** [loc t] returns the location of [t] — typically, in the jbuild file. *)
val sexp_of_t : t -> Sexp.t
(** Same as [sexp_of_t] but the S-expression encodes the internal
structure of [t]. *)
val sexp_of_ast : t -> Sexp.t
val to_string : t -> string
(** [t] generated by the OCaml code. The first argument should be
[__POS__]. The second is either a string to parse, a variable name
or plain text. [quoted] says whether the string is quoted ([false]
by default). *)
val virt : ?quoted: bool -> (string * int * int * int) -> string -> t
val virt_var : ?quoted: bool -> (string * int * int * int) -> string -> t
val virt_text : (string * int * int * int) -> string -> t
val vars : t -> String.Set.t
(** [vars t] returns the set of all variables in [t]. *)
val fold : t -> init:'a -> f:('a -> Loc.t -> string -> 'a) -> 'a
(** [fold t ~init ~f] fold [f] on all variables of [t], the text
portions being ignored. *)
val iter : t -> f:(Loc.t -> string -> unit) -> unit
(** [iter t ~f] iterates [f] over all variables of [t], the text
portions being ignored. *)
val is_var : t -> name:string -> bool
module Mode : sig
type 'a t =
| Single : Value.t t
| Many : Value.t list t
end
module Partial : sig
type nonrec 'a t =
| Expanded of 'a
| Unexpanded of t
end
val expand
: t
-> mode:'a Mode.t
-> dir:Path.t
-> f:(Loc.t -> string -> Value.t list option)
-> 'a
val partial_expand
: t
-> mode:'a Mode.t
-> dir:Path.t
-> f:(Loc.t -> string -> Value.t list option)
-> 'a Partial.t