Debian Codegraph @

plugins/ltac2/g_ltac2.mlg

raw
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.ltac2"
12
13 {
14
15 open Pp
16 open Util
17 open Names
18 open Procq
19 open Procq.Prim
20 open Attributes
21 open Constrexpr
22 open Tac2expr
23 open Tac2qexpr
24 open Stdarg
25
26 let lk_ident_or_anti =
27 Procq.Lookahead.(lk_ident <+> (lk_kw "$" >> lk_ident >> check_no_space))
28
29 (* lookahead for (x:=t), (?x:=t) and (1:=t) *)
30 let test_lpar_idnum_coloneq =
31 let open Procq.Lookahead in
32 to_entry "test_lpar_idnum_coloneq" begin
33 lk_kw "(" >> (lk_ident_or_anti <+> lk_nat) >> lk_kw ":="
34 end
35
36 (* lookahead for (x:t), (?x:t) *)
37 let test_lpar_id_colon =
38 let open Procq.Lookahead in
39 to_entry "test_lpar_id_colon" begin
40 lk_kw "(" >> lk_ident_or_anti >> lk_kw ":"
41 end
42
43 (* Hack to recognize "(x := t)" and "($x := t)" *)
44 let test_lpar_id_coloneq =
45 let open Procq.Lookahead in
46 to_entry "test_lpar_id_coloneq" begin
47 lk_kw "(" >> lk_ident_or_anti >> lk_kw ":="
48 end
49
50 (* Hack to recognize "(x)" *)
51 let test_lpar_id_rpar =
52 let open Procq.Lookahead in
53 to_entry "test_lpar_id_rpar" begin
54 lk_kw "(" >> lk_ident >> lk_kw ")"
55 end
56
57 let test_ampersand_ident =
58 let open Procq.Lookahead in
59 to_entry "test_ampersand_ident" begin
60 lk_kw "&" >> lk_ident >> check_no_space
61 end
62
63 let test_dollar_ident =
64 let open Procq.Lookahead in
65 to_entry "test_dollar_ident" begin
66 lk_kw "$" >> lk_ident >> check_no_space
67 end
68
69 let test_dollar_ident_colon_ident =
70 let open Procq.Lookahead in
71 to_entry "test_dollar_ident_colon_ident" begin
72 lk_kw "$" >> lk_ident >> lk_kw ":" >> lk_ident >> check_no_space
73 end
74
75 let test_ltac1_env =
76 let open Procq.Lookahead in
77 to_entry "test_ltac1_env" begin
78 lk_ident_list >> lk_kw "|-"
79 end
80
81 let test_qualid_with_or_lpar_or_rbrac =
82 let open Procq.Lookahead in
83 to_entry "test_qualid_with_or_lpar_or_rbrac" begin
84 (lk_qualid >> lk_kw "with") <+> lk_kw "(" <+> lk_kw "{"
85 end
86
87 let test_array_opening =
88 let open Procq.Lookahead in
89 to_entry "test_array_opening" begin
90 lk_kw "[" >> lk_kw "|" >> check_no_space
91 end
92
93 let test_array_closing =
94 let open Procq.Lookahead in
95 to_entry "test_array_closing" begin
96 lk_kw "|" >> lk_kw "]" >> check_no_space
97 end
98
99 let test_leftsquarebracket_equal =
100 let open Procq.Lookahead in
101 to_entry "test_leftsquarebracket_equal" begin
102 lk_kw "[" >> lk_kw "=" >> check_no_space
103 end
104
105 let ltac2_expr = Tac2entries.Pltac.ltac2_expr
106 let _ltac2_expr = ltac2_expr
107 let ltac2_type = Entry.make "ltac2_type"
108 let tac2def_val = Entry.make "tac2def_val"
109 let tac2def_typ = Entry.make "tac2def_typ"
110 let tac2def_ext = Entry.make "tac2def_ext"
111 let tac2def_syn = Entry.make "tac2def_syn"
112 let tac2abbrev_syn = Entry.make "tac2abbrev_syn"
113 let tac2def_mut = Entry.make "tac2def_mut"
114 let tac2mode = Entry.make "ltac2_command"
115 let ltac2_atom = Entry.make "ltac2_atom"
116
117 let tac2expr_in_env = Tac2entries.Pltac.tac2expr_in_env
118
119 let quoted_attributes = G_vernac.quoted_attributes
120
121 let inj_wit wit loc x = CAst.make ~loc @@ CTacExt (wit, x)
122 let inj_open_constr loc c = inj_wit Tac2quote.wit_open_constr loc c
123 let inj_pattern loc c = inj_wit Tac2quote.wit_pattern loc c
124 let inj_reference loc c = inj_wit Tac2quote.wit_reference loc c
125
126 let pattern_of_qualid qid =
127 if Tac2env.is_constructor qid then CAst.make ?loc:qid.CAst.loc @@ CPatRef (RelId qid, [])
128 else
129 let open Libnames in
130 if qualid_is_ident qid then CAst.make ?loc:qid.CAst.loc @@ CPatVar (Name (qualid_basename qid))
131 else
132 CErrors.user_err ?loc:qid.CAst.loc (Pp.str "Syntax error")
133
134 let opt_fun ?loc args ty e =
135 let e = match ty with
136 | None -> e
137 | Some ty -> CAst.make ?loc:e.CAst.loc (CTacCnv (e, ty))
138 in
139 match args with
140 | [] -> e
141 | _ :: _ -> CAst.make ?loc (CTacFun (args, e))
142
143 }
144
145 GRAMMAR EXTEND Gram
146 GLOBAL: ltac2_expr ltac2_type tac2def_val tac2def_typ tac2def_ext tac2def_syn tac2abbrev_syn
147 tac2def_mut tac2expr_in_env ltac2_atom;
148 tac2pat:
149 [ "3" LEFTA
150 [ p = tac2pat; "|"; pl = LIST1 tac2pat LEVEL "2" SEP "|" ->
151 { let pl = p :: pl in
152 CAst.make ~loc @@ CPatOr pl }
153 | p = tac2pat; "as"; id = identref -> { CAst.make ~loc @@ CPatAs (p,id) } ]
154 | "2" RIGHTA
155 [ p1 = tac2pat; "::"; p2 = tac2pat ->
156 { CAst.make ~loc @@ CPatRef (AbsKn (Other Tac2quote.Refs.c_cons), [p1; p2])}
157 ]
158 | "1" LEFTA
159 [ qid = Prim.qualid; pl = LIST1 tac2pat LEVEL "0" -> {
160 if Tac2env.is_constructor qid then
161 CAst.make ~loc @@ CPatRef (RelId qid, pl)
162 else
163 CErrors.user_err ~loc (Pp.str "Syntax error") }
164 | qid = Prim.qualid -> { pattern_of_qualid qid }
165 ]
166 | "0"
167 [ "_" -> { CAst.make ~loc @@ CPatVar Anonymous }
168 | "()" -> { CAst.make ~loc @@ CPatRef (AbsKn (Tuple 0), []) }
169 | n = Prim.integer -> { CAst.make ~loc @@ CPatAtm (AtmInt n) }
170 | s = Prim.string -> { CAst.make ~loc @@ CPatAtm (AtmStr s) }
171 | qid = Prim.qualid -> { pattern_of_qualid qid }
172 | "("; p = atomic_tac2pat; ")" -> { p }
173 | "{"; a = tac2rec_fieldpats; "}" -> { CAst.make ~loc @@ CPatRecord a }
174 | "["; pats = LIST0 tac2pat SEP ";"; "]" ->
175 {
176 let nil = CAst.make ~loc @@ CPatRef (AbsKn (Other Tac2quote.Refs.c_nil), []) in
177 let cons hd tl = CAst.make ~loc @@ CPatRef (AbsKn (Other Tac2quote.Refs.c_cons), [hd;tl]) in
178 List.fold_right cons pats nil
179 }
180 ] ]
181 ;
182 atomic_tac2pat:
183 [ [ ->
184 { CAst.make ~loc @@ CPatRef (AbsKn (Tuple 0), []) }
185 | p = tac2pat; ":"; t = ltac2_type ->
186 { CAst.make ~loc @@ CPatCnv (p, t) }
187 | p = tac2pat; ","; pl = LIST0 tac2pat SEP "," ->
188 { let pl = p :: pl in
189 CAst.make ~loc @@ CPatRef (AbsKn (Tuple (List.length pl)), pl) }
190 | p = tac2pat -> { p }
191 ] ]
192 ;
193 ltac2_expr:
194 [ "6" RIGHTA
195 [ e1 = SELF; ";"; e2 = SELF -> { CAst.make ~loc @@ CTacSeq (e1, e2) } ]
196 | "5"
197 [ "fun"; it = LIST1 input_fun; ty = type_cast; "=>"; body = ltac2_expr LEVEL "6" ->
198 { opt_fun ~loc it ty body }
199 | "let"; isrec = rec_flag;
200 lc = LIST1 let_clause SEP "with"; "in";
201 e = ltac2_expr LEVEL "6" ->
202 { CAst.make ~loc @@ CTacLet (isrec, lc, e) }
203 | "match"; e = ltac2_expr LEVEL "5"; "with"; bl = branches; "end" ->
204 { CAst.make ~loc @@ CTacCse (e, bl) }
205 | "if"; e = ltac2_expr LEVEL "5"; "then"; e1 = ltac2_expr LEVEL "5"; "else"; e2 = ltac2_expr LEVEL "5" ->
206 { CAst.make ~loc @@ CTacIft (e, e1, e2) }
207 ]
208 | "4" LEFTA [ ]
209 | "3" [ e0 = SELF; ","; el = LIST1 NEXT SEP "," ->
210 { let el = e0 :: el in
211 CAst.make ~loc @@ CTacApp (CAst.make ~loc @@ CTacCst (AbsKn (Tuple (List.length el))), el) } ]
212 | "2" RIGHTA
213 [ e1 = ltac2_expr; "::"; e2 = ltac2_expr ->
214 { CAst.make ~loc @@ CTacApp (CAst.make ~loc @@ CTacCst (AbsKn (Other Tac2quote.Refs.c_cons)), [e1; e2]) }
215 ]
216 | "1" LEFTA
217 [ e = ltac2_expr; el = LIST1 ltac2_expr LEVEL "0" ->
218 { CAst.make ~loc @@ CTacApp (e, el) }
219 | e = SELF; ".("; qid = Prim.qualid; ")" ->
220 { CAst.make ~loc @@ CTacPrj (e, RelId qid) }
221 | e = SELF; ".("; qid = Prim.qualid; ")"; ":="; r = ltac2_expr LEVEL "5" ->
222 { CAst.make ~loc @@ CTacSet (e, RelId qid, r) } ]
223 | "0"
224 [ "("; a = SELF; ")" -> { a }
225 | "("; a = SELF; ":"; t = ltac2_type; ")" ->
226 { CAst.make ~loc @@ CTacCnv (a, t) }
227 | "()" ->
228 { CAst.make ~loc @@ CTacCst (AbsKn (Tuple 0)) }
229 | "("; ")" ->
230 { CAst.make ~loc @@ CTacCst (AbsKn (Tuple 0)) }
231 | a = array_literal -> { a }
232 | a = list_literal -> { a }
233 | "{"; test_qualid_with_or_lpar_or_rbrac; e = ltac2_expr LEVEL "0"; "with"; a = tac2rec_fieldexprs; "}" ->
234 { CAst.make ~loc @@ CTacRec (Some e, a) }
235 | "{"; a = tac2rec_fieldexprs; "}" ->
236 { CAst.make ~loc @@ CTacRec (None, a) }
237 | a = ltac2_atom -> { a } ]
238 ]
239 ;
240 array_literal:
241 [ [ test_array_opening; "["; "|"; a = LIST0 ltac2_expr LEVEL "5" SEP ";"; test_array_closing; "|"; "]" ->
242 { Tac2quote.array_literal ~loc a } ] ]
243 ;
244 list_literal:
245 [ [ "["; a = LIST0 ltac2_expr LEVEL "5" SEP ";"; "]" ->
246 { Tac2quote.of_list ~loc (fun x -> x) a } ] ]
247 ;
248 branches:
249 [ [ -> { [] }
250 | "|"; bl = LIST1 branch SEP "|" -> { bl }
251 | bl = LIST1 branch SEP "|" -> { bl } ]
252 ]
253 ;
254 branch:
255 [ [ pat = atomic_tac2pat; "=>"; e = ltac2_expr LEVEL "6" -> { (pat, e) } ] ]
256 ;
257 rec_flag:
258 [ [ IDENT "rec" -> { true }
259 | -> { false } ] ]
260 ;
261 mut_flag:
262 [ [ IDENT "mutable" -> { true }
263 | -> { false } ] ]
264 ;
265 ltac2_typevar:
266 [ [ "'"; id = Prim.ident -> { id } ] ]
267 ;
268 ltac2_atom:
269 [ [ n = Prim.integer -> { CAst.make ~loc @@ CTacAtm (AtmInt n) }
270 | s = Prim.string -> { CAst.make ~loc @@ CTacAtm (AtmStr s) }
271 | qid = Prim.qualid ->
272 { if Tac2env.is_constructor qid then
273 CAst.make ~loc @@ CTacCst (RelId qid)
274 else
275 CAst.make ~loc @@ CTacRef (RelId qid) }
276 | "@"; id = Prim.ident -> { Tac2quote.of_ident (CAst.make ~loc id) }
277 | "&"; id = identref -> { Tac2quote.of_hyp ~loc id }
278 | "'"; c = Constr.constr -> { inj_open_constr loc c }
279 | IDENT "constr"; ":"; "("; c = Constr.lconstr; ")" -> { Tac2quote.of_constr c }
280 | IDENT "open_constr"; ":"; "("; c = Constr.lconstr; ")" -> { Tac2quote.of_open_constr c }
281 | IDENT "preterm"; ":"; "("; c = Constr.lconstr; ")" -> { Tac2quote.of_preterm c }
282 | IDENT "ident"; ":"; "("; c = identref; ")" -> { Tac2quote.of_ident c }
283 | IDENT "pat"; ":"; "("; c = Constr.cpattern; ")" -> { inj_pattern loc c }
284 | IDENT "reference"; ":"; "("; c = globref; ")" -> { inj_reference loc c }
285 ] ]
286 ;
287 tac2expr_in_env :
288 [ [ test_ltac1_env; ids = LIST0 identref; "|-"; e = ltac2_expr ->
289 { let check { CAst.v = id; CAst.loc = loc } =
290 if Tac2env.is_constructor (Libnames.qualid_of_ident ?loc id) then
291 CErrors.user_err ?loc Pp.(str "Invalid bound Ltac2 identifier " ++ Id.print id)
292 in
293 let () = List.iter check ids in
294 (ids, e)
295 }
296 | tac = ltac2_expr -> { [], tac }
297 ] ]
298 ;
299 type_cast:
300 [ [ -> { None }
301 | ":"; ty = ltac2_type -> { Some ty }
302 ] ]
303 ;
304 let_clause:
305 [ [ binder = let_binder; ty = type_cast; ":="; te = ltac2_expr ->
306 { let (pat, fn) = binder in
307 let te = opt_fun ~loc fn ty te in
308 (pat, te) }
309 ] ]
310 ;
311 let_binder:
312 [ [ pats = LIST1 input_fun ->
313 { match pats with
314 | [{CAst.v=CPatVar _} as pat] -> (pat, [])
315 | ({CAst.v=CPatVar (Name id)} as pat) :: args -> (pat, args)
316 | [pat] -> (pat, [])
317 | _ -> CErrors.user_err ~loc (str "Invalid pattern") }
318 ] ]
319 ;
320 ltac2_type:
321 [ "5" RIGHTA
322 [ t1 = ltac2_type; "->"; t2 = ltac2_type -> { CAst.make ~loc @@ CTypArrow (t1, t2) } ]
323 | "2"
324 [ t = ltac2_type; "*"; tl = LIST1 ltac2_type LEVEL "1" SEP "*" ->
325 { let tl = t :: tl in
326 CAst.make ~loc @@ CTypRef (AbsKn (Tuple (List.length tl)), tl) } ]
327 | "1" LEFTA
328 [ t = SELF; qid = Prim.qualid -> { CAst.make ~loc @@ CTypRef (RelId qid, [t]) } ]
329 | "0"
330 [ "("; p = LIST1 ltac2_type LEVEL "5" SEP ","; ")"; qid = OPT Prim.qualid ->
331 { match p, qid with
332 | [t], None -> t
333 | _, None -> CErrors.user_err ~loc (Pp.str "Syntax error")
334 | ts, Some qid -> CAst.make ~loc @@ CTypRef (RelId qid, p)
335 }
336 | id = ltac2_typevar -> { CAst.make ~loc @@ CTypVar (Name id) }
337 | "_" -> { CAst.make ~loc @@ CTypVar Anonymous }
338 | qid = Prim.qualid -> { CAst.make ~loc @@ CTypRef (RelId qid, []) }
339 ]
340 ];
341 binder:
342 [ [ "_" -> { CAst.make ~loc Anonymous }
343 | l = Prim.ident -> { CAst.make ~loc (Name l) } ] ]
344 ;
345 input_fun:
346 [ [ b = tac2pat LEVEL "0" -> { b } ] ]
347 ;
348 tac2def_body:
349 [ [ name = binder; it = LIST0 input_fun; ty = type_cast; ":="; e = ltac2_expr ->
350 { (name, opt_fun ~loc it ty e) }
351 ] ]
352 ;
353 tac2def_val:
354 [ [ mut = mut_flag; isrec = rec_flag; l = LIST1 tac2def_body SEP "with" ->
355 { StrVal (mut, isrec, l) }
356 ] ]
357 ;
358 tac2def_mut:
359 [ [ "Set"; qid = Prim.qualid; old = OPT [ "as"; id = identref -> { id } ]; ":="; e = ltac2_expr -> { StrMut (qid, old, e) } ] ]
360 ;
361 tac2typ_knd:
362 [ [ t = ltac2_type -> { CTydDef (Some t) }
363 | "["; ".."; "]" -> { CTydOpn }
364 | "["; t = tac2alg_constructors; "]" -> { CTydAlg t }
365 | "{"; t = tac2rec_fields; "}"-> { CTydRec t } ] ]
366 ;
367 tac2alg_constructors:
368 [ [ "|"; cs = LIST1 tac2alg_constructor SEP "|" -> { cs }
369 | cs = LIST0 tac2alg_constructor SEP "|" -> { cs } ] ]
370 ;
371 tac2alg_constructor:
372 [ [ atts = quoted_attributes; c = Prim.identref -> { (atts, c, []) }
373 | atts = quoted_attributes; c = Prim.identref; "("; args = LIST0 ltac2_type SEP ","; ")" ->
374 { (atts, c, args) } ] ]
375 ;
376 tac2rec_fields:
377 [ RIGHTA [ f = tac2rec_field; ";"; l = tac2rec_fields -> { f :: l }
378 | f = tac2rec_field; ";" -> { [f] }
379 | f = tac2rec_field -> { [f] }
380 | -> { [] } ] ]
381 ;
382 tac2rec_field:
383 [ [ mut = mut_flag; id = Prim.ident; ":"; t = ltac2_type -> { (id, mut, t) } ] ]
384 ;
385 tac2rec_fieldexprs:
386 [ RIGHTA [ f = tac2rec_fieldexpr; ";"; l = tac2rec_fieldexprs -> { f :: l }
387 | f = tac2rec_fieldexpr; ";" -> { [f] }
388 | f = tac2rec_fieldexpr-> { [f] }
389 | -> { [] } ] ]
390 ;
391 tac2rec_fieldexpr:
392 [ [ qid = Prim.qualid; e = OPT [ ":="; e = ltac2_expr LEVEL "1" -> { e } ] ->
393 { let e = match e with
394 | Some e -> e
395 | None ->
396 (* punning: [Foo.bar] becomes [Foo.bar := bar] *)
397 let id = Libnames.qualid_basename qid in
398 CAst.make ~loc @@ CTacRef (RelId (Libnames.qualid_of_ident ~loc id))
399 in
400 RelId qid, e }
401 ] ]
402 ;
403 tac2rec_fieldpats:
404 [ RIGHTA [ f = tac2rec_fieldpat; ";"; l = tac2rec_fieldpats -> { f :: l }
405 | f = tac2rec_fieldpat; ";" -> { [f] }
406 | f = tac2rec_fieldpat-> { [f] }
407 | -> { [] } ] ]
408 ;
409 tac2rec_fieldpat:
410 [ [ qid = Prim.qualid; e = OPT [ ":="; e = tac2pat -> { e } ] ->
411 { let e = match e with
412 | Some e -> e
413 | None ->
414 (* punning: [Foo.bar] becomes [Foo.bar := bar] *)
415 let id = Libnames.qualid_basename qid in
416 CAst.make ~loc @@ CPatVar (Name id)
417 in
418 RelId qid, e }
419 ] ]
420 ;
421 tac2typ_prm:
422 [ [ -> { [] }
423 | id = ltac2_typevar -> { [CAst.make ~loc id] }
424 | "("; ids = LIST1 [ id = ltac2_typevar -> { CAst.make ~loc id } ] SEP "," ;")" -> { ids }
425 ] ]
426 ;
427 tac2typ_def:
428 [ [ prm = tac2typ_prm; id = Prim.qualid; b = tac2type_body -> { let (r, e) = b in (id, r, (prm, e)) } ] ]
429 ;
430 tac2type_body:
431 [ [ -> { false, CTydDef None }
432 | ":="; e = tac2typ_knd -> { false, e }
433 | "::="; e = tac2typ_knd -> { true, e }
434 ] ]
435 ;
436 tac2def_typ:
437 [ [ "Type"; isrec = rec_flag; l = LIST1 tac2typ_def SEP "with" ->
438 { StrTyp (isrec, l) }
439 ] ]
440 ;
441 tac2def_ext:
442 [ [ "@"; IDENT "external"; id = identref; ":"; t = ltac2_type LEVEL "5"; ":=";
443 plugin = Prim.string; name = Prim.string ->
444 { let ml = { mltac_plugin = plugin; mltac_tactic = name } in
445 StrPrm (id, t, ml) }
446 ] ]
447 ;
448 syn_node:
449 [ [ "_" -> { CAst.make ~loc None }
450 | id = qualid -> { CAst.make ~loc (Some id) }
451 ] ]
452 ;
453 ltac2_syntax_class:
454 [ [ s = Prim.string -> { SexprStr (CAst.make ~loc s) }
455 | n = Prim.integer -> { SexprInt (CAst.make ~loc n) }
456 | id = syn_node -> { SexprRec (loc, id, []) }
457 | id = syn_node; "("; tok = LIST1 ltac2_syntax_class SEP "," ; ")" ->
458 { SexprRec (loc, id, tok) }
459 ] ]
460 ;
461 syn_level:
462 [ [ -> { None, None }
463 | ":"; n = Prim.natural -> { None, Some n }
464 | ":"; id = qualid; n = OPT [ "("; n = Prim.natural; ")" -> { n } ] -> { Some id, n }
465 ] ]
466 ;
467 tac2def_syn:
468 [ [ toks = LIST1 ltac2_syntax_class; n = syn_level; ":=";
469 e = ltac2_expr ->
470 { (toks, n, e) }
471 ] ]
472 ;
473 tac2abbrev_syn:
474 [ [ id = Prim.identref; ":="; e = ltac2_expr -> { (id, e) }
475 ] ]
476 ;
477 globref:
478 [ [ "&"; id = Prim.ident -> { CAst.make ~loc (QHypothesis id) }
479 | qid = Prim.qualid -> { CAst.make ~loc @@ QReference qid }
480 ] ]
481 ;
482 END
483
484 (* Quotation entries used by notations *)
485
486 {
487
488 open Tac2entries.Pltac
489
490 }
491
492 GRAMMAR EXTEND Gram
493 GLOBAL: q_ident q_bindings q_intropattern q_intropatterns q_induction_clause
494 q_conversion q_orient q_rewriting q_clause q_dispatch q_occurrences q_strategy_flag
495 q_destruction_arg q_reference q_with_bindings q_constr_matching
496 q_goal_matching q_hintdb q_move_location q_pose q_assert;
497 anti:
498 [ [ "$"; id = Prim.ident -> { QAnti (CAst.make ~loc id) } ] ]
499 ;
500 ident_or_anti:
501 [ [ id = identref -> { QExpr id }
502 | "$"; id = Prim.ident -> { QAnti (CAst.make ~loc id) }
503 ] ]
504 ;
505 lnatural:
506 [ [ n = Prim.natural -> { CAst.make ~loc n } ] ]
507 ;
508 q_ident:
509 [ [ id = ident_or_anti -> { id } ] ]
510 ;
511 qhyp:
512 [ [ x = anti -> { x }
513 | n = lnatural -> { QExpr (CAst.make ~loc @@ QAnonHyp n) }
514 | id = identref -> { QExpr (CAst.make ~loc @@ QNamedHyp id) }
515 ] ]
516 ;
517 simple_binding:
518 [ [ "("; h = qhyp; ":="; c = Constr.lconstr; ")" ->
519 { CAst.make ~loc (h, c) }
520 ] ]
521 ;
522 bindings:
523 [ [ test_lpar_idnum_coloneq; bl = LIST1 simple_binding ->
524 { CAst.make ~loc @@ QExplicitBindings bl }
525 | bl = LIST1 Constr.constr ->
526 { CAst.make ~loc @@ QImplicitBindings bl }
527 ] ]
528 ;
529 q_bindings:
530 [ [ bl = bindings -> { bl } ] ]
531 ;
532 q_with_bindings:
533 [ [ bl = with_bindings -> { bl } ] ]
534 ;
535 intropatterns:
536 [ [ l = LIST0 nonsimple_intropattern -> { CAst.make ~loc l } ] ]
537 ;
538 (* ne_intropatterns: *)
539 (* [ [ l = LIST1 nonsimple_intropattern -> l ]] *)
540 (* ; *)
541 or_and_intropattern:
542 [ [ "["; tc = LIST1 intropatterns SEP "|"; "]" -> { CAst.make ~loc @@ QIntroOrPattern tc }
543 | "()" -> { CAst.make ~loc @@ QIntroAndPattern (CAst.make ~loc []) }
544 | "("; si = simple_intropattern; ")" -> { CAst.make ~loc @@ QIntroAndPattern (CAst.make ~loc [si]) }
545 | "("; si = simple_intropattern; ",";
546 tc = LIST1 simple_intropattern SEP "," ; ")" ->
547 { CAst.make ~loc @@ QIntroAndPattern (CAst.make ~loc (si::tc)) }
548 | "("; si = simple_intropattern; "&";
549 tc = LIST1 simple_intropattern SEP "&" ; ")" ->
550 (* (A & B & C) is translated into (A,(B,C)) *)
551 { let rec pairify = function
552 | ([]|[_]|[_;_]) as l -> CAst.make ~loc l
553 | t::q ->
554 let q =
555 CAst.make ~loc @@
556 QIntroAction (CAst.make ~loc @@
557 QIntroOrAndPattern (CAst.make ~loc @@
558 QIntroAndPattern (pairify q)))
559 in
560 CAst.make ~loc [t; q]
561 in CAst.make ~loc @@ QIntroAndPattern (pairify (si::tc)) } ] ]
562 ;
563 equality_intropattern:
564 [ [ "->" -> { CAst.make ~loc @@ QIntroRewrite true }
565 | "<-" -> { CAst.make ~loc @@ QIntroRewrite false }
566 | test_leftsquarebracket_equal; "["; "="; tc = intropatterns; "]" -> { CAst.make ~loc @@ QIntroInjection tc } ] ]
567 ;
568 naming_intropattern:
569 [ [ LEFTQMARK; id = identref ->
570 { CAst.make ~loc @@ QIntroFresh (QExpr id) }
571 | "?$"; id = identref ->
572 { CAst.make ~loc @@ QIntroFresh (QAnti id) }
573 | "?" ->
574 { CAst.make ~loc @@ QIntroAnonymous }
575 | id = ident_or_anti ->
576 { CAst.make ~loc @@ QIntroIdentifier id }
577 ] ]
578 ;
579 nonsimple_intropattern:
580 [ [ l = simple_intropattern -> { l }
581 | "*" -> { CAst.make ~loc @@ QIntroForthcoming true }
582 | "**" -> { CAst.make ~loc @@ QIntroForthcoming false } ] ]
583 ;
584 simple_intropattern:
585 [ [ pat = simple_intropattern_closed;
586 l = LIST0 [ "%"; c = Constr.term LEVEL "0" -> { c } ] ->
587 { let mk c pat =
588 CAst.make ~loc @@ QIntroAction
589 (CAst.make ~loc @@ QIntroApplyOn (c, pat))
590 in
591 List.fold_right mk l pat
592 }
593 ] ]
594 ;
595 simple_intropattern_closed:
596 [ [ pat = equality_intropattern ->
597 { CAst.make ~loc @@ QIntroAction pat }
598 | pat = or_and_intropattern ->
599 { CAst.make ~loc @@ QIntroAction (CAst.make ~loc @@ QIntroOrAndPattern pat) }
600 | "_" ->
601 { CAst.make ~loc @@ QIntroAction (CAst.make ~loc @@ QIntroWildcard) }
602 | pat = naming_intropattern ->
603 { CAst.make ~loc @@ QIntroNaming pat }
604 ] ]
605 ;
606 q_intropatterns:
607 [ [ ipat = intropatterns -> { ipat } ] ]
608 ;
609 q_intropattern:
610 [ [ ipat = simple_intropattern -> { ipat } ] ]
611 ;
612 nat_or_anti:
613 [ [ n = lnatural -> { QExpr n }
614 | "$"; id = Prim.ident -> { QAnti (CAst.make ~loc id) }
615 ] ]
616 ;
617 eqn_ipat:
618 [ [ IDENT "eqn"; ":"; pat = naming_intropattern -> { Some pat }
619 | -> { None }
620 ] ]
621 ;
622 with_bindings:
623 [ [ "with"; bl = bindings -> { bl } | -> { CAst.make ~loc @@ QNoBindings } ] ]
624 ;
625 constr_with_bindings:
626 [ [ c = Constr.constr; l = with_bindings -> { CAst.make ~loc @@ (c, l) } ] ]
627 ;
628 destruction_arg:
629 [ [ n = lnatural -> { CAst.make ~loc @@ QElimOnAnonHyp n }
630 | id = identref -> { CAst.make ~loc @@ QElimOnIdent id }
631 | c = constr_with_bindings -> { CAst.make ~loc @@ QElimOnConstr c }
632 ] ]
633 ;
634 q_destruction_arg:
635 [ [ arg = destruction_arg -> { arg } ] ]
636 ;
637 as_or_and_ipat:
638 [ [ "as"; ipat = or_and_intropattern -> { Some ipat }
639 | -> { None }
640 ] ]
641 ;
642 occs_nums:
643 [ [ nl = LIST1 nat_or_anti -> { CAst.make ~loc @@ QOnlyOccurrences nl }
644 | "-"; n = nat_or_anti; nl = LIST0 nat_or_anti ->
645 { CAst.make ~loc @@ QAllOccurrencesBut (n::nl) }
646 ] ]
647 ;
648 occs:
649 [ [ "at"; occs = occs_nums -> { occs } | -> { CAst.make ~loc QAllOccurrences } ] ]
650 ;
651 hypident:
652 [ [ id = ident_or_anti ->
653 { id,Locus.InHyp }
654 | "("; IDENT "type"; IDENT "of"; id = ident_or_anti; ")" ->
655 { id,Locus.InHypTypeOnly }
656 | "("; IDENT "value"; IDENT "of"; id = ident_or_anti; ")" ->
657 { id,Locus.InHypValueOnly }
658 ] ]
659 ;
660 hypident_occ:
661 [ [ h=hypident; occs=occs -> { let (id,l) = h in ((occs,id),l) } ] ]
662 ;
663 in_clause:
664 [ [ "*"; occs=occs ->
665 { { q_onhyps = None; q_concl_occs = occs } }
666 | "*"; "|-"; occs = concl_occ ->
667 { { q_onhyps = None; q_concl_occs = occs } }
668 | hl = LIST0 hypident_occ SEP ","; "|-"; occs = concl_occ ->
669 { { q_onhyps = Some hl; q_concl_occs = occs } }
670 | hl = LIST0 hypident_occ SEP "," ->
671 { { q_onhyps = Some hl; q_concl_occs = CAst.make ~loc QNoOccurrences } }
672 ] ]
673 ;
674 clause:
675 [ [ "in"; cl = in_clause -> { CAst.make ~loc @@ cl }
676 | "at"; occs = occs_nums ->
677 { CAst.make ~loc @@ { q_onhyps = Some []; q_concl_occs = occs } }
678 ] ]
679 ;
680 q_clause:
681 [ [ cl = clause -> { cl } ] ]
682 ;
683 concl_occ:
684 [ [ "*"; occs = occs -> { occs }
685 | -> { CAst.make ~loc QNoOccurrences }
686 ] ]
687 ;
688 induction_clause:
689 [ [ c = destruction_arg; pat = as_or_and_ipat; eq = eqn_ipat;
690 cl = OPT clause ->
691 { CAst.make ~loc @@ {
692 indcl_arg = c;
693 indcl_eqn = eq;
694 indcl_as = pat;
695 indcl_in = cl;
696 } }
697 ] ]
698 ;
699 q_induction_clause:
700 [ [ cl = induction_clause -> { cl } ] ]
701 ;
702 conversion:
703 [ [ c = Constr.constr ->
704 { CAst.make ~loc @@ QConvert c }
705 | c1 = Constr.constr; "with"; c2 = Constr.constr ->
706 { CAst.make ~loc @@ QConvertWith (c1, c2) }
707 ] ]
708 ;
709 q_conversion:
710 [ [ c = conversion -> { c } ] ]
711 ;
712 q_orient:
713 [ [ "->" -> { CAst.make ~loc (Some true) }
714 | "<-" -> { CAst.make ~loc (Some false) }
715 | -> { CAst.make ~loc None }
716 ]]
717 ;
718 rewriter:
719 [ [ "!"; c = constr_with_bindings ->
720 { (CAst.make ~loc @@ QRepeatPlus,c) }
721 | [ "?" -> { () } | LEFTQMARK -> { () } ]; c = constr_with_bindings ->
722 { (CAst.make ~loc @@ QRepeatStar,c) }
723 | n = lnatural; "!"; c = constr_with_bindings ->
724 { (CAst.make ~loc @@ QPrecisely n,c) }
725 | n = lnatural; ["?" -> { () } | LEFTQMARK -> { () } ]; c = constr_with_bindings ->
726 { (CAst.make ~loc @@ QUpTo n,c) }
727 | n = lnatural; c = constr_with_bindings ->
728 { (CAst.make ~loc @@ QPrecisely n,c) }
729 | c = constr_with_bindings ->
730 { (CAst.make ~loc @@ QPrecisely (CAst.make 1), c) }
731 ] ]
732 ;
733 oriented_rewriter:
734 [ [ b = q_orient; r = rewriter ->
735 { let (m, c) = r in
736 CAst.make ~loc @@ {
737 rew_orient = b;
738 rew_repeat = m;
739 rew_equatn = c;
740 } }
741 ] ]
742 ;
743 q_rewriting:
744 [ [ r = oriented_rewriter -> { r } ] ]
745 ;
746 tactic_then_last:
747 [ [ "|"; lta = LIST0 (OPT ltac2_expr LEVEL "6") SEP "|" -> { lta }
748 | -> { [] }
749 ] ]
750 ;
751 for_each_goal:
752 [ RIGHTA [ ta = ltac2_expr; "|"; tg = for_each_goal -> { let (first,last) = tg in (Some ta :: first, last) }
753 | ta = ltac2_expr; ".."; l = tactic_then_last -> { ([], Some (Some ta, l)) }
754 | ".."; l = tactic_then_last -> { ([], Some (None, l)) }
755 | ta = ltac2_expr -> { ([Some ta], None) }
756 | "|"; tg = for_each_goal -> { let (first,last) = tg in (None :: first, last) }
757 | -> { ([None], None) }
758 ] ]
759 ;
760 q_dispatch:
761 [ [ d = for_each_goal -> { CAst.make ~loc d } ] ]
762 ;
763 q_occurrences:
764 [ [ occs = occs -> { occs } ] ]
765 ;
766 ltac2_red_flag:
767 [ [ IDENT "beta" -> { CAst.make ~loc @@ QBeta }
768 | IDENT "iota" -> { CAst.make ~loc @@ QIota }
769 | IDENT "match" -> { CAst.make ~loc @@ QMatch }
770 | IDENT "fix" -> { CAst.make ~loc @@ QFix }
771 | IDENT "cofix" -> { CAst.make ~loc @@ QCofix }
772 | IDENT "zeta" -> { CAst.make ~loc @@ QZeta }
773 | IDENT "delta"; d = delta_flag -> { d }
774 | IDENT "head" -> { CAst.make ~loc @@ QHead }
775 ] ]
776 ;
777 refglobal:
778 [ [ "&"; id = Prim.ident -> { QExpr (CAst.make ~loc @@ QHypothesis id) }
779 | qid = Prim.qualid -> { QExpr (CAst.make ~loc @@ QReference qid) }
780 | "$"; id = Prim.ident -> { QAnti (CAst.make ~loc id) }
781 ] ]
782 ;
783 q_reference:
784 [ [ r = refglobal -> { r } ] ]
785 ;
786 refglobals:
787 [ [ gl = LIST1 refglobal -> { CAst.make ~loc gl } ] ]
788 ;
789 delta_flag:
790 [ [ "-"; "["; idl = refglobals; "]" -> { CAst.make ~loc @@ QDeltaBut idl }
791 | "["; idl = refglobals; "]" -> { CAst.make ~loc @@ QConst idl }
792 | -> { CAst.make ~loc @@ QDeltaBut (CAst.make ~loc []) }
793 ] ]
794 ;
795 strategy_flag:
796 [ [ s = LIST1 ltac2_red_flag -> { CAst.make ~loc s }
797 | d = delta_flag ->
798 { CAst.make ~loc
799 [CAst.make ~loc QBeta; CAst.make ~loc QIota; CAst.make ~loc QZeta; d] }
800 ] ]
801 ;
802 q_strategy_flag:
803 [ [ flag = strategy_flag -> { flag } ] ]
804 ;
805 hintdb:
806 [ [ "*" -> { CAst.make ~loc @@ QHintAll }
807 | l = LIST1 ident_or_anti -> { CAst.make ~loc @@ QHintDbs l }
808 ] ]
809 ;
810 q_hintdb:
811 [ [ db = hintdb -> { db } ] ]
812 ;
813 match_pattern:
814 [ [ IDENT "context"; id = OPT Prim.ident;
815 "["; pat = Constr.cpattern; "]" -> { CAst.make ~loc @@ QConstrMatchContext (id, pat) }
816 | pat = Constr.cpattern -> { CAst.make ~loc @@ QConstrMatchPattern pat } ] ]
817 ;
818 match_rule:
819 [ [ mp = match_pattern; "=>"; tac = ltac2_expr ->
820 { CAst.make ~loc @@ (mp, tac) }
821 ] ]
822 ;
823 match_list:
824 [ [ mrl = LIST1 match_rule SEP "|" -> { CAst.make ~loc @@ mrl }
825 | "|"; mrl = LIST1 match_rule SEP "|" -> { CAst.make ~loc @@ mrl } ] ]
826 ;
827 q_constr_matching:
828 [ [ m = match_list -> { m } ] ]
829 ;
830 gmatch_hyp_pattern:
831 [ [ na = Prim.name; ":"; pat = match_pattern -> { (na, None, pat) }
832 | na = Prim.name; ":="; "["; bod = match_pattern; "]"; ":"; pat = match_pattern ->
833 { (na, Some bod, pat) }
834 | na = Prim.name; ":="; bod = match_pattern ->
835 { let bod, ty = match bod.CAst.v with
836 | QConstrMatchPattern { CAst.v = CCast (t, Some DEFAULTcast, ty) } ->
837 let t = CAst.make ?loc:t.loc @@ QConstrMatchPattern t in
838 let ty = CAst.make ?loc:ty.loc @@ QConstrMatchPattern ty in
839 t, ty
840 | _ ->
841 let ty = CAst.make @@ QConstrMatchPattern (CAst.make @@ CHole None) in
842 bod, ty
843 in
844 (na, Some bod, ty) }
845 ] ]
846 ;
847 gmatch_pattern:
848 [ [ "["; hl = LIST0 gmatch_hyp_pattern SEP ","; "|-"; p = match_pattern; "]" ->
849 { CAst.make ~loc @@ {
850 q_goal_match_concl = p;
851 q_goal_match_hyps = hl;
852 } }
853 ] ]
854 ;
855 gmatch_rule:
856 [ [ mp = gmatch_pattern; "=>"; tac = ltac2_expr ->
857 { CAst.make ~loc @@ (mp, tac) }
858 ] ]
859 ;
860 goal_match_list:
861 [ [ OPT "|"; mrl = LIST1 gmatch_rule SEP "|" -> { CAst.make ~loc @@ mrl } ] ]
862 ;
863 q_goal_matching:
864 [ [ m = goal_match_list -> { m } ] ]
865 ;
866 move_location:
867 [ [ "at"; IDENT "top" -> { CAst.make ~loc @@ QMoveFirst }
868 | "at"; IDENT "bottom" -> { CAst.make ~loc @@ QMoveLast }
869 | IDENT "after"; id = ident_or_anti -> { CAst.make ~loc @@ QMoveAfter id }
870 | IDENT "before"; id = ident_or_anti -> { CAst.make ~loc @@ QMoveBefore id }
871 ] ]
872 ;
873 q_move_location:
874 [ [ mv = move_location -> { mv } ] ]
875 ;
876 as_name:
877 [ [ -> { None }
878 | "as"; id = ident_or_anti -> { Some id }
879 ] ]
880 ;
881 pose:
882 [ [ test_lpar_id_coloneq; "("; id = ident_or_anti; ":="; c = Constr.lconstr; ")" ->
883 { CAst.make ~loc (Some id, c) }
884 | c = Constr.constr; na = as_name -> { CAst.make ~loc (na, c) }
885 ] ]
886 ;
887 q_pose:
888 [ [ p = pose -> { p } ] ]
889 ;
890 as_ipat:
891 [ [ "as"; ipat = simple_intropattern -> { Some ipat }
892 | -> { None }
893 ] ]
894 ;
895 by_tactic:
896 [ [ "by"; tac = ltac2_expr LEVEL "5" -> { Some tac }
897 | -> { None }
898 ] ]
899 ;
900 assertion:
901 [ [ test_lpar_id_coloneq; "("; id = ident_or_anti; ":="; c = Constr.lconstr; ")" ->
902 { CAst.make ~loc (QAssertValue (id, c)) }
903 | test_lpar_id_colon; "("; id = ident_or_anti; ":"; c = Constr.lconstr; ")"; tac = by_tactic ->
904 { let ipat = CAst.make ~loc @@ QIntroNaming (CAst.make ~loc @@ QIntroIdentifier id) in
905 CAst.make ~loc (QAssertType (Some ipat, c, tac)) }
906 | c = Constr.constr; ipat = as_ipat; tac = by_tactic ->
907 { CAst.make ~loc (QAssertType (ipat, c, tac)) }
908 ] ]
909 ;
910 q_assert:
911 [ [ a = assertion -> { a } ] ]
912 ;
913 END
914
915 (** Extension of constr syntax *)
916
917 (*
918 GRAMMAR EXTEND Gram
919 Procq.Constr.term: LEVEL "0"
920 [ [ IDENT "ltac2"; ":"; "("; tac = ltac2_expr; ")" ->
921 { let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_constr) tac in
922 CAst.make ~loc (CGenarg arg) }
923 | test_ampersand_ident; "&"; id = Prim.ident ->
924 { let tac = Tac2quote.of_exact_hyp ~loc (CAst.make ~loc id) in
925 let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_constr) tac in
926 CAst.make ~loc (CGenarg arg) }
927 | test_dollar_ident; "$"; id = Prim.ident ->
928 { let id = Loc.tag ~loc id in
929 let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_quotation) id in
930 CAst.make ~loc (CGenarg arg) }
931 ] ]
932 ;
933 END
934 *)
935 {
936
937 let () =
938
939 let open Tok in
940 let (++) r s = Procq.Rule.next r s in
941 let rules = [
942 Procq.(
943 Production.make
944 (Rule.stop ++ Symbol.nterm test_dollar_ident ++ Symbol.token (PKEYWORD "$") ++ Symbol.nterm Prim.ident)
945 begin fun id _ _ loc ->
946 let id = CAst.make ~loc id in
947 let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_var_quotation) (None, id) in
948 CAst.make ~loc (CGenarg arg)
949 end
950 );
951
952 Procq.(
953 Production.make
954 (Rule.stop ++ Symbol.nterm test_dollar_ident_colon_ident ++
955 Symbol.token (PKEYWORD "$") ++ Symbol.nterm Prim.identref ++
956 Symbol.token (PKEYWORD ":") ++ Symbol.nterm Prim.identref)
957 begin fun id _ kind _ _ loc ->
958 let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_var_quotation) (Some kind, id) in
959 CAst.make ~loc (CGenarg arg)
960 end
961 );
962
963 Procq.(
964 Production.make
965 (Rule.stop ++ Symbol.nterm test_ampersand_ident ++ Symbol.token (PKEYWORD "&") ++ Symbol.nterm Prim.ident)
966 begin fun id _ _ loc ->
967 let tac = Tac2quote.of_exact_hyp ~loc (CAst.make ~loc id) in
968 let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_constr) tac in
969 CAst.make ~loc (CGenarg arg)
970 end
971 );
972
973 Procq.(
974 Production.make
975 (Rule.stop ++ Symbol.token (PIDENT (Some "ltac2")) ++ Symbol.token (PKEYWORD ":") ++
976 Symbol.token (PKEYWORD "(") ++ Symbol.nterm ltac2_expr ++ Symbol.token (PKEYWORD ")"))
977 begin fun _ tac _ _ _ loc ->
978 let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_constr) tac in
979 CAst.make ~loc (CGenarg arg)
980 end
981 )
982 ] in
983
984 Egramml.grammar_extend ~ignore_kw:false ~plugin_uid:("rocq-runtime.plugins.ltac2", "g_ltac2.mlg:adhoc1")
985 Procq.Constr.term (Procq.Reuse (Some"0", rules))
986
987
988 }
989
990 {
991
992 let pr_ltac2entry = Tac2print.pr_strexpr
993 let pr_ltac2expr e = Tac2print.pr_rawexpr_gen E5 ~avoid:Id.Set.empty e
994 let pr_ltac2def_syn (a,b,c) = Tac2entries.pr_register_notation a b c
995 let pr_ltac2abbrev_syn (a,c) = Tac2entries.pr_register_abbreviation a c
996
997 }
998
999 VERNAC ARGUMENT EXTEND ltac2_entry
1000 PRINTED BY { pr_ltac2entry }
1001 | [ tac2def_val(v) ] -> { v }
1002 | [ tac2def_typ(t) ] -> { t }
1003 | [ tac2def_ext(e) ] -> { e }
1004 | [ tac2def_mut(e) ] -> { e }
1005 END
1006
1007 VERNAC ARGUMENT EXTEND ltac2def_syn
1008 PRINTED BY { pr_ltac2def_syn }
1009 | [ tac2def_syn(e) ] -> { e }
1010 END
1011
1012 VERNAC ARGUMENT EXTEND ltac2abbrev_syn
1013 PRINTED BY { pr_ltac2abbrev_syn }
1014 | [ tac2abbrev_syn(e) ] -> { e }
1015 END
1016
1017 VERNAC ARGUMENT EXTEND ltac2_expr
1018 PRINTED BY { pr_ltac2expr }
1019 | [ _ltac2_expr(e) ] -> { e }
1020 END
1021
1022 {
1023
1024 let names_of_strexpr = function
1025 | StrVal(_, _, l) ->
1026 List.concat_map (fun (na, _) -> match na.CAst.v with Anonymous -> [] | Name id -> [id]) l
1027 | StrTyp(_, l) ->
1028 List.map (fun (qid, _, _) -> Libnames.qualid_basename qid) l
1029 | _ -> []
1030
1031 }
1032
1033 VERNAC COMMAND EXTEND VernacDeclareTactic2Definition
1034 | #[ raw_attributes ] [ "Ltac2" ltac2_entry(e) ] => {
1035 VtSideff (names_of_strexpr e, VtLater)
1036 } -> {
1037 Tac2entries.register_struct raw_attributes e
1038 }
1039 | [ "Ltac2" "Import" "Type" reference(qid) "as" ident(id) ] => {
1040 VtSideff ([id], VtLater)
1041 } -> {
1042 Tac2entries.import_type qid id
1043 }
1044 | [ "Ltac2" "Custom" "Entry" identref(id) ] => { Vernacextend.(VtSideff ([], VtNow)) } SYNTERP AS _ {
1045 Tac2entries.register_custom_entry id
1046 } -> {
1047 ()
1048 }
1049 | #[ raw_attributes ] [ "Ltac2" "Notation" ltac2def_syn(e) ] => { Vernacextend.(VtSideff ([], VtNow)) } SYNTERP AS synterpv {
1050 let (toks, n, body) = e in
1051 Tac2entries.register_notation raw_attributes toks n body
1052 } ->
1053 {
1054 Tac2entries.register_notation_interpretation synterpv
1055 }
1056 | #[ raw_attributes ] [ "Ltac2" "Abbreviation" ltac2abbrev_syn(e) ] => { Vernacextend.(VtSideff ([], VtNow)) } SYNTERP AS synterpv {
1057 let (id, body) = e in
1058 Tac2entries.register_abbreviation raw_attributes id body
1059 } ->
1060 {
1061 Tac2entries.register_notation_interpretation synterpv
1062 }
1063 | ![proof_opt_query] [ "Ltac2" "Eval" ltac2_expr(e) ] => { Vernacextend.classify_as_query } -> {
1064 fun ~pstate -> Tac2entries.perform_eval ~pstate e
1065 }
1066 END
1067
1068 {
1069
1070 let _ : Pvernac.proof_mode = Pvernac.register_proof_mode "Ltac2"
1071 (ProofMode {
1072 command_entry = tac2mode;
1073 wit_tactic_expr = Tac2env.wit_ltac2_tac;
1074 tactic_expr_entry = ltac2_expr;
1075 })
1076
1077 open Vernacextend
1078
1079 let toplevel_selector = G_vernac.toplevel_selector
1080
1081 let pr_ltac2_selector s = Pp.(Goal_select.pr_goal_selector s ++ str ":")
1082
1083 let pr_ltac2_use_default b =
1084 if b.CAst.v then (* Bug: a space is inserted before "..." *) str ".." else mt ()
1085
1086 let subprf = G_vernac.subprf
1087 let subprf_with_selector = G_vernac.subprf_with_selector
1088
1089 }
1090
1091 VERNAC ARGUMENT EXTEND ltac2_selector PRINTED BY { pr_ltac2_selector }
1092 | [ toplevel_selector(s) ] -> { s }
1093 END
1094
1095 VERNAC ARGUMENT EXTEND ltac2_use_default PRINTED BY { pr_ltac2_use_default }
1096 | [ "." ] -> { CAst.make ~loc false }
1097 | [ "..." ] -> { CAst.make ~loc true }
1098 END
1099
1100 VERNAC { tac2mode } EXTEND VernacLtac2
1101 | ![proof] [ ltac2_selector_opt(g) ltac2_expr(t) ltac2_use_default(with_end_tac) ] =>
1102 { classify_as_proofstep } -> { fun ~pstate ->
1103 Tac2entries.call ~pstate g ~with_end_tac t
1104 }
1105 | ![proof] [ "par" ":" ltac2_expr(t) "." ] =>
1106 { classify_as_proofstep } -> { fun ~pstate ->
1107 Tac2entries.call_par ~pstate t
1108 }
1109 END
1110
1111 GRAMMAR EXTEND Gram
1112 GLOBAL: tac2mode;
1113 tac2mode: TOP
1114 [ [ p = subprf -> { Vernacexpr.VernacSynPure p }
1115 | g = OPT toplevel_selector; p = subprf_with_selector -> { Vernacexpr.VernacSynPure (p g) }
1116 ] ];
1117 END
1118
1119 {
1120
1121 let test_ltac2_ident_aux =
1122 let open Procq.Lookahead in
1123 to_entry "test_ltac2_ident" begin
1124 lk_kw "Ltac2" >> lk_ident
1125 end
1126
1127 }
1128
1129 VERNAC ARGUMENT EXTEND test_ltac2_ident PRINTED BY { fun _ -> Pp.mt() }
1130 | [ test_ltac2_ident_aux(x) ] -> { x }
1131 END
1132
1133 VERNAC COMMAND EXTEND Ltac2Printers CLASSIFIED AS QUERY
1134 | [ "Print" test_ltac2_ident(_test) "Ltac2" reference(tac) ] -> { Tac2entries.print_ltac2 tac }
1135 | [ "Print" "Ltac2" "Type" reference(tac) ] -> { Tac2entries.print_ltac2_type tac }
1136 | [ "Locate" "Ltac2" reference(r) ] -> { Tac2entries.print_located_tactic r }
1137 | [ "Print" "Ltac2" "Signatures" ] -> { Tac2entries.print_signatures () }
1138 | [ "Ltac2" "Check" ltac2_expr(e) ] -> { Tac2entries.typecheck_expr e }
1139 | [ "Ltac2" "Globalize" ltac2_expr(e) ] -> { Tac2entries.globalize_expr e }
1140 END