diff --git a/src/string_with_vars.ml b/src/string_with_vars.ml index 19e2a2fb..3860423c 100644 --- a/src/string_with_vars.ml +++ b/src/string_with_vars.ml @@ -131,7 +131,28 @@ module Expand = struct end end +module type Expand_intf = sig + type context + type expansion + + val expand + : context + -> t + -> allow_multivalue:bool + -> f:(Loc.t -> string -> expansion option) + -> expansion Expand.Full.t + + val partial_expand + : context + -> t + -> allow_multivalue:bool + -> f:(Loc.t -> string -> expansion option) + -> expansion Expand.Partial.t +end + module Expand_to(V: EXPANSION) = struct + type expansion = V.t + type context = V.context let check_valid_multivalue syntax ~var t x = if not t.quoted && V.is_multivalued x then diff --git a/src/string_with_vars.mli b/src/string_with_vars.mli index 0b0e0451..fa9d5d5f 100644 --- a/src/string_with_vars.mli +++ b/src/string_with_vars.mli @@ -79,24 +79,27 @@ module Expand : sig end end -module Expand_to(V : EXPANSION) : sig +module type Expand_intf = sig + type context + type expansion + val expand - : V.context + : context -> t -> allow_multivalue:bool - -> f:(Loc.t -> string -> V.t option) - -> V.t Expand.Full.t + -> f:(Loc.t -> string -> expansion option) + -> expansion Expand.Full.t (** [expand t ~f] return [t] where all variables have been expanded using [f]. If [f loc var] return [Some x], the variable [var] is replaced by [x]; otherwise, the variable is inserted using the syntax it was originally defined with: ${..} or $(..) *) val partial_expand - : V.context + : context -> t -> allow_multivalue:bool - -> f:(Loc.t -> string -> V.t option) - -> V.t Expand.Partial.t + -> f:(Loc.t -> string -> expansion option) + -> expansion Expand.Partial.t (** [partial_expand t ~f] is like [expand_generic] where all variables that could be expanded (i.e., those for which [f] returns [Some _]) are. If all the variables of [t] were @@ -104,6 +107,9 @@ module Expand_to(V : EXPANSION) : sig least a variable of [t], it returns a string-with-vars. *) end +module Expand_to(V : EXPANSION) : Expand_intf + with type expansion = V.t and type context = V.context + val expand : t -> f:(Loc.t -> string -> string option)