module Pat:sig..end
Patterns are strings with variable references of the form
$(VAR[,transform]). In patterns any literal $ must be written
$$.
See carcass-syntax(5) for more information.
type transform =
| |
Uppercase |
| |
Lowercase |
| |
Capitalize |
| |
Uncapitalize |
val transform_of_string : string -> transform optiontransform_of_string s parses a transform from s.val transform_to_string : transform -> stringtransform_of_string t parses a transform from s.val pp_transform : transform Fmt.tpp_transform is a pretty printer for transforms.type lexeme =
| |
Lit of |
| |
Var of |
typet =(lexeme * Carcass.Loc.t) list * Carcass.Loc.t
val empty : tempty is an empty builtin pattern.val dom : t -> Astring.String.setdom p is the set of variable references in p.val equal : t -> t -> boolequal p p' is p = p'.val compare : t -> t -> intcompare p p' is Pervasives.compare p p'.val to_string : ?flesh:bool -> t -> stringto_string ~flesh p converts p to a string according the carcass
syntax for variable references. Escapes the $ in lexeme
literals to $$.
If flesh is true (defaults to false) also escapes double
quote characters '"' (U+0022) with the sequence "\\\""
(<U+005C, U+0022>) and backslash characters '\\' (U+005C) with
the sequence "\\\\" (<U+005C, U+005C>).
val of_input : ?flesh:bool ->
src:Carcass.Loc.src ->
[ `Channel of Pervasives.in_channel | `String of string ] ->
(t, [> Carcass.Error.parse ]) Result.resultof_input ~flesh ~src i considers i as a single atom and
returns its pattern. If flesh is true carcass escapes are
recognized and interpreted; if false (defaults) only variable
references are recognized.val pp : ?flesh:bool -> t Fmt.t
val subst : (string -> string option) -> t -> tsubst defs p substitutes variables in p by the value they map
to in defs.type env
val env : ?undef:(string -> (t, Carcass.Error.parse) Rresult.result option) ->
t Astring.String.map -> envenv ~undef m is an evaluation environment in which variables are
defined according to the map m. undef is called on undefined
variables; its result is cached by the environement, defaults to
(fun _ -> None).val env_var_value : env ->
string ->
(string * Carcass.Loc.t, [> Carcass.Error.eval ]) Rresult.result optionenv_var_value env var is value of variable var in env, if
defined.val eval : env ->
t ->
(string * Carcass.Loc.t, [> Carcass.Error.eval ]) Rresult.resulteval env pat is the evaluation of pattern pat
in environment env.val query : ?init:string Astring.String.map ->
t -> string -> string Astring.String.map optionquery ~init p s returns an environment mapping each pattern variable
of p to its matched part in s, if s matches p. Variables are
added to init. Variables greedily match from zero to more
characters of the file, i.e. .* in regexp speak.