Debian Codegraph @

tests/test_API.v

raw
1 From elpi Require Import elpi.
2
3 Elpi Command test.API.
4
5 Elpi Query lp:{{
6 coq.version V MA MI P,
7 std.assert! (MA = 8 ; MA = 9) "Coq major version not 8 or 9",
8 std.assert! (MI >= 0 ; MI < 20) "Coq minor version not in 0 - 20",
9 % std.assert! (P >= 0 ; P > -5) "Coq never made so many betas",
10 coq.say "Coq version:" V "=" MA "." MI "." P.
11 }}.
12
13 Elpi Command version.
14 Elpi Accumulate lp:{{
15
16 % elpi:if version rocq-elpi < 2.0.0
17 main _ :- coq.error "bad".
18 % elpi:endif
19
20 main _ :- true.
21
22 }}.
23 Elpi version.
24
25 (****** say *************************************)
26
27 Elpi Query lp:{{
28 coq.say "hello world"
29 }}.
30
31 (****** warnings *************************************)
32
33 Set Warnings "-elpi,-category,+unknown-warning".
34 Elpi Query lp:{{
35 coq.warn "this is a generic warning".
36 }}.
37
38 Elpi Query lp:{{
39 coq.say "A",
40 coq.warning "category" "name" "this is a warning with a name an category".
41 }} lp:{{
42 coq.say "B",
43 coq.warning "category" "name" "this is a warning with a name an category".
44 }}.
45
46 Set Warnings "+category".
47
48 Elpi Query lp:{{
49 coq.warning "category" "name" "this is a warning with a name an category".
50 }} lp:{{ coq.warning "category" "name" "this is a warning with a name an category". }}.
51 Fail Elpi Query lp:{{
52 coq.warning "category" "name" "this is another warning with a name an category".
53 }} lp:{{ coq.warning "category" "name" "this is a warning with a name an category". }}.
54 Set Warnings "elpi,category".
55
56 (****** locate **********************************)
57
58 (* nametab *)
59 Elpi Query lp:{{
60 coq.locate "nat" (indt GR),
61 coq.locate "Datatypes.nat" (indt GR),
62 coq.locate "Init.Datatypes.nat" (indt GR),
63 coq.locate "Corelib.Init.Datatypes.nat" (indt GR).
64 }}.
65
66 Fail Elpi Query lp:{{
67 coq.locate "foobar" _.
68 }}.
69
70 Elpi Query lp:{{
71 coq.locate "plus" (const GR),
72 coq.locate "Nat.add" (const GR),
73 coq.locate-module "Init.Datatypes" MP_.
74 }}.
75
76 Notation succ x := (S x).
77
78 Elpi Query lp:{{ std.do! [
79 coq.locate-all "plus" X1, X1 = [loc-gref (const GR)],
80 coq.locate-all "Nat.add" X2, X2 = [loc-gref (const GR)],
81 coq.locate-all "succ" X3, X3 = [loc-abbreviation A_],
82 coq.locate-all "Init.Datatypes" X4, X4 = [loc-modpath MP_],
83 coq.locate-all "fdsfdsjkfdksljflkdsjlkfdjkls" [],
84 ].
85 }}.
86
87
88 (***** Univs *******************************)
89
90 Elpi Query lp:{{coq.univ.print}}.
91 Elpi Query lp:{{coq.univ.new X_}}.
92 Elpi Query lp:{{coq.sort.leq X_ Y_}}.
93 Elpi Query lp:{{coq.sort.eq X_ Y_}}.
94 Elpi Query lp:{{coq.sort.pts-triple X_ Y_ Z_}}.
95 Elpi Query lp:{{coq.sort.sup X_ Y_}}.
96
97
98 (********* accumulate *************** *)
99
100 Elpi Db test.db lp:{{type foo string -> prop.}}.
101 Elpi Command test.use.db.
102 Elpi Accumulate Db test.db.
103 #[synterp] Elpi Accumulate lp:{{
104 main [] :- coq.env.begin-module "test_db_accumulate" none, coq.env.end-module _.
105 }}.
106 Elpi Accumulate lp:{{
107 main [] :-
108 coq.elpi.accumulate _ "test.db"
109 (clause _ _ (pi x\ foo x :- x = "here")),
110 coq.env.begin-module "test_db_accumulate" _,
111 coq.elpi.accumulate current "test.db"
112 (clause _ _ (pi x\ foo x :- x = "there")),
113 coq.env.end-module _.
114 }}.
115
116
117 Fail Elpi Query lp:{{foo _}}.
118 Elpi test.use.db.
119 Elpi Query lp:{{foo "here"}}.
120
121 Fail Elpi Query lp:{{foo "there"}}.
122 Import test_db_accumulate.
123 Elpi Query lp:{{foo "there"}}.
124 Module xx := test_db_accumulate.
125
126
127 Elpi Db test2.db lp:{{
128 type foo gref -> prop.
129 }}.
130 Elpi Command test2.use.db.
131 Elpi Accumulate Db test2.db.
132 Elpi Accumulate lp:{{
133 main [str S] :- coq.locate S GR, coq.elpi.accumulate _ "test2.db" (clause _ _ (foo GR)).
134 main [str "local", str S] :- coq.locate S GR, @local! => coq.elpi.accumulate _ "test2.db" (clause _ _ (foo GR)).
135 main [int N] :- std.findall (foo X_) L, coq.say L, std.length L N.
136 }}.
137
138 Module T2.
139 Section T2.
140 Variable X : nat.
141 Elpi test2.use.db X.
142 Elpi test2.use.db nat.
143 Elpi test2.use.db "local" bool.
144 Elpi test2.use.db 3.
145 End T2.
146 Elpi test2.use.db "local" bool.
147 Elpi test2.use.db 2.
148 End T2.
149 Elpi test2.use.db 0.
150 Import T2.
151 Elpi test2.use.db 1.
152
153
154 Section T3. Fail Elpi Db test3.db lp:{{ }}. End T3.
155 Module T3. Fail Elpi Db test3.db lp:{{ }}. End T3.
156
157 (* scope grafted clauses, again and across files *)
158
159 Elpi Db global.db lp:{{
160 pred declared o:string.
161
162 :name "init"
163 declared _ :- fail.
164 }}.
165 Elpi Command declare.
166 Elpi Accumulate Db global.db.
167 #[synterp] Elpi Accumulate lp:{{
168 main [str "library",_] :- coq.env.begin-module "ClausesL" none, coq.env.end-module _.
169 main [str "current",_] :- coq.env.begin-module "ClausesC" none, coq.env.end-module _.
170 main [str "execution-site",_] :- coq.env.begin-module "ClausesE" none, coq.env.end-module _.
171 }}.
172 Elpi Accumulate lp:{{
173
174 main [str "library", str I] :-
175 coq.env.begin-module "ClausesL" _,
176 coq.elpi.accumulate library "global.db" (clause _ (before "init") (declared I)),
177 coq.env.end-module _.
178 main [str "current", str I] :-
179 coq.env.begin-module "ClausesC" _,
180 coq.elpi.accumulate current "global.db" (clause _ (before "init") (declared I)),
181 coq.env.end-module _.
182 main [str "execution-site", str I] :-
183 coq.env.begin-module "ClausesE" _,
184 coq.elpi.accumulate execution-site "global.db" (clause _ (before "init") (declared I)),
185 coq.env.end-module _.
186
187 }}.
188
189
190 Elpi Command declare.test.
191 Elpi Accumulate Db global.db.
192 Elpi Accumulate lp:{{
193
194 main [str "mem", str I] :-
195 std.assert! (declared I) "clause not present".
196 main [str "length", int I] :-
197 std.findall (declared J_) L,
198 std.assert! (std.length L I) "wrong number of clauses".
199
200 }}.
201
202
203
204 Module Box.
205 Elpi declare "current" "BOX.ClausesC".
206 Fail Elpi declare.test "mem" "BOX.ClausesC".
207
208 Elpi declare "library" "GLOBAL".
209 Elpi declare "execution-site" "BOX".
210 Elpi declare.test "mem" "GLOBAL".
211 Elpi declare.test "mem" "BOX".
212 Elpi declare.test "length" 2.
213
214 End Box.
215
216 Elpi declare.test "mem" "GLOBAL".
217 Fail Elpi declare.test "mem" "BOX".
218 Elpi declare.test "length" 1.
219
220 Export Box.
221 Elpi declare.test "mem" "BOX".
222 Elpi declare.test "length" 2.
223
224 Import Box.ClausesC.
225 Elpi declare.test "mem" "BOX.ClausesC".
226 Elpi declare.test "length" 3.
227
228 (********* options ************)
229
230 Elpi Query lp:{{ % see test_API.v
231
232 coq.option.add ["Foo", "Bar"] (coq.option.string (some "x")) tt
233
234 }}.
235
236
237 (********* export *************** *)
238
239 Elpi Command export.me.
240 Elpi Accumulate lp:{{ main A :- coq.say "hello" A. }}.
241
242
243 Elpi Export export.me.
244
245 export.me 1 2 (nat) "x".
246
247 (************* halt ********************)
248
249 Elpi Command halt.
250 Elpi Accumulate lp:{{
251 main _ :- std.assert! (3 = 2) "ooops".
252 }}.
253 Fail Elpi halt.
254
255 (**********************************************)
256
257 Elpi Command test.pp.
258 Elpi Accumulate lp:{{
259 main _ :- std.do! [
260 P = coq.pp.box (coq.pp.hv 2) [coq.pp.str "Module", coq.pp.spc, coq.pp.str "Foo", coq.pp.spc, coq.pp.str":=", coq.pp.brk 1 0, coq.pp.str "body", coq.pp.spc, coq.pp.str "End Foo."],
261 coq.say P,
262 @ppwidth! 15 => coq.say {coq.pp->string P},
263 @ppall! => coq.say {coq.term->string {{ fix foo x y {struct x} := match x in bool with false => y | true => 3 end }} },
264 @ppmost! => coq.say {coq.term->string {{ fix foo x y {struct x} := match x in bool with false => y | true => 3 end }} },
265 ].
266 }}.
267 Elpi test.pp.
268