Debian Codegraph @

src/rocq_elpi_vernacular_syntax.mlg

raw
1 (* rocq-elpi: Coq terms as the object language of elpi *)
2 (* license: GNU Lesser General Public License Version 2.1 or later *)
3 (* ------------------------------------------------------------------------- *)
4
5 DECLARE PLUGIN "rocq-elpi.elpi"
6
7 {
8
9 open Stdarg
10 open Ltac_plugin
11
12 open Procq.Constr
13
14 open Rocq_elpi_arg_syntax
15 module EV = Rocq_elpi_vernacular
16 module EA = Rocq_elpi_arg_HOAS
17 module U = Rocq_elpi_utils
18
19 }
20
21 (* Anti-quotation ******************************************************** *)
22
23 {
24 [%%if coq = "9.0" || coq = "9.1" || coq = "9.2"]
25 let pr_elpi_code _ _ _ (s : Elpi.API.Ast.Loc.t * string) = Pp.str (snd s)
26 }
27
28 ARGUMENT EXTEND elpi_code
29 PRINTED BY { pr_elpi_code }
30 END
31 {
32 let () = Rocq_elpi_glob_quotation.is_elpi_code_r :=
33 (fun x -> Genarg.(has_type x (glbwit wit_elpi_code)))
34 let () = Rocq_elpi_glob_quotation.get_elpi_code_r :=
35 (fun x -> Genarg.(out_gen (glbwit wit_elpi_code) x))
36
37 let pr_elpi_code_appArg _ _ _ (s : Elpi.API.Ast.Loc.t * string list) = Pp.prlist Pp.str (snd s)
38 }
39
40 ARGUMENT EXTEND elpi_code_appArg
41 PRINTED BY { pr_elpi_code_appArg }
42 END
43 {
44
45 let () = Rocq_elpi_glob_quotation.is_elpi_code_appArg_r :=
46 (fun x -> Genarg.(has_type x (glbwit wit_elpi_code_appArg )))
47 let () = Rocq_elpi_glob_quotation.get_elpi_code_appArg_r :=
48 (fun x -> Genarg.(out_gen (glbwit wit_elpi_code_appArg ) x))
49
50 let mk_elpi_code x = Genarg.in_gen (Genarg.rawwit wit_elpi_code) x
51 let mk_elpi_code_appArg x = Genarg.in_gen (Genarg.rawwit wit_elpi_code_appArg) x
52 [%%else]
53 let mk_elpi_code x = GenConstr.Raw (Rocq_elpi_glob_quotation.elpi_code_tag, x)
54 let mk_elpi_code_appArg x = GenConstr.Raw (Rocq_elpi_glob_quotation.elpi_code_appArg_tag, x)
55 [%%endif]
56
57 let pr_ghost_loc _ _ _ loc = Loc.pr loc
58 }
59
60 ARGUMENT EXTEND ghost PRINTED BY { pr_ghost_loc }
61 | [ ] -> { loc }
62 END
63
64 {
65
66 let rec inlogpath q = function
67 | [] -> []
68 | x :: xs -> (Libnames.string_of_qualid q ^ "/" ^ x) :: inlogpath q xs
69
70 let warning_legacy_typecheck =
71 CWarnings.create ~name:"elpi.typecheck-syntax" ~category:Rocq_elpi_utils.elpi_depr_cat (fun () ->
72 Pp.strbrk "The command 'Elpi Typecheck' is deprecated (and does nothing) since type checking is now performed by 'Elpi Accumulate'.")
73
74 let warning_legacy_accumulate_gen =
75 CWarnings.create ~default:CWarnings.AsError ~name:"elpi.accumulate-syntax" ~category:Rocq_elpi_utils.elpi_depr_cat (fun has_from ->
76 if has_from then
77 Pp.strbrk "The syntax 'Elpi Accumulate File \"path\"' is deprecated, use 'Elpi Accumulate File \"path\" From logpath'"
78 else Pp.strbrk "The syntax 'Elpi Accumulate File \"path\" From logpath' is deprecated, use 'From logpath Extra Dependency \"path\" as name. Elpi Accumulate File name.'")
79
80 let warning_legacy_accumulate ?loc () = warning_legacy_accumulate_gen ?loc true
81 let warning_legacy_accumulate2 ?loc () = warning_legacy_accumulate_gen ?loc false
82
83 let lib_ref id =
84 let id = String.concat "." (snd id) in
85 try Rocqlib.lib_ref id
86 with Rocqlib.NotFoundRef _ ->
87 CErrors.user_err
88 Pp.(str "Global reference not found: lib:" ++ str id
89 ++ str " (you may need to require some .v file with \
90 `Register ... as " ++ str id ++ str ".`).")
91
92 [%%if coq = "9.0" || coq = "9.1"]
93 let lookahead_lib_colon kwstate strm =
94 match Gramlib.LStream.peek_nth kwstate 0 strm with
95 | Tok.IDENT "lib" ->
96 (match Gramlib.LStream.peek_nth kwstate 1 strm with
97 | Tok.KEYWORD ":" -> ()
98 | _ -> streamFail ())
99 | _ -> streamFail ()
100 [%%else]
101 let lookahead_lib_colon kwstate strm =
102 match Gramlib.LStream.peek_nth kwstate 0 strm with
103 | Some (Tok.IDENT "lib") ->
104 (match Gramlib.LStream.peek_nth kwstate 1 strm with
105 | Some (Tok.KEYWORD ":") -> streamOk ()
106 | _ -> streamFail ())
107 | _ -> streamFail ()
108 [%%endif]
109
110 let lookahead_lib_colon = Procq.Entry.(of_parser "lookahead_lib_colon" { parser_fun = lookahead_lib_colon })
111
112 let idents_of loc s =
113 let s = String.sub s 1 (String.length s - 2) in
114 let l = Str.(split (regexp "[\t \n]+") s) in
115 List.iter (fun x ->
116 if not (CLexer.is_ident x) then
117 CErrors.user_err
118 Pp.(str "Expected ident list after \"lp:(\" but " ++
119 quote (str x) ++ str " is not an ident."))
120 l;
121 Rocq_elpi_utils.of_coq_loc (trim_loc loc), l
122
123 }
124 GRAMMAR EXTEND Gram
125 GLOBAL: term;
126
127 term: LEVEL "0"
128 [ [ s = QUOTATION "lp:" ->
129 {
130 let loc = { loc with Loc.bp = loc.Loc.bp + 3 } in
131 let mk mk0 v = CAst.make ~loc @@ Constrexpr.CGenarg (mk0 v) in
132 if s.[0] = '('
133 then mk mk_elpi_code_appArg (idents_of loc s)
134 else if s.[0] = '\123'
135 then mk mk_elpi_code (strip_curly loc s)
136 else mk mk_elpi_code (Rocq_elpi_utils.of_coq_loc loc,s) }
137 ] ]
138 ;
139 END
140
141 GRAMMAR EXTEND Gram
142 GLOBAL: term;
143
144 term: LEVEL "0"
145 [ [ lookahead_lib_colon;IDENT "lib"; ":"; id = qualified_name -> {
146 let ref = lib_ref id in
147 let path = Nametab.path_of_global ref in
148 CAst.make ~loc Constrexpr.(CRef (Libnames.qualid_of_path ~loc:(fst id) path,None)) }
149 | lookahead_lib_colon;IDENT "lib"; ":"; "@"; id = qualified_name -> {
150 let ref = lib_ref id in
151 let path = Nametab.path_of_global ref in
152 let f = Libnames.qualid_of_path ~loc:(fst id) path in
153 CAst.make ~loc Constrexpr.(CAppExpl((f,None),[])) } ] ]
154 ;
155 END
156
157 (* Syntax **************************************************************** *)
158
159 {
160 let classify_named_vernac (_,p) = Vernacextend.VtSideff([Names.Id.of_string_soft @@ String.concat "." p],VtNow)
161 }
162
163 VERNAC COMMAND EXTEND ElpiNamed
164 | #[ atts = any_attribute ] [ "Elpi" "Program" ghost(gloc0) qualified_name(p) elpi_string(s) ghost(gloc1) ] => { classify_named_vernac p } SYNTERP AS atts
165 {
166 let gloc = Loc.merge gloc0 gloc1 in
167 let atts = validate_attributes raw_args_attributes atts in
168 EV.Synterp.create_program ~atts ~loc:gloc ~init:s p;
169 atts
170 } -> {
171 let gloc = Loc.merge gloc0 gloc1 in
172 EV.Interp.create_program ~atts ~loc:gloc ~init:s p
173 }
174 | #[ atts = any_attribute ] [ "Elpi" "Command" ghost(gloc0) qualified_name(p) ghost(gloc1) ] => { classify_named_vernac p } SYNTERP AS atts
175 {
176 let gloc = Loc.merge gloc0 gloc1 in
177 let atts = validate_attributes raw_args_attributes atts in
178 EV.Synterp.create_command ~atts ~loc:gloc p;
179 atts
180 } -> {
181 let gloc = Loc.merge gloc0 gloc1 in
182 EV.Interp.create_command ~atts ~loc:gloc p }
183 | #[ atts = any_attribute ] [ "Elpi" "Tactic" ghost(gloc0) qualified_name(p) ghost(gloc1) ] => { classify_named_vernac p } SYNTERP AS _
184 {
185 let gloc = Loc.merge gloc0 gloc1 in
186 let () = ignore_unknown_attributes atts in
187 EV.Synterp.create_tactic ~loc:gloc p
188 } -> {
189 let gloc = Loc.merge gloc0 gloc1 in
190 EV.Interp.create_tactic ~loc:gloc p }
191 | #[ atts = any_attribute ] [ "Elpi" "Db" ghost(gloc0) qualified_name(d) elpi_string(s) ghost(gloc1) ] => { classify_named_vernac d } SYNTERP AS atts
192 {
193 let gloc = Loc.merge gloc0 gloc1 in
194 let atts = validate_attributes synterp_attribute atts in
195 EV.Synterp.create_db ~atts ~loc:gloc d ~init:s;
196 atts
197 } -> {
198 let gloc = Loc.merge gloc0 gloc1 in
199 EV.Interp.create_db ~atts ~loc:gloc d ~init:s }
200 | #[ atts = any_attribute ] [ "Elpi" "File" ghost(gloc0) qualified_name(d) elpi_string(s) ghost(gloc1) ] => { classify_named_vernac d } SYNTERP AS atts
201 {
202 let gloc = Loc.merge gloc0 gloc1 in
203 let atts = validate_attributes synterp_attribute atts in
204 EV.Synterp.create_file ~atts ~loc:gloc d ~init:s;
205 atts
206 } -> {
207 let gloc = Loc.merge gloc0 gloc1 in
208 EV.Interp.create_file ~atts ~loc:gloc d ~init:s }
209 END
210
211 VERNAC COMMAND EXTEND ElpiAccumulate CLASSIFIED AS SIDEFF
212 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "File" ne_qualified_name_list(ids) ] SYNTERP AS atts {
213 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
214 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~what:Code (List.map snd ids);
215 atts
216 } -> {
217 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~what:Code (List.map snd ids) }
218 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Files" ne_qualified_name_list(ids) ] SYNTERP AS atts {
219 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
220 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~what:Code (List.map snd ids);
221 atts
222 } -> {
223 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~what:Code (List.map snd ids) }
224 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "File" ne_qualified_name_list(ids) ] SYNTERP AS atts {
225 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
226 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:Code (List.map snd ids);
227 atts
228 } -> {
229 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:Code (List.map snd ids) }
230 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Files" ne_qualified_name_list(ids) ] SYNTERP AS atts {
231 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
232 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:Code (List.map snd ids);
233 atts
234 } -> {
235 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:Code (List.map snd ids) }
236 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "File" "Signature" ne_qualified_name_list(ids) ] SYNTERP AS atts {
237 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
238 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~what:SignatureOnly (List.map snd ids);
239 atts
240 } -> {
241 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~what:SignatureOnly (List.map snd ids) }
242 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Files" "Signature" ne_qualified_name_list(ids) ] SYNTERP AS atts {
243 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
244 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~what:SignatureOnly (List.map snd ids);
245 atts
246 } -> {
247 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~what:SignatureOnly (List.map snd ids) }
248 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "File" "Signature" ne_qualified_name_list(ids) ] SYNTERP AS atts {
249 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
250 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:SignatureOnly (List.map snd ids);
251 atts
252 } -> {
253 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:SignatureOnly (List.map snd ids) }
254 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Files" "Signature" ne_qualified_name_list(ids) ] SYNTERP AS atts {
255 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
256 EV.Synterp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:SignatureOnly (List.map snd ids);
257 atts
258 } -> {
259 EV.Interp.accumulate_extra_deps ~atts ~loc:gloc ~program:(snd p) ~what:SignatureOnly (List.map snd ids) }
260 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Plugin" string(s) ] SYNTERP AS atts {
261 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
262 EV.Synterp.accumulate_plugin ~atts ~loc:gloc s;
263 atts
264 } -> {
265 EV.Interp.accumulate_plugin ~atts ~loc:gloc s }
266 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Plugin" string(s) ] SYNTERP AS atts {
267 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
268 EV.Synterp.accumulate_plugin ~atts ~loc:gloc ~program:(snd p) s;
269 atts
270 } -> {
271 EV.Interp.accumulate_plugin ~atts ~loc:gloc ~program:(snd p) s }
272
273 (************************************** legacy accumulation *************************************************)
274
275 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "File" string_list(s) ] SYNTERP AS atts { warning_legacy_accumulate ();
276 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
277 EV.Synterp.accumulate_files ~atts ~loc:gloc s;
278 atts
279 } -> {
280 EV.Interp.accumulate_files ~atts ~loc:gloc s }
281 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "File" string_list(s) "From" global(g) ] SYNTERP AS atts { warning_legacy_accumulate2 ();
282 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
283 EV.Synterp.accumulate_files ~atts ~loc:gloc (inlogpath g s);
284 atts
285 } -> {
286 EV.Interp.accumulate_files ~atts ~loc:gloc (inlogpath g s) }
287 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Files" string_list(s) ] SYNTERP AS atts { warning_legacy_accumulate ();
288 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
289 EV.Synterp.accumulate_files ~atts ~loc:gloc s;
290 atts
291 } -> {
292 EV.Interp.accumulate_files ~atts ~loc:gloc s }
293 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Files" string_list(s) "From" global(g) ] SYNTERP AS atts { warning_legacy_accumulate2 ();
294 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
295 EV.Synterp.accumulate_files ~atts ~loc:gloc (inlogpath g s);
296 atts
297 } -> {
298 EV.Interp.accumulate_files ~atts ~loc:gloc (inlogpath g s) }
299 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc0) elpi_string(s) ghost(gloc1) ] SYNTERP AS atts {
300 let gloc = Loc.merge gloc0 gloc1 in
301 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
302 EV.Synterp.accumulate_string ~atts ~loc:gloc s;
303 atts
304 } -> {
305 let gloc = Loc.merge gloc0 gloc1 in
306 EV.Interp.accumulate_string ~atts ~loc:gloc s }
307 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "File" string_list(s) ] SYNTERP AS atts { warning_legacy_accumulate ();
308 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
309 EV.Synterp.accumulate_files ~atts ~loc:gloc ~program:(snd p) s;
310 atts
311 } -> {
312 EV.Interp.accumulate_files ~atts ~loc:gloc ~program:(snd p) s }
313 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "File" string_list(s) "From" global(g) ] SYNTERP AS atts { warning_legacy_accumulate2 ();
314 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
315 EV.Synterp.accumulate_files ~atts ~loc:gloc ~program:(snd p) (inlogpath g s);
316 atts
317 } -> {
318 EV.Interp.accumulate_files ~atts ~loc:gloc ~program:(snd p) (inlogpath g s) }
319 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Files" string_list(s) ] SYNTERP AS atts { warning_legacy_accumulate ();
320 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
321 EV.Synterp.accumulate_files ~atts ~loc:gloc ~program:(snd p) s;
322 atts
323 } -> {
324 EV.Interp.accumulate_files ~atts ~loc:gloc ~program:(snd p) s }
325 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Files" string_list(s) "From" global(g) ] SYNTERP AS atts { warning_legacy_accumulate2 ();
326 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
327 EV.Synterp.accumulate_files ~atts ~loc:gloc ~program:(snd p) (inlogpath g s);
328 atts
329 } -> {
330 EV.Interp.accumulate_files ~atts ~loc:gloc ~program:(snd p) (inlogpath g s) }
331
332 (********************************** end legacy **************************************************)
333
334 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc0) qualified_name(p) elpi_string(s) ghost(gloc1) ] SYNTERP AS atts {
335 let gloc = Loc.merge gloc0 gloc1 in
336 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
337 EV.Synterp.accumulate_string ~atts ~loc:gloc ~program:(snd p) s;
338 atts
339 } -> {
340 let gloc = Loc.merge gloc0 gloc1 in
341 EV.Interp.accumulate_string ~atts ~loc:gloc ~program:(snd p) s }
342 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Db" qualified_name(d) ] SYNTERP AS atts {
343 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
344 EV.Synterp.accumulate_db ~atts ~loc:gloc (snd d);
345 atts
346 } -> {
347 EV.Interp.accumulate_db ~atts ~loc:gloc (snd d) }
348 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Db" qualified_name(d) ] SYNTERP AS atts {
349 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
350 EV.Synterp.accumulate_db ~atts ~loc:gloc ~program:(snd p) (snd d);
351 atts
352 } -> {
353 EV.Interp.accumulate_db ~atts ~loc:gloc ~program:(snd p) (snd d) }
354 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) "Db" "Header" qualified_name(d) ] SYNTERP AS atts {
355 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
356 EV.Synterp.accumulate_db_header ~atts ~loc:gloc (snd d);
357 atts
358 } -> {
359 EV.Interp.accumulate_db_header ~atts ~loc:gloc (snd d) }
360 | #[ atts = any_attribute ] [ "Elpi" "Accumulate" ghost(gloc) qualified_name(p) "Db" "Header" qualified_name(d) ] SYNTERP AS atts {
361 let atts = validate_attributes scope_and_skip_and_synterp_attributes atts in
362 EV.Synterp.accumulate_db_header ~atts ~loc:gloc ~program:(snd p) (snd d);
363 atts
364 } -> {
365 EV.Interp.accumulate_db_header ~atts ~loc:gloc ~program:(snd p) (snd d) }
366 END
367
368 VERNAC COMMAND EXTEND ElpiUnnamed CLASSIFIED AS SIDEFF
369 | #[ atts = any_attribute ] [ "Elpi" "Debug" string_list(s) ] SYNTERP AS atts {
370 let atts = validate_attributes synterp_attribute atts in
371 EV.Synterp.debug ~atts s;
372 atts
373 } -> {
374 EV.Interp.debug ~atts s }
375 | #[ atts = any_attribute ] [ "Elpi" "Trace" "Browser" string_list(s) ] SYNTERP AS atts {
376 let atts = validate_attributes synterp_attribute atts in
377 EV.Synterp.trace_browser ~atts s;
378 atts
379 } -> {
380 EV.Interp.trace_browser ~atts s }
381 | #[ atts = any_attribute ] [ "Elpi" "Trace" string_list(s) ] SYNTERP AS atts {
382 let atts = validate_attributes synterp_attribute atts in
383 EV.Synterp.trace ~atts 1 max_int s [];
384 atts
385 } -> {
386 EV.Interp.trace ~atts 1 max_int s [] }
387 | #[ atts = any_attribute ] [ "Elpi" "Trace" string_list(s) "/" string_list(o) ] SYNTERP AS atts {
388 let atts = validate_attributes synterp_attribute atts in
389 EV.Synterp.trace ~atts 1 max_int s o;
390 atts
391 } -> {
392 EV.Interp.trace ~atts 1 max_int s o }
393 | #[ atts = any_attribute ] [ "Elpi" "Trace" int(start) int(stop) string_list(s) ] SYNTERP AS atts {
394 let atts = validate_attributes synterp_attribute atts in
395 EV.Synterp.trace ~atts start stop s [];
396 atts
397 } -> {
398 EV.Interp.trace ~atts start stop s [] }
399 | #[ atts = any_attribute ] [ "Elpi" "Trace" int(start) int(stop) string_list(s) "/" string_list(o) ] SYNTERP AS atts {
400 let atts = validate_attributes synterp_attribute atts in
401 EV.Synterp.trace ~atts start stop s o;
402 atts
403 } -> {
404 EV.Interp.trace ~atts start stop s o }
405
406 | #[ atts = any_attribute ] [ "Elpi" "Trace" "Off" ] SYNTERP AS atts {
407 let atts = validate_attributes synterp_attribute atts in
408 EV.Synterp.trace ~atts 0 0 [] [];
409 atts
410 } -> {
411 EV.Interp.trace ~atts 0 0 [] [] }
412 | #[ atts = any_attribute ] [ "Elpi" "Bound" "Steps" int(steps) ] SYNTERP AS atts {
413 let atts = validate_attributes synterp_attribute atts in
414 EV.Synterp.bound_steps ~atts steps;
415 atts
416 } -> {
417 EV.Interp.bound_steps ~atts steps }
418
419 | #[ atts = any_attribute ] [ "Elpi" "Print" ghost(gloc) qualified_name(p) string(output) string_list(args) ] SYNTERP AS atts {
420 let atts = validate_attributes synterp_attribute atts in
421 EV.Synterp.print ~atts ~loc:gloc ~name:(snd p) ~args output;
422 atts
423 } -> {
424 EV.Interp.print ~atts ~loc:gloc ~name:(snd p) ~args output; }
425
426 | #[ atts = any_attribute ] [ "Elpi" "Typecheck" ] SYNTERP AS _
427 {
428 let () = ignore_unknown_attributes atts in
429 warning_legacy_typecheck ()
430 } -> {
431 warning_legacy_typecheck () }
432 | #[ atts = any_attribute ] [ "Elpi" "Typecheck" qualified_name(p) ] SYNTERP AS _
433 {
434 let () = ignore_unknown_attributes atts in
435 warning_legacy_typecheck ()
436 } -> {
437 let () = ignore_unknown_attributes atts in
438 warning_legacy_typecheck () }
439
440 | #[ atts = any_attribute ] [ "Elpi" "Document" "Builtins" ] -> {
441 let () = ignore_unknown_attributes atts in
442 EV.document_builtins () }
443 | #[ atts = any_attribute ] [ "Elpi" "Template" "Command" ghost(gloc) string(syn) string(int) ] SYNTERP AS _ {
444 let () = ignore_unknown_attributes atts in
445 EV.Synterp.load_command ~loc:gloc syn
446 } -> {
447 EV.Interp.load_command ~loc:gloc int }
448 | #[ atts = any_attribute ] [ "Elpi" "Template" "Tactic" ghost(gloc) string(s) ] SYNTERP AS _ {
449 let () = ignore_unknown_attributes atts in
450 () (* no synterp tactics EV.Synterp.load_tactic syn *)
451 } -> {
452 EV.Interp.load_tactic ~loc:gloc s }
453 END
454
455 VERNAC COMMAND EXTEND ElpiRun CLASSIFIED BY { fun _ -> Vernacextend.(VtSideff ([], VtNow)) }
456 | #[ atts = any_attribute ] [ "Elpi" "Query" ghost(gloc) elpi_string(synterp) elpi_string_opt(interp) ] SYNTERP AS syndata
457 {
458 let () = ignore_unknown_attributes atts in
459 let synterp, interp = match interp with None -> None, synterp | Some interp -> Some synterp, interp in
460 match synterp with
461 | Some synterp -> EV.Synterp.run_in_program ~loc:gloc synterp
462 | None -> None
463 } -> {
464 let synterp, interp = match interp with None -> None, synterp | Some interp -> Some synterp, interp in
465 EV.Interp.run_in_program ~loc:gloc ~syndata interp }
466 | #[ atts = any_attribute ] [ "Elpi" "Query" ghost(gloc) qualified_name(p) elpi_string(synterp) elpi_string_opt(interp) ] SYNTERP AS syndata
467 {
468 let () = ignore_unknown_attributes atts in
469 let synterp, interp = match interp with None -> None, synterp | Some interp -> Some synterp, interp in
470 match synterp with
471 | Some synterp -> EV.Synterp.run_in_program ~loc:gloc synterp
472 | None -> None
473 } -> {
474 let synterp, interp = match interp with None -> None, synterp | Some interp -> Some synterp, interp in
475 EV.Interp.run_in_program ~loc:gloc ~program:(snd p) ~syndata interp }
476 | #[ atts = any_attribute ] [ "Elpi" "Export" qualified_name(p) ] => { Vernacextend.(VtSideff ([],VtNow)) } SYNTERP AS _ {
477 let atts = validate_attributes proof_attribute atts in
478 EV.export_command ~atts (snd p)
479 } -> {
480 ()
481 }
482 | #[ atts = any_attribute ] [ "Elpi" "Export" qualified_name(p) "As" qualified_name(q) ] => { Vernacextend.(VtSideff ([],VtNow)) } SYNTERP AS _ {
483 let atts = validate_attributes proof_attribute atts in
484 EV.export_command ~atts ~as_:(snd q) (snd p)
485 } -> {
486 ()
487 }
488 | #[ atts = any_attribute ] [ "Elpi" qualified_name(p) elpi_cmd_arg_list(args) ] SYNTERP AS syndata
489 {
490 let () = ignore_unknown_attributes atts in
491 EV.Synterp.run_program ~loc:(fst p) (snd p) ~atts args
492 } -> {
493 EV.Interp.run_program ~loc:(fst p) (snd p) ~atts ~syndata args }
494 END
495
496 TACTIC EXTEND elpi_tac
497 | [ "elpi" qualified_name(p) elpi_tactic_arg_list(args) ] ->
498 { EV.run_tactic ~loc:(fst p) (snd p) ~atts:[] ist args }
499 | [ "ltac_attributes" ":" "(" ltac_attributes(atts) ")" "elpi" qualified_name(p) elpi_tactic_arg_list(args) ] ->
500 { EV.run_tactic ~loc:(fst p) (snd p) ~atts ist args }
501 | [ "#[" attributes(atts) "]" "elpi" qualified_name(p) elpi_tactic_arg_list(args) ] ->
502 { EV.run_tactic ~loc:(fst p) (snd p) ~atts ist args }
503 | [ "elpi" "query" ghost(gloc) elpi_string(s) ] ->
504 { EV.run_in_tactic ~loc:gloc s ist }
505 | [ "elpi" "query" qualified_name(p) elpi_string(s) ] ->
506 { EV.run_in_tactic ~loc:(fst p) s ~program:(snd p) ist }
507 END
508
509 (* vim:set ft=ocaml: *)