Skip to content

Commit

Permalink
Add coq.env.add-context for inserting a context declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechStep committed Jan 6, 2025
1 parent 983f0dc commit ee28024
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions builtin-doc/coq-builtin.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,17 @@ coq.env.add-section-variable Name Ty C :-
coq.env.add-section-variable-two Name explicit Ty C.



pred coq.env.add-context i:context-decl.
coq.env.add-context context-end.
coq.env.add-context (context-item Name I Ty none Rest) :-
coq.env.add-section-variable-two Name I Ty C,
coq.env.add-context (Rest {coq.env.global (const C)}).
coq.env.add-context (context-item Name _I Ty (some Bo) Rest) :-
coq.env.add-const Name Bo Ty ff C,
coq.env.add-context (Rest {coq.env.global (const C)}).


% [coq.env.add-indt Decl I] Declares an inductive type.
% Supported attributes:
% - @dropunivs! (default: false, drops all universe constraints from the
Expand Down
11 changes: 11 additions & 0 deletions src/coq_elpi_builtins.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,17 @@ coq.env.add-section-variable Name Ty C :-
coq.env.add-section-variable-two Name explicit Ty C.
|};

LPCode {|
pred coq.env.add-context i:context-decl.
coq.env.add-context context-end.
coq.env.add-context (context-item Name I Ty none Rest) :-
coq.env.add-section-variable-two Name I Ty C,
coq.env.add-context (Rest {coq.env.global (const C)}).
coq.env.add-context (context-item Name _I Ty (some Bo) Rest) :-
coq.env.add-const Name Bo Ty ff C,
coq.env.add-context (Rest {coq.env.global (const C)}).
|};

MLCode(Pred("coq.env.add-indt",
CIn(indt_decl_in, "Decl",
Out(inductive, "I",
Expand Down
19 changes: 19 additions & 0 deletions tests/test_API_context.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From elpi Require Import elpi.

Elpi Command context.
Elpi Accumulate lp:{{
main [ctx-decl Ctx] :- !,
coq.env.add-context Ctx.
}}.

Section CA.
Elpi context Context (a : nat) [b : nat] {c : nat} (d : nat := 3) (e := 4).
Check eq_refl : d = 3.
Check eq_refl : e = 4.
Definition foo := a + b + c + d + e.
End CA.
Print foo.

Elpi Query lp:{{
coq.arguments.implicit {coq.locate "foo"} [[explicit, implicit, maximal]].
}}.

0 comments on commit ee28024

Please sign in to comment.