2016-12-23 15:32:23 +00:00
|
|
|
(** 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. *)
|
2016-12-02 13:54:32 +00:00
|
|
|
|
|
|
|
open Import
|
|
|
|
|
|
|
|
type t
|
2018-01-27 23:14:04 +00:00
|
|
|
(** A sequence of text and variables. *)
|
|
|
|
|
2017-02-25 17:53:39 +00:00
|
|
|
val t : t Sexp.Of_sexp.t
|
2018-01-29 09:14:09 +00:00
|
|
|
(** [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 "${@}". *)
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2017-05-05 11:26:56 +00:00
|
|
|
val loc : t -> Loc.t
|
2018-01-27 23:14:04 +00:00
|
|
|
(** [loc t] returns the location of [t] — typically, in the jbuild file. *)
|
|
|
|
|
|
|
|
val sexp_of_t : t -> Sexp.t
|
2017-05-05 11:26:56 +00:00
|
|
|
|
2017-05-30 14:40:06 +00:00
|
|
|
val to_string : t -> string
|
2017-06-08 09:54:46 +00:00
|
|
|
|
2018-01-27 23:14:04 +00:00
|
|
|
(** [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. *)
|
2018-01-28 23:14:42 +00:00
|
|
|
val virt : (string * int * int * int) -> string -> t
|
|
|
|
val virt_var : (string * int * int * int) -> string -> t
|
|
|
|
val virt_quoted_var : (string * int * int * int) -> string -> t
|
|
|
|
val virt_text : (string * int * int * int) -> string -> t
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2018-01-28 23:14:42 +00:00
|
|
|
val unquoted_var : t -> string option
|
|
|
|
(** [unquoted_var t] return the [Some name] where [name] is the name of
|
2018-01-27 23:14:04 +00:00
|
|
|
the variable if [t] is solely made of a variable and [None] otherwise. *)
|
2017-03-03 11:49:40 +00:00
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
val vars : t -> String_set.t
|
2018-01-27 23:14:04 +00:00
|
|
|
(** [vars t] returns the set of all variables in [t]. *)
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2017-05-05 11:26:56 +00:00
|
|
|
val fold : t -> init:'a -> f:('a -> Loc.t -> string -> 'a) -> 'a
|
2018-01-27 23:14:04 +00:00
|
|
|
(** [fold t ~init ~f] fold [f] on all variables of [t], the text
|
|
|
|
portions being ignored. *)
|
|
|
|
|
2017-05-31 07:31:52 +00:00
|
|
|
val iter : t -> f:(Loc.t -> string -> unit) -> unit
|
2018-01-27 23:14:04 +00:00
|
|
|
(** [iter t ~f] iterates [f] over all variables of [t], the text
|
|
|
|
portions being ignored. *)
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2017-05-31 07:31:52 +00:00
|
|
|
val expand : t -> f:(Loc.t -> string -> string option) -> string
|
2018-01-27 23:14:04 +00:00
|
|
|
(** [expand t ~f] return [t] where all variables have been expanded
|
|
|
|
using [f]. If [f] returns [Some x], the variable is replaced by
|
|
|
|
[x]; if [f] returns [None], the variable is inserted as [${v}] or
|
|
|
|
[$(v)] — depending on the original concrete syntax used — where [v]
|
|
|
|
is the name if the variable. *)
|
|
|
|
|
|
|
|
val partial_expand : t -> f:(Loc.t -> string -> string option)
|
|
|
|
-> (string, t) either
|
|
|
|
(** [partial_expand t ~f] is like [expand] where all variables that
|
|
|
|
could be expanded (i.e., those for which [f] returns [Some _]) are.
|
|
|
|
If all the variables of [t] were expanded, a string is returned.
|
|
|
|
If [f] returns [None] on at least a variable of [t], it returns a
|
|
|
|
string-with-vars. *)
|
|
|
|
|