Skip to content

Commit ee28024

Browse files
committed
Add coq.env.add-context for inserting a context declaration
1 parent 983f0dc commit ee28024

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

builtin-doc/coq-builtin.elpi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,17 @@ coq.env.add-section-variable Name Ty C :-
817817
coq.env.add-section-variable-two Name explicit Ty C.
818818

819819

820+
821+
pred coq.env.add-context i:context-decl.
822+
coq.env.add-context context-end.
823+
coq.env.add-context (context-item Name I Ty none Rest) :-
824+
coq.env.add-section-variable-two Name I Ty C,
825+
coq.env.add-context (Rest {coq.env.global (const C)}).
826+
coq.env.add-context (context-item Name _I Ty (some Bo) Rest) :-
827+
coq.env.add-const Name Bo Ty ff C,
828+
coq.env.add-context (Rest {coq.env.global (const C)}).
829+
830+
820831
% [coq.env.add-indt Decl I] Declares an inductive type.
821832
% Supported attributes:
822833
% - @dropunivs! (default: false, drops all universe constraints from the

src/coq_elpi_builtins.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,17 @@ coq.env.add-section-variable Name Ty C :-
20602060
coq.env.add-section-variable-two Name explicit Ty C.
20612061
|};
20622062

2063+
LPCode {|
2064+
pred coq.env.add-context i:context-decl.
2065+
coq.env.add-context context-end.
2066+
coq.env.add-context (context-item Name I Ty none Rest) :-
2067+
coq.env.add-section-variable-two Name I Ty C,
2068+
coq.env.add-context (Rest {coq.env.global (const C)}).
2069+
coq.env.add-context (context-item Name _I Ty (some Bo) Rest) :-
2070+
coq.env.add-const Name Bo Ty ff C,
2071+
coq.env.add-context (Rest {coq.env.global (const C)}).
2072+
|};
2073+
20632074
MLCode(Pred("coq.env.add-indt",
20642075
CIn(indt_decl_in, "Decl",
20652076
Out(inductive, "I",

tests/test_API_context.v

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From elpi Require Import elpi.
2+
3+
Elpi Command context.
4+
Elpi Accumulate lp:{{
5+
main [ctx-decl Ctx] :- !,
6+
coq.env.add-context Ctx.
7+
}}.
8+
9+
Section CA.
10+
Elpi context Context (a : nat) [b : nat] {c : nat} (d : nat := 3) (e := 4).
11+
Check eq_refl : d = 3.
12+
Check eq_refl : e = 4.
13+
Definition foo := a + b + c + d + e.
14+
End CA.
15+
Print foo.
16+
17+
Elpi Query lp:{{
18+
coq.arguments.implicit {coq.locate "foo"} [[explicit, implicit, maximal]].
19+
}}.

0 commit comments

Comments
 (0)