Skip to content

Commit 475ac11

Browse files
authored
Merge pull request #602 from LPCIC/ppgoal
API to print a goal
2 parents 4525fee + f82bee7 commit 475ac11

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## UNRELEASED
4+
5+
### API
6+
- New `coq.goal->pp`
7+
38
## [2.0.2] - 01/02/2024
49

510
Requires Elpi 1.18.2 and Coq 8.19.

coq-builtin.elpi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,16 @@ external pred coq.term->string i:term, o:string.
16911691
% - @holes! (default: false, prints evars as _)
16921692
external pred coq.term->pp i:term, o:coq.pp.
16931693

1694+
% [coq.goal->pp G B] prints a goal G to a pp.t B using Coq's pretty
1695+
% printer"
1696+
% Supported attributes:
1697+
% - @ppall! (default: false, prints all details)
1698+
% - @ppmost! (default: false, prints most details)
1699+
% - @pplevel! (default: _, prints parentheses to reach that level, 200 =
1700+
% off)
1701+
% - @holes! (default: false, prints evars as _)
1702+
external pred coq.goal->pp i:goal, o:coq.pp.
1703+
16941704
% -- Extra Dependencies -----------------------------------------------
16951705

16961706
% [coq.extra-dep Identifier FileName] Resolve the file name of an extra

src/coq_elpi_builtins.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,6 +3830,30 @@ Supported attributes:
38303830
state, !: s, [])),
38313831
DocAbove);
38323832

3833+
MLCode(Pred("coq.goal->pp",
3834+
CIn(goal,"G",
3835+
Out(ppboxes, "B",
3836+
Full(raw_ctx, {|prints a goal G to a pp.t B using Coq's pretty printer"
3837+
Supported attributes:
3838+
- @ppall! (default: false, prints all details)
3839+
- @ppmost! (default: false, prints most details)
3840+
- @pplevel! (default: _, prints parentheses to reach that level, 200 = off)
3841+
- @holes! (default: false, prints evars as _)|}))),
3842+
(fun (proof_context,evar,args) _ ~depth _ _ state ->
3843+
let sigma = get_sigma state in
3844+
let pr_named_context_of env sigma =
3845+
let make_decl_list env d pps = Printer.pr_named_decl env sigma d :: pps in
3846+
let psl = List.rev (Environ.fold_named_context make_decl_list env ~init:[]) in
3847+
Pp.(v 0 (prlist_with_sep (fun _ -> ws 2) (fun x -> x) psl)) in
3848+
let s = Pp.(repr @@ with_pp_options proof_context.options.pp (fun () ->
3849+
v 0 @@
3850+
pr_named_context_of proof_context.env sigma ++ cut () ++
3851+
str "======================" ++ cut () ++
3852+
Printer.pr_econstr_env proof_context.env sigma
3853+
Evd.(evar_concl @@ find_undefined sigma evar))) in
3854+
state, !: s, [])),
3855+
DocAbove);
3856+
38333857
LPDoc "-- Extra Dependencies -----------------------------------------------";
38343858

38353859
MLCode(Pred("coq.extra-dep",

tests/test_tactic.v

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ Elpi Print foobar.
2626
Elpi Tactic print_goal.
2727
Elpi Accumulate lp:{{
2828

29-
solve (goal L _ T _ As as G) [seal G] :-
29+
solve (goal _ _ _ _ _ as G) [seal G] :-
3030
print_constraints,
31-
coq.say "Goal: ", coq.say As, coq.say "\n",
32-
coq.say L,
33-
coq.say "------------",
34-
coq.say T {coq.term->string T}.
31+
coq.say "Goal: \n",
32+
coq.say {coq.pp->string {coq.goal->pp G} }.
3533

3634
}}.
3735

0 commit comments

Comments
 (0)