Debian Codegraph @

plugins/ring/g_ring.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 {
12
13 open Ltac_plugin
14 open Pp
15 open Util
16 open Ring_ast
17 open Ring
18 open Stdarg
19 open Tacarg
20 open Procq.Constr
21 open Pltac
22
23 }
24
25 DECLARE PLUGIN "rocq-runtime.plugins.ring"
26
27 TACTIC EXTEND protect_fv
28 | [ "protect_fv" string(map) "in" ident(id) ] ->
29 { protect_tac_in map id }
30 | [ "protect_fv" string(map) ] ->
31 { protect_tac map }
32 END
33
34 {
35
36 open Pptactic
37 open Ppconstr
38
39 let pr_constr_expr env sigma c = pr_constr_expr ~flags:(current_flags()) env sigma c
40
41 let pr_ring_mod env sigma = function
42 | Ring_kind (Computational eq_test) -> str "decidable" ++ pr_arg (pr_constr_expr env sigma) eq_test
43 | Ring_kind Abstract -> str "abstract"
44 | Ring_kind (Morphism morph) -> str "morphism" ++ pr_arg (pr_constr_expr env sigma) morph
45 | Const_tac (CstTac cst_tac) -> str "constants" ++ spc () ++ str "[" ++ pr_raw_tactic env sigma cst_tac ++ str "]"
46 | Const_tac (Closed l) -> str "closed" ++ spc () ++ str "[" ++ prlist_with_sep spc pr_qualid l ++ str "]"
47 | Pre_tac t -> str "preprocess" ++ spc () ++ str "[" ++ pr_raw_tactic env sigma t ++ str "]"
48 | Post_tac t -> str "postprocess" ++ spc () ++ str "[" ++ pr_raw_tactic env sigma t ++ str "]"
49 | Setoid(sth,ext) -> str "setoid" ++ pr_arg (pr_constr_expr env sigma) sth ++ pr_arg (pr_constr_expr env sigma) ext
50 | Pow_spec(Closed l,spec) -> str "power_tac" ++ pr_arg (pr_constr_expr env sigma) spec ++ spc () ++ str "[" ++ prlist_with_sep spc pr_qualid l ++ str "]"
51 | Pow_spec(CstTac cst_tac,spec) -> str "power_tac" ++ pr_arg (pr_constr_expr env sigma) spec ++ spc () ++ str "[" ++ pr_raw_tactic env sigma cst_tac ++ str "]"
52 | Sign_spec t -> str "sign" ++ pr_arg (pr_constr_expr env sigma) t
53 | Div_spec t -> str "div" ++ pr_arg (pr_constr_expr env sigma) t
54
55 }
56
57 VERNAC ARGUMENT EXTEND ring_mod
58 PRINTED BY { pr_ring_mod env sigma }
59 | [ "decidable" constr(eq_test) ] -> { Ring_kind(Computational eq_test) }
60 | [ "abstract" ] -> { Ring_kind Abstract }
61 | [ "morphism" constr(morph) ] -> { Ring_kind(Morphism morph) }
62 | [ "constants" "[" tactic(cst_tac) "]" ] -> { Const_tac(CstTac cst_tac) }
63 | [ "closed" "[" ne_global_list(l) "]" ] -> { Const_tac(Closed l) }
64 | [ "preprocess" "[" tactic(pre) "]" ] -> { Pre_tac pre }
65 | [ "postprocess" "[" tactic(post) "]" ] -> { Post_tac post }
66 | [ "setoid" constr(sth) constr(ext) ] -> { Setoid(sth,ext) }
67 | [ "sign" constr(sign_spec) ] -> { Sign_spec sign_spec }
68 | [ "power" constr(pow_spec) "[" ne_global_list(l) "]" ] ->
69 { Pow_spec (Closed l, pow_spec) }
70 | [ "power_tac" constr(pow_spec) "[" tactic(cst_tac) "]" ] ->
71 { Pow_spec (CstTac cst_tac, pow_spec) }
72 | [ "div" constr(div_spec) ] -> { Div_spec div_spec }
73 END
74
75 {
76
77 let pr_ring_mods env sigma l = surround (prlist_with_sep pr_comma (pr_ring_mod env sigma) l)
78
79 }
80
81 VERNAC ARGUMENT EXTEND ring_mods
82 PRINTED BY { pr_ring_mods env sigma }
83 | [ "(" ne_ring_mod_list_sep(mods, ",") ")" ] -> { mods }
84 END
85
86 VERNAC COMMAND EXTEND AddSetoidRing CLASSIFIED AS SIDEFF
87 | [ "Add" "Ring" identref(id) ":" constr(t) ring_mods_opt(l) ] ->
88 { add_theory id.CAst.v t (Option.default [] l) }
89 | [ "Print" "Rings" ] => { Vernacextend.classify_as_query } -> {
90 print_rings ()
91 }
92 END
93
94 TACTIC EXTEND ring_lookup
95 | [ "ring_lookup" tactic0(f) "[" constr_list(lH) "]" ne_constr_list(lrt) ] ->
96 { let (t,lr) = List.sep_last lrt in ring_lookup f lH lr t }
97 END
98
99 {
100
101 let pr_field_mod env sigma = function
102 | Ring_mod m -> pr_ring_mod env sigma m
103 | Inject inj -> str "completeness" ++ pr_arg (pr_constr_expr env sigma) inj
104
105 }
106
107 VERNAC ARGUMENT EXTEND field_mod
108 PRINTED BY { pr_field_mod env sigma }
109 | [ ring_mod(m) ] -> { Ring_mod m }
110 | [ "completeness" constr(inj) ] -> { Inject inj }
111 END
112
113 {
114
115 let pr_field_mods env sigma l = surround (prlist_with_sep pr_comma (pr_field_mod env sigma) l)
116
117 }
118
119 VERNAC ARGUMENT EXTEND field_mods
120 PRINTED BY { pr_field_mods env sigma }
121 | [ "(" ne_field_mod_list_sep(mods, ",") ")" ] -> { mods }
122 END
123
124 VERNAC COMMAND EXTEND AddSetoidField CLASSIFIED AS SIDEFF
125 | [ "Add" "Field" identref(id) ":" constr(t) field_mods_opt(l) ] ->
126 { let l = match l with None -> [] | Some l -> l in add_field_theory id.CAst.v t l }
127 | [ "Print" "Fields" ] => {Vernacextend.classify_as_query} -> {
128 print_fields ()
129 }
130 END
131
132 TACTIC EXTEND field_lookup
133 | [ "field_lookup" tactic(f) "[" constr_list(lH) "]" ne_constr_list(lt) ] ->
134 { let (t,l) = List.sep_last lt in field_lookup f lH l t }
135 END