(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
(* (c) Copyright 2006-2015 Microsoft Corporation and Inria. *)
open Environ open Evd open Constr open Genintern
(** ******** Small Scale Reflection pattern matching facilities ************* *)
(** The type of context patterns, the patterns of the [set] tactic and
[:] tactical. These are patterns that identify a precise subterm. *) type cpattern =
{ kind : ssrtermkind
; pattern : Genintern.glob_constr_and_expr
; interpretation : Geninterp.interp_sign option } val pr_cpattern : cpattern -> Pp.t
(** The type of rewrite patterns, the patterns of the [rewrite] tactic. Thesepatternsalsoincludepatternsthatidentifyallthesubterms
of a context (i.e. "in" prefix) *) type rpattern = (cpattern, cpattern) ssrpattern val pr_rpattern : rpattern -> Pp.t
(** Extracts the redex and applies to it the substitution part of the pattern.
@raise Anomaly if called on [In_T] or [In_X_In_T] *) val redex_of_pattern :
pattern -> (Evd.evar_map * EConstr.t) option
(** [interp_rpattern ise gl rpat] "internalizes" and "interprets" [rpat]
in the current [Ltac] interpretation signature [ise] and tactic input [gl]*) val interp_rpattern :
Environ.env -> Evd.evar_map ->
rpattern ->
pattern
(** [interp_cpattern ise gl cpat ty] "internalizes" and "interprets" [cpat] inthecurrent[Ltac]interpretationsignature[ise]andtacticinput[gl].
[ty] is an optional type for the redex of [cpat] *) val interp_cpattern :
Environ.env -> Evd.evar_map ->
cpattern -> (glob_constr_and_expr * Geninterp.interp_sign) option ->
pattern
(** The set of occurrences to be matched. The boolean is set to true
* to signal the complement of this set (i.e. \{-1 3\}) *) type occ = (bool * int list) option
(** [subst e p t i]. [i] is the number of binders
traversed so far, [p] the term from the pattern, [t] the matched one *) type subst = Environ.env -> EConstr.t -> EConstr.t -> int -> EConstr.t
(** [eval_pattern b env sigma t pat occ subst] maps [t] calling [subst] on every [occ]occurrenceof[pat].The[int]argumentisthenumberof binderstraversed.If[pat]is[None]thenthensubstiscalledon[t]. [t]mustlivein[env]and[sigma],[pat]musthavebeeninterpretedin (anextensionof)[sigma]. @raiseNoMatchif[pat]hasnooccurrenceand[b]is[true](default[false]) @return[t]whereall[occ]occurrencesof[pat]havebeenmappedusing
[subst] *) val eval_pattern :
?raise_NoMatch:bool ->
env -> evar_map -> EConstr.t ->
pattern option -> occ -> subst ->
EConstr.t
(** [fill_occ_pattern b env sigma t pat occ h] is a simplified version of [eval_pattern]. Itreplacesall[occ]occurrencesof[pat]in[t]withRel[h]. [t]mustlivein[env]and[sigma],[pat]musthavebeeninterpretedin (anextensionof)[sigma]. @raiseNoMatchif[pat]hasnooccurrenceand[b]is[true](default[false]) @returntheinstanceoftheredexof[pat]thatwasmatchedand[t]
transformed as described above. *) val fill_occ_pattern :
?raise_NoMatch:bool ->
env -> evar_map -> EConstr.t ->
pattern -> occ -> int ->
EConstr.t Evd.in_ustate * EConstr.t
(** Variant of the above function where we fix [h := 1] and return
[redex_of_pattern pat] if [pat] has no occurrence. *) val fill_rel_occ_pattern :
env -> evar_map -> EConstr.t -> pattern -> occ ->
evar_map * EConstr.t * EConstr.t
(* The primitive matching facility. It matches of a term with holes, like
the T pattern above, and calls a continuation on its occurrences. *)
type ssrdir = L2R | R2L val pr_dir_side : ssrdir -> Pp.t
(** patterns for a term with wildcards *) type tpatterns
val empty_tpatterns : Evd.evar_map -> tpatterns
(** [mk_tpattern env sigma0 sigma_p ok p_origin dir t] compiles a term [t] livingin[env][sigma](anextensionof[sigma0])introa[tpattern]. The[tpattern]canholda(proof)term[p]andadiction[dir].The[ok] callbackisusedtofilteroccurrences. @returnthecompiled[tpattern]andits[evar_map]
@raise UserEerror is the pattern is a wildcard *) val mk_tpattern :
?p_origin:ssrdir * EConstr.t ->
?ok:(EConstr.t -> evar_map -> bool) ->
rigid:(Evar.t -> bool) ->
env ->
EConstr.t ->
ssrdir -> EConstr.t ->
tpatterns -> tpatterns
(** [findP env t i k] is a stateful function that finds the next occurrence ofatpatternandcallsthecallback[k]tomapthesubtermmatched. The[int]argumentpassedto[k]isthenumberofbinderstraversedsofar plustheinitialvalue[i]. @return[t]wherethesubtermsidentifiedbytheselectedoccurrencesof thepatterhavebeenmappedusing[k] @raiseNoMatchiftheraise_NoMatchflaggivento[mk_tpattern_matcher]is [true]andifthepatterndidnotmatch @raiseUserEerroriftheraise_NoMatchflaggivento[mk_tpattern_matcher]is
[false] and if the pattern did not match *) type find_P =
Environ.env -> EConstr.t -> int -> k:subst -> EConstr.t
(** [conclude ()] asserts that all mentioned occurrences have been visited. @returntheinstanceofthepattern,theevarmapafterthepattern instantiation,theprooftermandthessrditstoredinthetpattern
@raise UserEerror if too many occurrences were specified *) type conclude =
unit -> EConstr.t * ssrdir * (bool * evar_map * UState.t * EConstr.t)
(** [mk_tpattern_matcher b o sigma0 occ sigma_tplist] creates a pair afunction[find_P]and[conclude]withthebehaviourexplainedabove. Theflag[b](default[false])changestheerrorreportingbehaviour of[find_P]ifnoneofthe[tpattern]matches.Theargument[o]can bepassedtotunethe[UserError]eventuallyraised(usefulifthe
pattern is coming from the LHS/RHS of an equation) *) val mk_tpattern_matcher :
?all_instances:bool ->
?raise_NoMatch:bool ->
?upats_origin:ssrdir * EConstr.t ->
evar_map -> occ -> tpatterns -> find_P * conclude
(** Example of [mk_tpattern_matcher] to implement [rewrite\{occ\}\[int\]rules]. Itfirstmatches"int"(called[pat]),theninallmatchedsubterms itmatchestheLHSoftherulesusing[find_R]. [concl0]istheinitialgoal,[concl]willbethegoalwheresometerms arereplacedbyaDeBruijnindex.The[rw_progress]extracheck selectsonlyoccurrencesthatarenotrewrittentothemselves(e.g. anoccurrence"x+x"rewrittenwiththecommutativitylawofaddition isskipped) {[ letfind_R,conclude=matchpatwith |Some(_,In_T_)-> letaux(sigma,pats)(d,r,lhs,rhs)= letsigma,pat= mk_tpatternenv0sigma0(sigma,r)(rw_progressrhs)dlhsin sigma,pats@[pat]in letrpats=List.fold_leftaux(r_sigma,[])rulesin letfind_R,end_R=mk_tpattern_matchersigma0occrpatsin find_R~k:(fun__h->mkRelh), funcl->letrdx,d,r=end_R()in(d,r),rdx |_->...in letconcl=eval_patternenv0sigma0concl0patoccfind_Rin let(d,r),rdx=concludeconclin
]} *)
(* convenience shortcut: [fill_occ_term env concl sigma occ (sigma,t)] returns *[concl]where[occ]occurrencesof[t]havebeenreplaced
* by [Rel 1] and the instance of [t] *)
(** Helpers to make stateful closures. Example: a [find_P] function may be calledmanytimes,butthepatterninstantiationphaseisperformedonlythe firsttime.Thecorresponding[conclude]hastoreturntheinstantiated patternredex.Sinceitisupto[find_P]toraise[NoMatch]ifthepattern hasnoinstance,[conclude]considersitananomalyifthepatterndid
not match *)
(** [do_once r f] calls [f] and updates the ref only once *) val do_once : 'a option ref -> (unit -> 'a) -> unit
(** [assert_done r] return the content of r.
@raise Anomaly is r is [None] *) val assert_done : 'a option ref -> 'a
(** Very low level APIs. thesearecallstoevarconv's[the_conv_x]followedby [solve_unif_constraints_with_heuristics].
In case of failure they raise [NoMatch] *)
(** Some more low level functions needed to implement the full SSR language
on top of the former APIs *) val tag_of_cpattern : cpattern -> ssrtermkind val loc_of_cpattern : cpattern -> Loc.t option val id_of_pattern : evar_map -> pattern -> Names.Id.t option val is_wildcard : cpattern -> bool val cpattern_of_id : Names.Id.t -> cpattern val pr_constr_pat : env -> evar_map -> constr -> Pp.t val pr_econstr_pat : env -> evar_map -> econstr -> Pp.t
(* One can also "Set SsrMatchingDebug" from a .v *) val debug : bool -> unit
val ssrinstancesof : cpattern -> unit Proofview.tactic
(** Functions used for grammar extensions. Do not use. *)
module Internal : sig val wit_rpatternty : (rpattern, rpattern, rpattern) Genarg.genarg_type val glob_rpattern : Genintern.glob_sign -> rpattern -> rpattern val subst_rpattern : Mod_subst.substitution -> rpattern -> rpattern val interp_rpattern : Geninterp.interp_sign -> env -> evar_map -> rpattern -> rpattern val pr_rpattern : rpattern -> Pp.t val mk_rpattern : (cpattern, cpattern) ssrpattern -> rpattern val mk_lterm : Constrexpr.constr_expr -> Geninterp.interp_sign option -> cpattern val mk_term : ssrtermkind -> Constrexpr.constr_expr -> Geninterp.interp_sign option -> cpattern
val glob_cpattern : Genintern.glob_sign -> cpattern -> cpattern val subst_ssrterm : Mod_subst.substitution -> cpattern -> cpattern val interp_ssrterm : Geninterp.interp_sign -> env -> evar_map -> cpattern -> cpattern val pr_ssrterm : cpattern -> Pp.t end
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.