1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(*i $Id: matching.mli 11739 2009-01-02 19:33:19Z herbelin $ i*)
19
(*s This modules implements pattern-matching on terms *)
21
exception PatternMatchingFailure
23
val special_meta : metavariable
25
type bound_ident_map = (identifier * identifier) list
27
(* [matches pat c] matches [c] against [pat] and returns the resulting
28
assignment of metavariables; it raises [PatternMatchingFailure] if
29
not matchable; bindings are given in increasing order based on the
30
numbers given in the pattern *)
31
val matches : constr_pattern -> constr -> patvar_map
33
(* [extended_matches pat c] also returns the names of bound variables
34
in [c] that matches the bound variables in [pat]; if several bound
35
variables or metavariables have the same name, the metavariable,
36
or else the rightmost bound variable, takes precedence *)
37
val extended_matches :
38
constr_pattern -> constr -> bound_ident_map * patvar_map
40
(* [is_matching pat c] just tells if [c] matches against [pat] *)
41
val is_matching : constr_pattern -> constr -> bool
43
(* [matches_conv env sigma] matches up to conversion in environment
44
[(env,sigma)] when constants in pattern are concerned; it raises
45
[PatternMatchingFailure] if not matchable; bindings are given in
46
increasing order based on the numbers given in the pattern *)
47
val matches_conv :env -> Evd.evar_map -> constr_pattern -> constr -> patvar_map
49
(* The type of subterm matching results: a substitution + a context
50
(whose hole is denoted with [special_meta]) + a continuation that
51
either returns the next matching subterm or raise PatternMatchingFailure *)
52
type subterm_matching_result =
53
(bound_ident_map * patvar_map) * constr * (unit -> subterm_matching_result)
55
(* [match_subterm n pat c] returns the substitution and the context
56
corresponding to the first **closed** subterm of [c] matching [pat], and
57
a continuation that looks for the next matching subterm.
58
It raises PatternMatchingFailure if no subterm matches the pattern *)
59
val match_subterm : constr_pattern -> constr -> subterm_matching_result
61
(* [match_appsubterm pat c] returns the substitution and the context
62
corresponding to the first **closed** subterm of [c] matching [pat],
63
considering application contexts as well. It also returns a
64
continuation that looks for the next matching subterm.
65
It raises PatternMatchingFailure if no subterm matches the pattern *)
66
val match_appsubterm : constr_pattern -> constr -> subterm_matching_result
68
(* [match_subterm_gen] calls either [match_subterm] or [match_appsubterm] *)
69
val match_subterm_gen : bool (* true = with app context *) ->
70
constr_pattern -> constr -> subterm_matching_result
72
(* [is_matching_appsubterm pat c] tells if a subterm of [c] matches
73
against [pat] taking partial subterms into consideration *)
74
val is_matching_appsubterm : ?closed:bool -> constr_pattern -> constr -> bool
76
(* [is_matching_conv env sigma pat c] tells if [c] matches against [pat]
77
up to conversion for constants in patterns *)
78
val is_matching_conv :
79
env -> Evd.evar_map -> constr_pattern -> constr -> bool