Module Bos_setup.Pat
include module type of struct include Bos.Pat end
Patterns
type t = Bos.Pat.tThe type for patterns.
val v : string -> Bos_setup.Pat.tv s is a pattern from the string s.
val empty : Bos_setup.Pat.tempty is an empty pattern.
val dom : Bos_setup.Pat.t -> Astring.String.Set.tdom p is the set of variables in p.
val equal : Bos_setup.Pat.t -> Bos_setup.Pat.t -> boolequal p p' is p = p'.
val compare : Bos_setup.Pat.t -> Bos_setup.Pat.t -> intcompare p p' is Stdlib.compare p p'.
val of_string : string -> (Bos_setup.Pat.t, [> Rresult.R.msg ]) Rresult.resultof_string s parses s according to the pattern syntax (i.e. a literal '$' must be represented by "$$" in s).
val to_string : Bos_setup.Pat.t -> stringto_string p converts p to a string according to the pattern syntax (i.e. a literal '$' will be represented by "$$").
val pp : Stdlib.Format.formatter -> Bos_setup.Pat.t -> unitpp ppf p prints p on ppf according to the pattern syntax.
val dump : Stdlib.Format.formatter -> Bos_setup.Pat.t -> unitdump ppf p prints p as a syntactically valid OCaml string on ppf.
Substitution
Note. Substitution replaces variables with data, i.e. strings. It cannot substitute variables with variables.
type defs = string Astring.String.Map.tType type for variable definitions. Maps pattern variable names to strings.
val subst :
?undef:(string -> string option) ->
Bos_setup.Pat.defs ->
Bos_setup.Pat.t ->
Bos_setup.Pat.tsubst ~undef defs p tries to substitute variables in p by their value. First a value is looked up in defs and if not found in undef. undef defaults to (fun _ -> None).
val format :
?undef:(string -> string) ->
Bos_setup.Pat.defs ->
Bos_setup.Pat.t ->
stringformat ~undef defs p substitutes all variables in p with data. First a value is looked up in defs and if not found in undef (defaults to fun _ -> ""). The resulting string is not in pattern syntax (i.e. a literal '$' is represented by '$' in the result).
Matching
Pattern variables greedily match from zero to more bytes from left to right. This is .* in regexp speak.
val matches : Bos_setup.Pat.t -> string -> boolmatches p s is true iff the string s matches p. Here are a few examples:
matches (v "$(mod).mli") "string.mli"istrue.matches (v "$(mod).mli") "string.mli "isfalse.matches (v "$(mod).mli") ".mli"istrue.matches (v "$(mod).$(suff)") "string.mli"istrue.matches (v "$(mod).$(suff)") "string.mli "istrue.
val query :
?init:Bos_setup.Pat.defs ->
Bos_setup.Pat.t ->
string ->
Bos_setup.Pat.defs optionquery ~init p s is like matches except that a matching string returns a map from each pattern variable to its matched part in the string (mappings are added to init, defaults to String.Map.empty) or None if s doesn't match p. If a variable appears more than once in pat the first match is returned in the map.