| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
DECLARE PLUGIN "rocq-runtime.plugins.ltac" |
| 12 |
|
| 13 |
{ |
| 14 |
|
| 15 |
open Pp |
| 16 |
open CErrors |
| 17 |
open Util |
| 18 |
open Names |
| 19 |
open Namegen |
| 20 |
open Tacexpr |
| 21 |
open Genredexpr |
| 22 |
open Constrexpr |
| 23 |
open Libnames |
| 24 |
open Tok |
| 25 |
open Tactypes |
| 26 |
open Tactics |
| 27 |
open Inv |
| 28 |
open Locus |
| 29 |
open G_redexpr |
| 30 |
|
| 31 |
open Procq |
| 32 |
|
| 33 |
|
| 34 |
let all_with ~head delta = |
| 35 |
let all = [FBeta;FMatch;FFix;FCofix;FZeta;delta] in |
| 36 |
Redops.make_red_flag (if head then FHead :: all else all) |
| 37 |
|
| 38 |
(* Hack to parse "(x:=t)" as an explicit argument without conflicts with the *) |
| 39 |
(* admissible notation "(x t)" *) |
| 40 |
let test_lpar_id_coloneq = |
| 41 |
let open Procq.Lookahead in |
| 42 |
to_entry "lpar_id_coloneq" begin |
| 43 |
lk_kw "(" >> lk_ident >> lk_kw ":=" |
| 44 |
end |
| 45 |
|
| 46 |
(* Hack to recognize "(x)" *) |
| 47 |
let test_lpar_id_rpar = |
| 48 |
let open Procq.Lookahead in |
| 49 |
to_entry "lpar_id_coloneq" begin |
| 50 |
lk_kw "(" >> lk_ident >> lk_kw ")" |
| 51 |
end |
| 52 |
|
| 53 |
(* idem for (x:=t) and (1:=t) *) |
| 54 |
let test_lpar_idnum_coloneq = |
| 55 |
let open Procq.Lookahead in |
| 56 |
to_entry "test_lpar_idnum_coloneq" begin |
| 57 |
lk_kw "(" >> (lk_ident <+> lk_nat) >> lk_kw ":=" |
| 58 |
end |
| 59 |
|
| 60 |
let test_leftsquarebracket_equal = |
| 61 |
let open Procq.Lookahead in |
| 62 |
to_entry "test_leftsquarebracket_equal" begin |
| 63 |
lk_kw "[" >> lk_kw "=" >> check_no_space |
| 64 |
end |
| 65 |
|
| 66 |
(* idem for (x:t) *) |
| 67 |
open Extraargs |
| 68 |
|
| 69 |
(* idem for (x1..xn:t) [n^2 complexity but exceptional use] *) |
| 70 |
let check_for_coloneq = |
| 71 |
Procq.Entry.(of_parser "lpar_id_colon" |
| 72 |
{ parser_fun = fun kwstate strm -> |
| 73 |
let rec skip_to_rpar p n = |
| 74 |
match List.last (Gramlib.LStream.npeek kwstate n strm) with |
| 75 |
| KEYWORD "(" -> skip_to_rpar (p+1) (n+1) |
| 76 |
| KEYWORD ")" -> if Int.equal p 0 then Ok (n+1) else skip_to_rpar (p-1) (n+1) |
| 77 |
| KEYWORD "." -> Error () |
| 78 |
| _ -> skip_to_rpar p (n+1) in |
| 79 |
let rec skip_names n = |
| 80 |
match List.last (Gramlib.LStream.npeek kwstate n strm) with |
| 81 |
| IDENT _ | KEYWORD "_" -> skip_names (n+1) |
| 82 |
| KEYWORD ":" -> skip_to_rpar 0 (n+1) (* skip a constr *) |
| 83 |
| _ -> Error () in |
| 84 |
let rec skip_binders n = |
| 85 |
match List.last (Gramlib.LStream.npeek kwstate n strm) with |
| 86 |
| KEYWORD "(" -> Result.bind (skip_names (n+1)) skip_binders |
| 87 |
| IDENT _ | KEYWORD "_" -> skip_binders (n+1) |
| 88 |
| KEYWORD ":=" -> Ok () |
| 89 |
| _ -> Error () in |
| 90 |
match Gramlib.LStream.peek_nth kwstate 0 strm with |
| 91 |
| Some (KEYWORD "(") -> skip_binders 2 |
| 92 |
| _ -> Error () }) |
| 93 |
|
| 94 |
let lookup_at_as_comma = |
| 95 |
let open Procq.Lookahead in |
| 96 |
to_entry "lookup_at_as_comma" begin |
| 97 |
lk_kws [",";"at";"as"] |
| 98 |
end |
| 99 |
|
| 100 |
open Constr |
| 101 |
open Prim |
| 102 |
open Pltac |
| 103 |
|
| 104 |
let mk_fix_tac (loc,id,bl,ann,ty) = |
| 105 |
let n = |
| 106 |
match bl,ann with |
| 107 |
[([_],_,_)], None -> 1 |
| 108 |
| _, Some x -> |
| 109 |
let ids = List.map (fun x -> x.CAst.v) (List.flatten (List.map (fun (nal,_,_) -> nal) bl)) in |
| 110 |
(try List.index Names.Name.equal x.CAst.v ids |
| 111 |
with Not_found -> user_err ~loc Pp.(str "No such fix variable.")) |
| 112 |
| _ -> user_err ~loc Pp.(str "Cannot guess decreasing argument of fix.") in |
| 113 |
let bl = List.map (fun (nal,bk,t) -> CLocalAssum (nal,None,bk,t)) bl in |
| 114 |
(id,n, CAst.make ~loc @@ CProdN(bl,ty)) |
| 115 |
|
| 116 |
let mk_cofix_tac (loc,id,bl,ann,ty) = |
| 117 |
let () = Option.iter (fun { CAst.loc = aloc } -> |
| 118 |
user_err ?loc:aloc |
| 119 |
(Pp.str"Annotation forbidden in cofix expression.")) |
| 120 |
ann |
| 121 |
in |
| 122 |
let bl = List.map (fun (nal,bk,t) -> CLocalAssum (nal,None,bk,t)) bl in |
| 123 |
(id,if bl = [] then ty else CAst.make ~loc @@ CProdN(bl,ty)) |
| 124 |
|
| 125 |
(* Functions overloaded by quotifier *) |
| 126 |
let destruction_arg_of_constr (c,lbind as clbind) = match lbind with |
| 127 |
| NoBindings -> |
| 128 |
begin |
| 129 |
try ElimOnIdent (CAst.make ?loc:(Constrexpr_ops.constr_loc c) (Constrexpr_ops.coerce_to_id c).CAst.v) |
| 130 |
with e when CErrors.noncritical e -> ElimOnConstr clbind |
| 131 |
end |
| 132 |
| _ -> ElimOnConstr clbind |
| 133 |
|
| 134 |
let mkNumber n = |
| 135 |
Number (NumTok.Signed.of_int_string (string_of_int n)) |
| 136 |
|
| 137 |
let mkTacCase with_evar = function |
| 138 |
| [(clear,ElimOnConstr cl),(None,None),None],None -> |
| 139 |
TacCase (with_evar,(clear,cl)) |
| 140 |
(* Reinterpret numbers as a notation for terms *) |
| 141 |
| [(clear,ElimOnAnonHyp n),(None,None),None],None -> |
| 142 |
TacCase (with_evar, |
| 143 |
(clear,(CAst.make @@ CPrim (mkNumber n), |
| 144 |
NoBindings))) |
| 145 |
(* Reinterpret ident as notations for variables in the context *) |
| 146 |
(* because we don't know if they are quantified or not *) |
| 147 |
| [(clear,ElimOnIdent id),(None,None),None],None -> |
| 148 |
TacCase (with_evar,(clear,(CAst.make @@ CRef (qualid_of_ident ?loc:id.CAst.loc id.CAst.v,None),NoBindings))) |
| 149 |
| ic -> |
| 150 |
if List.exists (function ((_, ElimOnAnonHyp _),_,_) -> true | _ -> false) (fst ic) |
| 151 |
then |
| 152 |
user_err Pp.(str "Use of numbers as direct arguments of 'case' is not supported."); |
| 153 |
TacInductionDestruct (false,with_evar,ic) |
| 154 |
|
| 155 |
let rec mkCLambdaN_simple_loc ?loc bll c = |
| 156 |
match bll with |
| 157 |
| ({CAst.loc = loc1}::_ as idl,bk,t) :: bll -> |
| 158 |
CAst.make ?loc @@ CLambdaN ([CLocalAssum (idl,None,bk,t)],mkCLambdaN_simple_loc ?loc:(Loc.merge_opt loc1 loc) bll c) |
| 159 |
| ([],_,_) :: bll -> mkCLambdaN_simple_loc ?loc bll c |
| 160 |
| [] -> c |
| 161 |
|
| 162 |
let mkCLambdaN_simple bl c = match bl with |
| 163 |
| [] -> c |
| 164 |
| h :: _ -> |
| 165 |
let loc = Loc.merge_opt (List.hd (pi1 h)).CAst.loc (Constrexpr_ops.constr_loc c) in |
| 166 |
mkCLambdaN_simple_loc ?loc bl c |
| 167 |
|
| 168 |
let loc_of_ne_list l = Loc.merge_opt (List.hd l).CAst.loc (List.last l).CAst.loc |
| 169 |
|
| 170 |
let all_concl_occs_clause = { onhyps=Some[]; concl_occs=AllOccurrences } |
| 171 |
|
| 172 |
let merge_occurrences loc cl = function |
| 173 |
| None -> |
| 174 |
if Locusops.clause_with_generic_occurrences cl then (None, cl) |
| 175 |
else |
| 176 |
user_err ~loc (str "Found an \"at\" clause without \"with\" clause.") |
| 177 |
| Some (occs, p) -> |
| 178 |
let ans = match occs with |
| 179 |
| AllOccurrences -> cl |
| 180 |
| _ -> |
| 181 |
begin match cl with |
| 182 |
| { onhyps = Some []; concl_occs = AllOccurrences } -> |
| 183 |
{ onhyps = Some []; concl_occs = occs } |
| 184 |
| { onhyps = Some [(AllOccurrences, id), l]; concl_occs = NoOccurrences } -> |
| 185 |
{ cl with onhyps = Some [(occs, id), l] } |
| 186 |
| _ -> |
| 187 |
if Locusops.clause_with_generic_occurrences cl then |
| 188 |
user_err ~loc (str "Unable to interpret the \"at\" clause; move it in the \"in\" clause.") |
| 189 |
else |
| 190 |
user_err ~loc (str "Cannot use clause \"at\" twice.") |
| 191 |
end |
| 192 |
in |
| 193 |
(Some p, ans) |
| 194 |
|
| 195 |
let intro_naming_of_lident { CAst.loc; v = id } = CAst.make ?loc @@ IntroNaming (IntroIdentifier id) |
| 196 |
|
| 197 |
let deprecated_conversion_at_with = |
| 198 |
CWarnings.create |
| 199 |
~name:"conversion_at_with" ~category:Deprecation.Version.v8_14 |
| 200 |
(fun () -> Pp.str "The syntax [at ... with ...] is deprecated. Use [with ... at ...] instead.") |
| 201 |
|
| 202 |
(* Auxiliary grammar rules *) |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
GRAMMAR EXTEND Gram |
| 207 |
GLOBAL: simple_tactic constr_with_bindings quantified_hypothesis |
| 208 |
bindings open_constr uconstr |
| 209 |
intropattern simple_intropattern |
| 210 |
in_clause clause_dft_concl hypident destruction_arg; |
| 211 |
|
| 212 |
(* An identifier or a quotation meta-variable *) |
| 213 |
id_or_meta: |
| 214 |
[ [ id = identref -> { id } ] ] |
| 215 |
; |
| 216 |
open_constr: |
| 217 |
[ [ c = constr -> { c } ] ] |
| 218 |
; |
| 219 |
uconstr: |
| 220 |
[ [ c = constr -> { c } ] ] |
| 221 |
; |
| 222 |
destruction_arg: |
| 223 |
[ [ n = natural -> { (None,ElimOnAnonHyp n) } |
| 224 |
| test_lpar_id_rpar; c = constr_with_bindings -> |
| 225 |
{ (Some false,destruction_arg_of_constr c) } |
| 226 |
| c = constr_with_bindings_arg -> { on_snd destruction_arg_of_constr c } |
| 227 |
] ] |
| 228 |
; |
| 229 |
constr_with_bindings_arg: |
| 230 |
[ [ c = constr_with_bindings -> { (None,c) } ] ] |
| 231 |
; |
| 232 |
quantified_hypothesis: |
| 233 |
[ [ id = ident -> { NamedHyp (CAst.make ~loc id) } |
| 234 |
| n = natural -> { AnonHyp n } ] ] |
| 235 |
; |
| 236 |
conversion: |
| 237 |
[ [ c = constr -> { (None, c) } |
| 238 |
| c1 = constr; "with"; c2 = constr -> { (Some (AllOccurrences,c1),c2) } |
| 239 |
| c1 = constr; "at"; occs = occs_nums; "with"; c2 = constr -> |
| 240 |
{ deprecated_conversion_at_with (); (* 8.14 *) |
| 241 |
(Some (occs,c1), c2) } ] ] |
| 242 |
; |
| 243 |
intropatterns: |
| 244 |
[ [ l = LIST0 intropattern -> { l } ] ] |
| 245 |
; |
| 246 |
ne_intropatterns: |
| 247 |
[ [ l = LIST1 intropattern -> { l } ] ] |
| 248 |
; |
| 249 |
or_and_intropattern: |
| 250 |
[ [ "["; tc = LIST1 intropatterns SEP "|"; "]" -> { IntroOrPattern tc } |
| 251 |
| "()" -> { IntroAndPattern [] } |
| 252 |
| "("; si = simple_intropattern; ")" -> { IntroAndPattern [si] } |
| 253 |
| "("; si = simple_intropattern; ","; |
| 254 |
tc = LIST1 simple_intropattern SEP "," ; ")" -> |
| 255 |
{ IntroAndPattern (si::tc) } |
| 256 |
| "("; si = simple_intropattern; "&"; |
| 257 |
tc = LIST1 simple_intropattern SEP "&" ; ")" -> |
| 258 |
(* (A & B & C) is translated into (A,(B,C)) *) |
| 259 |
{ let rec pairify = function |
| 260 |
| ([]|[_]|[_;_]) as l -> l |
| 261 |
| t::q -> [t; CAst.make ?loc:(loc_of_ne_list q) (IntroAction (IntroOrAndPattern (IntroAndPattern (pairify q))))] |
| 262 |
in IntroAndPattern (pairify (si::tc)) } ] ] |
| 263 |
; |
| 264 |
equality_intropattern: |
| 265 |
[ [ "->" -> { IntroRewrite true } |
| 266 |
| "<-" -> { IntroRewrite false } |
| 267 |
| test_leftsquarebracket_equal; "["; "="; tc = intropatterns; "]" -> { IntroInjection tc } ] ] |
| 268 |
; |
| 269 |
naming_intropattern: |
| 270 |
[ [ prefix = pattern_ident -> { IntroFresh prefix.CAst.v } |
| 271 |
| "?" -> { IntroAnonymous } |
| 272 |
| id = ident -> { IntroIdentifier id } ] ] |
| 273 |
; |
| 274 |
intropattern: |
| 275 |
[ [ l = simple_intropattern -> { l } |
| 276 |
| "*" -> { CAst.make ~loc @@ IntroForthcoming true } |
| 277 |
| "**" -> { CAst.make ~loc @@ IntroForthcoming false } ] ] |
| 278 |
; |
| 279 |
simple_intropattern: |
| 280 |
[ [ pat = simple_intropattern_closed; |
| 281 |
l = LIST0 ["%"; c = term LEVEL "0" -> { c } ] -> |
| 282 |
{ let {CAst.loc=loc0;v=pat} = pat in |
| 283 |
let f c pat = |
| 284 |
let loc1 = Constrexpr_ops.constr_loc c in |
| 285 |
let loc = Loc.merge_opt loc0 loc1 in |
| 286 |
IntroAction (IntroApplyOn (CAst.(make ?loc:loc1 c),CAst.(make ?loc pat))) in |
| 287 |
CAst.make ~loc @@ List.fold_right f l pat } ] ] |
| 288 |
; |
| 289 |
simple_intropattern_closed: |
| 290 |
[ [ pat = equality_intropattern -> { CAst.make ~loc @@ IntroAction pat } |
| 291 |
| pat = or_and_intropattern -> { CAst.make ~loc @@ IntroAction (IntroOrAndPattern pat) } |
| 292 |
| "_" -> { CAst.make ~loc @@ IntroAction IntroWildcard } |
| 293 |
| pat = naming_intropattern -> { CAst.make ~loc @@ IntroNaming pat } ] ] |
| 294 |
; |
| 295 |
simple_binding: |
| 296 |
[ [ "("; id = identref; ":="; c = lconstr; ")" -> { CAst.make ~loc (NamedHyp id, c) } |
| 297 |
| "("; n = natural; ":="; c = lconstr; ")" -> { CAst.make ~loc (AnonHyp n, c) } ] ] |
| 298 |
; |
| 299 |
bindings: |
| 300 |
[ [ test_lpar_idnum_coloneq; bl = LIST1 simple_binding -> |
| 301 |
{ ExplicitBindings bl } |
| 302 |
| bl = LIST1 constr -> { ImplicitBindings bl } ] ] |
| 303 |
; |
| 304 |
constr_with_bindings: |
| 305 |
[ [ c = constr; l = with_bindings -> { (c, l) } ] ] |
| 306 |
; |
| 307 |
with_bindings: |
| 308 |
[ [ "with"; bl = bindings -> { bl } | -> { NoBindings } ] ] |
| 309 |
; |
| 310 |
hypident: |
| 311 |
[ [ id = id_or_meta -> |
| 312 |
{ let id : lident = id in |
| 313 |
id,InHyp } |
| 314 |
| "("; IDENT "type"; IDENT "of"; id = id_or_meta; ")" -> |
| 315 |
{ let id : lident = id in |
| 316 |
id,InHypTypeOnly } |
| 317 |
| "("; IDENT "value"; IDENT "of"; id = id_or_meta; ")" -> |
| 318 |
{ let id : lident = id in |
| 319 |
id,InHypValueOnly } |
| 320 |
] ] |
| 321 |
; |
| 322 |
hypident_occ: |
| 323 |
[ [ h=hypident; occs=occs -> |
| 324 |
{ let (id,l) = h in |
| 325 |
let id : lident = id in |
| 326 |
((occs,id),l) } ] ] |
| 327 |
; |
| 328 |
in_clause: |
| 329 |
[ [ "*"; occs=occs -> |
| 330 |
{ {onhyps=None; concl_occs=occs} } |
| 331 |
| "*"; "|-"; occs=concl_occ -> |
| 332 |
{ {onhyps=None; concl_occs=occs} } |
| 333 |
| "|-"; occs=concl_occ -> |
| 334 |
{ {onhyps=Some []; concl_occs=occs} } |
| 335 |
| hl = LIST1 hypident_occ SEP ","; "|-"; occs=concl_occ -> |
| 336 |
{ {onhyps=Some hl; concl_occs=occs} } |
| 337 |
| hl = LIST1 hypident_occ SEP "," -> |
| 338 |
{ {onhyps=Some hl; concl_occs=NoOccurrences} } ] ] |
| 339 |
; |
| 340 |
clause_dft_concl: |
| 341 |
[ [ "in"; cl = in_clause -> { cl } |
| 342 |
| occs=occs -> { {onhyps=Some[]; concl_occs=occs} } |
| 343 |
| -> { all_concl_occs_clause } ] ] |
| 344 |
; |
| 345 |
clause_dft_all: |
| 346 |
[ [ "in"; cl = in_clause -> { cl } |
| 347 |
| -> { {onhyps=None; concl_occs=AllOccurrences} } ] ] |
| 348 |
; |
| 349 |
opt_clause: |
| 350 |
[ [ "in"; cl = in_clause -> { Some cl } |
| 351 |
| "at"; occs = occs_nums -> { Some {onhyps=Some[]; concl_occs=occs} } |
| 352 |
| -> { None } ] ] |
| 353 |
; |
| 354 |
concl_occ: |
| 355 |
[ [ "*"; occs = occs -> { occs } |
| 356 |
| -> { NoOccurrences } ] ] |
| 357 |
; |
| 358 |
in_hyp_list: |
| 359 |
[ [ "in"; idl = LIST1 id_or_meta -> { idl } |
| 360 |
| -> { [] } ] ] |
| 361 |
; |
| 362 |
in_hyp_as: |
| 363 |
[ [ "in"; l = LIST1 [id = id_or_meta; ipat = as_ipat -> { (id,ipat) } ] SEP "," -> { l } |
| 364 |
| -> { [] } ] ] |
| 365 |
; |
| 366 |
orient_rw: |
| 367 |
[ [ "->" -> { true } |
| 368 |
| "<-" -> { false } |
| 369 |
| -> { true } ] ] |
| 370 |
; |
| 371 |
simple_binder: |
| 372 |
[ [ na=name -> { ([na],Default Glob_term.Explicit, CAst.make ~loc @@ |
| 373 |
CHole (Some (GBinderType na.CAst.v))) } |
| 374 |
| "("; nal=LIST1 name; ":"; c=lconstr; ")" -> { (nal,Default Glob_term.Explicit,c) } |
| 375 |
] ] |
| 376 |
; |
| 377 |
fixdecl: |
| 378 |
[ [ "("; id = ident; bl=LIST0 simple_binder; ann=struct_annot; |
| 379 |
":"; ty=lconstr; ")" -> { (loc, id, bl, ann, ty) } ] ] |
| 380 |
; |
| 381 |
struct_annot: |
| 382 |
[ [ "{"; IDENT "struct"; id=name; "}" -> { Some id } |
| 383 |
| -> { None } ] ] |
| 384 |
; |
| 385 |
cofixdecl: |
| 386 |
[ [ "("; id = ident; bl=LIST0 simple_binder; ":"; ty=lconstr; ")" -> |
| 387 |
{ (loc, id, bl, None, ty) } ] ] |
| 388 |
; |
| 389 |
bindings_with_parameters: |
| 390 |
[ [ check_for_coloneq; "("; id = ident; bl = LIST0 simple_binder; |
| 391 |
":="; c = lconstr; ")" -> { (id, mkCLambdaN_simple bl c) } ] ] |
| 392 |
; |
| 393 |
eliminator: |
| 394 |
[ [ "using"; el = constr_with_bindings -> { el } ] ] |
| 395 |
; |
| 396 |
as_ipat: |
| 397 |
[ [ "as"; ipat = simple_intropattern -> { Some ipat } |
| 398 |
| -> { None } ] ] |
| 399 |
; |
| 400 |
or_and_intropattern_loc: |
| 401 |
[ [ ipat = or_and_intropattern -> { ArgArg (CAst.make ~loc ipat) } |
| 402 |
| locid = identref -> { ArgVar locid } ] ] |
| 403 |
; |
| 404 |
as_or_and_ipat: |
| 405 |
[ [ "as"; ipat = equality_intropattern -> |
| 406 |
{ match ipat with |
| 407 |
| IntroRewrite _ -> user_err ~loc Pp.(str "Disjunctive/conjunctive pattern expected.") |
| 408 |
| IntroInjection _ -> user_err ~loc Pp.(strbrk "Found an injection pattern while a disjunctive/conjunctive pattern was expected; use " ++ str "\"injection as pattern\"" ++ strbrk " instead.") |
| 409 |
| _ -> assert false } |
| 410 |
| "as"; ipat = or_and_intropattern_loc -> { Some ipat } |
| 411 |
| -> { None } ] ] |
| 412 |
; |
| 413 |
eqn_ipat: |
| 414 |
[ [ IDENT "eqn"; ":"; pat = naming_intropattern -> { Some (CAst.make ~loc pat) } |
| 415 |
| -> { None } ] ] |
| 416 |
; |
| 417 |
as_name: |
| 418 |
[ [ "as"; id = ident -> { Names.Name.Name id } | -> { Names.Name.Anonymous } ] ] |
| 419 |
; |
| 420 |
by_tactic: |
| 421 |
[ [ "by"; tac = ltac_expr LEVEL "3" -> { Some tac } |
| 422 |
| -> { None } ] ] |
| 423 |
; |
| 424 |
rewriter : |
| 425 |
[ [ "!"; c = constr_with_bindings_arg -> { (Equality.RepeatPlus,c) } |
| 426 |
| ["?" -> { () } | LEFTQMARK -> { () } ]; c = constr_with_bindings_arg -> { (Equality.RepeatStar,c) } |
| 427 |
| n = natural; "!"; c = constr_with_bindings_arg -> { (Equality.Precisely n,c) } |
| 428 |
| n = natural; ["?" -> { () } | LEFTQMARK -> { () } ]; c = constr_with_bindings_arg -> { (Equality.UpTo n,c) } |
| 429 |
| n = natural; c = constr_with_bindings_arg -> { (Equality.Precisely n,c) } |
| 430 |
| c = constr_with_bindings_arg -> { (Equality.Precisely 1, c) } |
| 431 |
] ] |
| 432 |
; |
| 433 |
oriented_rewriter : |
| 434 |
[ [ b = orient_rw; p = rewriter -> { let (m,c) = p in (b,m,c) } ] ] |
| 435 |
; |
| 436 |
induction_clause: |
| 437 |
[ [ c = destruction_arg; pat = as_or_and_ipat; eq = eqn_ipat; |
| 438 |
cl = opt_clause -> { (c,(eq,pat),cl) } ] ] |
| 439 |
; |
| 440 |
induction_clause_list: |
| 441 |
[ [ ic = LIST1 induction_clause SEP ","; el = OPT eliminator; |
| 442 |
cl_tolerance = opt_clause -> |
| 443 |
(* Condition for accepting "in" at the end by compatibility *) |
| 444 |
{ match ic,el,cl_tolerance with |
| 445 |
| [c,pat,None],Some _,Some _ -> ([c,pat,cl_tolerance],el) |
| 446 |
| _,_,Some _ -> CErrors.user_err ~loc Pp.(str "Unsupported syntax.") |
| 447 |
| _,_,None -> (ic,el) } ] ] |
| 448 |
; |
| 449 |
simple_tactic: |
| 450 |
[ [ |
| 451 |
(* Basic tactics *) |
| 452 |
IDENT "intros"; pl = ne_intropatterns -> |
| 453 |
{ CAst.make ~loc @@ TacAtom (TacIntroPattern (false,pl)) } |
| 454 |
| IDENT "intros" -> |
| 455 |
{ CAst.make ~loc @@ TacAtom (TacIntroPattern (false,[CAst.make ~loc @@IntroForthcoming false])) } |
| 456 |
| IDENT "eintros"; pl = ne_intropatterns -> |
| 457 |
{ CAst.make ~loc @@ TacAtom (TacIntroPattern (true,pl)) } |
| 458 |
| IDENT "eintros" -> |
| 459 |
{ CAst.make ~loc @@ TacAtom (TacIntroPattern (true,[CAst.make ~loc @@IntroForthcoming false])) } |
| 460 |
|
| 461 |
| IDENT "apply"; cl = LIST1 constr_with_bindings_arg SEP ","; |
| 462 |
inhyp = in_hyp_as -> { CAst.make ~loc @@ TacAtom (TacApply (true,false,cl,inhyp)) } |
| 463 |
| IDENT "eapply"; cl = LIST1 constr_with_bindings_arg SEP ","; |
| 464 |
inhyp = in_hyp_as -> { CAst.make ~loc @@ TacAtom (TacApply (true,true,cl,inhyp)) } |
| 465 |
| IDENT "simple"; IDENT "apply"; |
| 466 |
cl = LIST1 constr_with_bindings_arg SEP ","; |
| 467 |
inhyp = in_hyp_as -> { CAst.make ~loc @@ TacAtom (TacApply (false,false,cl,inhyp)) } |
| 468 |
| IDENT "simple"; IDENT "eapply"; |
| 469 |
cl = LIST1 constr_with_bindings_arg SEP","; |
| 470 |
inhyp = in_hyp_as -> { CAst.make ~loc @@ TacAtom (TacApply (false,true,cl,inhyp)) } |
| 471 |
| IDENT "elim"; cl = constr_with_bindings_arg; el = OPT eliminator -> |
| 472 |
{ CAst.make ~loc @@ TacAtom (TacElim (false,cl,el)) } |
| 473 |
| IDENT "eelim"; cl = constr_with_bindings_arg; el = OPT eliminator -> |
| 474 |
{ CAst.make ~loc @@ TacAtom (TacElim (true,cl,el)) } |
| 475 |
| IDENT "case"; icl = induction_clause_list -> { CAst.make ~loc @@ TacAtom (mkTacCase false icl) } |
| 476 |
| IDENT "ecase"; icl = induction_clause_list -> { CAst.make ~loc @@ TacAtom (mkTacCase true icl) } |
| 477 |
| "fix"; id = ident; n = natural; "with"; fd = LIST1 fixdecl -> |
| 478 |
{ CAst.make ~loc @@ TacAtom (TacMutualFix (id,n,List.map mk_fix_tac fd)) } |
| 479 |
| "cofix"; id = ident; "with"; fd = LIST1 cofixdecl -> |
| 480 |
{ CAst.make ~loc @@ TacAtom (TacMutualCofix (id,List.map mk_cofix_tac fd)) } |
| 481 |
|
| 482 |
| IDENT "pose"; bl = bindings_with_parameters -> |
| 483 |
{ let (id,b) = bl in CAst.make ~loc @@ TacAtom (TacLetTac (false,Names.Name.Name id,b,Locusops.nowhere,true,None)) } |
| 484 |
| IDENT "pose"; b = constr; na = as_name -> |
| 485 |
{ CAst.make ~loc @@ TacAtom (TacLetTac (false,na,b,Locusops.nowhere,true,None)) } |
| 486 |
| IDENT "epose"; bl = bindings_with_parameters -> |
| 487 |
{ let (id,b) = bl in CAst.make ~loc @@ TacAtom (TacLetTac (true,Names.Name id,b,Locusops.nowhere,true,None)) } |
| 488 |
| IDENT "epose"; b = constr; na = as_name -> |
| 489 |
{ CAst.make ~loc @@ TacAtom (TacLetTac (true,na,b,Locusops.nowhere,true,None)) } |
| 490 |
| IDENT "set"; bl = bindings_with_parameters; p = clause_dft_concl -> |
| 491 |
{ let (id,c) = bl in CAst.make ~loc @@ TacAtom (TacLetTac (false,Names.Name.Name id,c,p,true,None)) } |
| 492 |
| IDENT "set"; c = constr; na = as_name; p = clause_dft_concl -> |
| 493 |
{ CAst.make ~loc @@ TacAtom (TacLetTac (false,na,c,p,true,None)) } |
| 494 |
| IDENT "eset"; bl = bindings_with_parameters; p = clause_dft_concl -> |
| 495 |
{ let (id,c) = bl in CAst.make ~loc @@ TacAtom (TacLetTac (true,Names.Name id,c,p,true,None)) } |
| 496 |
| IDENT "eset"; c = constr; na = as_name; p = clause_dft_concl -> |
| 497 |
{ CAst.make ~loc @@ TacAtom (TacLetTac (true,na,c,p,true,None)) } |
| 498 |
| IDENT "remember"; c = constr; na = as_name; e = eqn_ipat; |
| 499 |
p = clause_dft_all -> |
| 500 |
{ CAst.make ~loc @@ TacAtom (TacLetTac (false,na,c,p,false,e)) } |
| 501 |
| IDENT "eremember"; c = constr; na = as_name; e = eqn_ipat; |
| 502 |
p = clause_dft_all -> |
| 503 |
{ CAst.make ~loc @@ TacAtom (TacLetTac (true,na,c,p,false,e)) } |
| 504 |
|
| 505 |
(* Alternative syntax for "pose proof c as id" *) |
| 506 |
| IDENT "assert"; test_lpar_id_coloneq; "("; lid = identref; ":="; |
| 507 |
c = lconstr; ")" -> |
| 508 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (false,true,None,Some (intro_naming_of_lident lid),c)) } |
| 509 |
| IDENT "eassert"; test_lpar_id_coloneq; "("; lid = identref; ":="; |
| 510 |
c = lconstr; ")" -> |
| 511 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (true,true,None,Some (intro_naming_of_lident lid),c)) } |
| 512 |
|
| 513 |
(* Alternative syntax for "assert c as id by tac" *) |
| 514 |
| IDENT "assert"; test_lpar_id_colon; "("; lid = identref; ":"; |
| 515 |
c = lconstr; ")"; tac=by_tactic -> |
| 516 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (false,true,Some tac,Some (intro_naming_of_lident lid),c)) } |
| 517 |
| IDENT "eassert"; test_lpar_id_colon; "("; lid = identref; ":"; |
| 518 |
c = lconstr; ")"; tac=by_tactic -> |
| 519 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (true,true,Some tac,Some (intro_naming_of_lident lid),c)) } |
| 520 |
|
| 521 |
(* Alternative syntax for "enough c as id by tac" *) |
| 522 |
| IDENT "enough"; test_lpar_id_colon; "("; lid = identref; ":"; |
| 523 |
c = lconstr; ")"; tac=by_tactic -> |
| 524 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (false,false,Some tac,Some (intro_naming_of_lident lid),c)) } |
| 525 |
| IDENT "eenough"; test_lpar_id_colon; "("; lid = identref; ":"; |
| 526 |
c = lconstr; ")"; tac=by_tactic -> |
| 527 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (true,false,Some tac,Some (intro_naming_of_lident lid),c)) } |
| 528 |
|
| 529 |
| IDENT "assert"; c = constr; ipat = as_ipat; tac = by_tactic -> |
| 530 |
{ CAst.make ~loc @@ TacAtom (TacAssert (false,true,Some tac,ipat,c)) } |
| 531 |
| IDENT "eassert"; c = constr; ipat = as_ipat; tac = by_tactic -> |
| 532 |
{ CAst.make ~loc @@ TacAtom (TacAssert (true,true,Some tac,ipat,c)) } |
| 533 |
|
| 534 |
(* Alternative syntax for "pose proof c as id by tac" *) |
| 535 |
| IDENT "pose"; IDENT "proof"; test_lpar_id_coloneq; "("; lid = identref; ":="; |
| 536 |
c = lconstr; ")" -> |
| 537 |
{ CAst.make ~loc @@ TacAtom (TacAssert (false,true,None,Some (intro_naming_of_lident lid),c)) } |
| 538 |
| IDENT "epose"; IDENT "proof"; test_lpar_id_coloneq; "("; lid = identref; ":="; |
| 539 |
c = lconstr; ")" -> |
| 540 |
{ CAst.make ~loc @@ TacAtom ( TacAssert (true,true,None,Some (intro_naming_of_lident lid),c)) } |
| 541 |
| IDENT "pose"; IDENT "proof"; c = lconstr; ipat = as_ipat -> |
| 542 |
{ CAst.make ~loc @@ TacAtom (TacAssert (false,true,None,ipat,c)) } |
| 543 |
| IDENT "epose"; IDENT "proof"; c = lconstr; ipat = as_ipat -> |
| 544 |
{ CAst.make ~loc @@ TacAtom (TacAssert (true,true,None,ipat,c)) } |
| 545 |
| IDENT "enough"; c = constr; ipat = as_ipat; tac = by_tactic -> |
| 546 |
{ CAst.make ~loc @@ TacAtom (TacAssert (false,false,Some tac,ipat,c)) } |
| 547 |
| IDENT "eenough"; c = constr; ipat = as_ipat; tac = by_tactic -> |
| 548 |
{ CAst.make ~loc @@ TacAtom (TacAssert (true,false,Some tac,ipat,c)) } |
| 549 |
|
| 550 |
| IDENT "generalize"; c = constr -> |
| 551 |
{ CAst.make ~loc @@ TacAtom (TacGeneralize [((AllOccurrences,c),Names.Name.Anonymous)]) } |
| 552 |
| IDENT "generalize"; c = constr; l = LIST1 constr -> |
| 553 |
{ let gen_everywhere c = ((AllOccurrences,c),Names.Name.Anonymous) in |
| 554 |
CAst.make ~loc @@ TacAtom (TacGeneralize (List.map gen_everywhere (c::l))) } |
| 555 |
| IDENT "generalize"; c = constr; lookup_at_as_comma; nl = occs; |
| 556 |
na = as_name; |
| 557 |
l = LIST0 [","; c = pattern_occ; na = as_name -> { (c,na) } ] -> |
| 558 |
{ CAst.make ~loc @@ TacAtom (TacGeneralize (((nl,c),na)::l)) } |
| 559 |
|
| 560 |
(* Derived basic tactics *) |
| 561 |
| IDENT "induction"; ic = induction_clause_list -> |
| 562 |
{ CAst.make ~loc @@ TacAtom (TacInductionDestruct (true,false,ic)) } |
| 563 |
| IDENT "einduction"; ic = induction_clause_list -> |
| 564 |
{ CAst.make ~loc @@ TacAtom (TacInductionDestruct(true,true,ic)) } |
| 565 |
| IDENT "destruct"; icl = induction_clause_list -> |
| 566 |
{ CAst.make ~loc @@ TacAtom (TacInductionDestruct(false,false,icl)) } |
| 567 |
| IDENT "edestruct"; icl = induction_clause_list -> |
| 568 |
{ CAst.make ~loc @@ TacAtom (TacInductionDestruct(false,true,icl)) } |
| 569 |
|
| 570 |
(* Equality and inversion *) |
| 571 |
| IDENT "rewrite"; l = LIST1 oriented_rewriter SEP ","; |
| 572 |
cl = clause_dft_concl; t=by_tactic -> { CAst.make ~loc @@ TacAtom (TacRewrite (false,l,cl,t)) } |
| 573 |
| IDENT "erewrite"; l = LIST1 oriented_rewriter SEP ","; |
| 574 |
cl = clause_dft_concl; t=by_tactic -> { CAst.make ~loc @@ TacAtom (TacRewrite (true,l,cl,t)) } |
| 575 |
| IDENT "dependent"; k = |
| 576 |
[ IDENT "simple"; IDENT "inversion" -> { SimpleInversion } |
| 577 |
| IDENT "inversion" -> { FullInversion } |
| 578 |
| IDENT "inversion_clear" -> { FullInversionClear } ]; |
| 579 |
hyp = quantified_hypothesis; |
| 580 |
ids = as_or_and_ipat; co = OPT ["with"; c = constr -> { c } ] -> |
| 581 |
{ CAst.make ~loc @@ TacAtom (TacInversion (DepInversion (k,co,ids),hyp)) } |
| 582 |
| IDENT "simple"; IDENT "inversion"; |
| 583 |
hyp = quantified_hypothesis; ids = as_or_and_ipat; |
| 584 |
cl = in_hyp_list -> |
| 585 |
{ CAst.make ~loc @@ TacAtom (TacInversion (NonDepInversion (SimpleInversion, cl, ids), hyp)) } |
| 586 |
| IDENT "inversion"; |
| 587 |
hyp = quantified_hypothesis; ids = as_or_and_ipat; |
| 588 |
cl = in_hyp_list -> |
| 589 |
{ CAst.make ~loc @@ TacAtom (TacInversion (NonDepInversion (FullInversion, cl, ids), hyp)) } |
| 590 |
| IDENT "inversion_clear"; |
| 591 |
hyp = quantified_hypothesis; ids = as_or_and_ipat; |
| 592 |
cl = in_hyp_list -> |
| 593 |
{ CAst.make ~loc @@ TacAtom (TacInversion (NonDepInversion (FullInversionClear, cl, ids), hyp)) } |
| 594 |
| IDENT "inversion"; hyp = quantified_hypothesis; |
| 595 |
"using"; c = constr; cl = in_hyp_list -> |
| 596 |
{ CAst.make ~loc @@ TacAtom (TacInversion (InversionUsing (c,cl), hyp)) } |
| 597 |
|
| 598 |
(* Conversion *) |
| 599 |
| IDENT "red"; cl = clause_dft_concl -> |
| 600 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Red, cl)) } |
| 601 |
| IDENT "hnf"; cl = clause_dft_concl -> |
| 602 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Hnf, cl)) } |
| 603 |
| IDENT "simpl"; h = OPT [ IDENT "head" -> { () } ]; d = delta_flag; |
| 604 |
po = OPT ref_or_pattern_occ; cl = clause_dft_concl -> |
| 605 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Simpl (all_with ~head:(Option.has_some h) d, po), cl)) } |
| 606 |
| IDENT "cbv"; s = strategy_flag; cl = clause_dft_concl -> |
| 607 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Cbv s, cl)) } |
| 608 |
| IDENT "cbn"; s = strategy_flag; cl = clause_dft_concl -> |
| 609 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Cbn s, cl)) } |
| 610 |
| IDENT "lazy"; s = strategy_flag; cl = clause_dft_concl -> |
| 611 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Lazy s, cl)) } |
| 612 |
| IDENT "compute"; delta = delta_flag; cl = clause_dft_concl -> |
| 613 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Cbv (all_with ~head:false delta), cl)) } |
| 614 |
| IDENT "vm_compute"; po = OPT ref_or_pattern_occ; cl = clause_dft_concl -> |
| 615 |
{ CAst.make ~loc @@ TacAtom (TacReduce (CbvVm po, cl)) } |
| 616 |
| IDENT "native_compute"; po = OPT ref_or_pattern_occ; cl = clause_dft_concl -> |
| 617 |
{ CAst.make ~loc @@ TacAtom (TacReduce (CbvNative po, cl)) } |
| 618 |
| IDENT "unfold"; ul = LIST1 unfold_occ SEP ","; cl = clause_dft_concl -> |
| 619 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Unfold ul, cl)) } |
| 620 |
| IDENT "fold"; l = LIST1 constr; cl = clause_dft_concl -> |
| 621 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Fold l, cl)) } |
| 622 |
| IDENT "pattern"; pl = LIST1 pattern_occ SEP","; cl = clause_dft_concl -> |
| 623 |
{ CAst.make ~loc @@ TacAtom (TacReduce (Pattern pl, cl)) } |
| 624 |
|
| 625 |
(* Change ne doit pas s'appliquer dans un Definition t := Eval ... *) |
| 626 |
| IDENT "change"; c = conversion; cl = clause_dft_concl -> |
| 627 |
{ let (oc, c) = c in |
| 628 |
let p,cl = merge_occurrences loc cl oc in |
| 629 |
CAst.make ~loc @@ TacAtom (TacChange (true,p,c,cl)) } |
| 630 |
| IDENT "change_no_check"; c = conversion; cl = clause_dft_concl -> |
| 631 |
{ let (oc, c) = c in |
| 632 |
let p,cl = merge_occurrences loc cl oc in |
| 633 |
CAst.make ~loc @@ TacAtom (TacChange (false,p,c,cl)) } |
| 634 |
] ] |
| 635 |
; |
| 636 |
END |