Write explicit interface for Expand_to

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-06-05 12:09:47 +07:00
parent eab7c46bdb
commit cadee0e661
2 changed files with 34 additions and 7 deletions

View File

@ -131,7 +131,28 @@ module Expand = struct
end end
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 module Expand_to(V: EXPANSION) = struct
type expansion = V.t
type context = V.context
let check_valid_multivalue syntax ~var t x = let check_valid_multivalue syntax ~var t x =
if not t.quoted && V.is_multivalued x then if not t.quoted && V.is_multivalued x then

View File

@ -79,24 +79,27 @@ module Expand : sig
end end
end end
module Expand_to(V : EXPANSION) : sig module type Expand_intf = sig
type context
type expansion
val expand val expand
: V.context : context
-> t -> t
-> allow_multivalue:bool -> allow_multivalue:bool
-> f:(Loc.t -> string -> V.t option) -> f:(Loc.t -> string -> expansion option)
-> V.t Expand.Full.t -> expansion Expand.Full.t
(** [expand t ~f] return [t] where all variables have been expanded (** [expand t ~f] return [t] where all variables have been expanded
using [f]. If [f loc var] return [Some x], the variable [var] is using [f]. If [f loc var] return [Some x], the variable [var] is
replaced by [x]; otherwise, the variable is inserted using the syntax replaced by [x]; otherwise, the variable is inserted using the syntax
it was originally defined with: ${..} or $(..) *) it was originally defined with: ${..} or $(..) *)
val partial_expand val partial_expand
: V.context : context
-> t -> t
-> allow_multivalue:bool -> allow_multivalue:bool
-> f:(Loc.t -> string -> V.t option) -> f:(Loc.t -> string -> expansion option)
-> V.t Expand.Partial.t -> expansion Expand.Partial.t
(** [partial_expand t ~f] is like [expand_generic] where all (** [partial_expand t ~f] is like [expand_generic] where all
variables that could be expanded (i.e., those for which [f] variables that could be expanded (i.e., those for which [f]
returns [Some _]) are. If all the variables of [t] were 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. *) least a variable of [t], it returns a string-with-vars. *)
end end
module Expand_to(V : EXPANSION) : Expand_intf
with type expansion = V.t and type context = V.context
val expand val expand
: t : t
-> f:(Loc.t -> string -> string option) -> f:(Loc.t -> string -> string option)