Skip to content

Commit 742a023

Browse files
committed
ifdefs on elpi version in source code
1 parent 3564cc9 commit 742a023

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

coq-elpi.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ depends: [
1919
"ocaml" {>= "4.10.0"}
2020
"stdlib-shims"
2121
"elpi" {>= "1.18.2" & < "1.20.0~"}
22-
"coq" {>= "8.20" & < "8.21"}
22+
"coq" {>= "8.20+rc1" & < "8.21~"}
2323
"ppx_optcomp"
2424
"ocaml-lsp-server" {with-dev-setup}
2525
"odoc" {with-doc}

etc/dune

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
(public_name coq_elpi_optcomp)
1010
(modules optcomp)
1111
(libraries str)
12+
(package coq-elpi))
13+
14+
(executable
15+
(name version_parser)
16+
(public_name coq_elpi_version_parser)
17+
(modules version_parser)
18+
(libraries str)
1219
(package coq-elpi))

etc/version_parser.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
let is_number x = try let _ = int_of_string x in true with _ -> false ;;
3+
4+
let main () =
5+
let v = Sys.argv.(1) in
6+
let l = String.split_on_char '.' Str.(replace_first (regexp "^v") "" v) in
7+
(* sanitization *)
8+
let l =
9+
match l with
10+
| l when List.for_all is_number l -> l
11+
| ["%%VERSION_NUM%%"] -> ["99";"99";"99"]
12+
| _ -> Printf.eprintf "version_parser: cannot parse: %s\n" v; exit 1 in
13+
let open Format in
14+
printf "(%a)%!" (pp_print_list ~pp_sep:(fun fmt () -> pp_print_string fmt ", ") pp_print_string) l
15+
;;
16+
17+
main ()

src/coq_elpi_builtins_synterp.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(* license: GNU Lesser General Public License Version 2.1 or later *)
33
(* ------------------------------------------------------------------------- *)
44

5+
[%%import "coq_elpi_config.mlh"]
6+
57
module API = Elpi.API
68
module State = API.State
79
module Conv = API.Conversion
@@ -150,6 +152,12 @@ let invocation_site_loc_synterp : API.Ast.Loc.t State.component =
150152
~init:(fun () -> API.Ast.Loc.initial "(should-not-happen)")
151153
~start:(fun x -> x) ()
152154

155+
[%%if elpi >= (1, 20, 0)]
156+
let compat_graft x = x
157+
[%%else]
158+
let compat_graft = Option.map (function `Remove, _ -> nYI "clause removal" | ((`Replace | `Before | `After), _) as x -> x)
159+
[%%endif]
160+
153161
type accumulation_item = qualified_name * API.Ast.program * Id.t list * Coq_elpi_utils.clause_scope
154162
let accumulate_clauses ~clauses_for_later ~accumulate_to_db ~preprocess_clause ~scope ~dbname clauses ~depth ~options state =
155163
let invocation_loc = State.get invocation_site_loc_synterp state in
@@ -158,7 +166,7 @@ let accumulate_clauses ~clauses_for_later ~accumulate_to_db ~preprocess_clause ~
158166
let clauses scope =
159167
clauses |> CList.rev_map (fun (name,graft,clause) ->
160168
let vars, clause = preprocess_clause ~depth clause in
161-
let graft = Option.map (function `Remove, _ -> nYI "clause removal" | ((`Replace | `Before | `After), _) as x -> x) graft in
169+
let graft = compat_graft graft in
162170
let clause = U.clause_of_term ?name ?graft ~depth loc clause in
163171
(dbname,clause,vars,scope)) in
164172
let local = (options : options).local = Some true in

src/dune

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(public_name coq-elpi.elpi)
44
(synopsis "Elpi")
55
(flags :standard -w -27)
6+
(preprocessor_deps coq_elpi_config.mlh)
67
(preprocess (pps ppx_optcomp -- -cookie "ppx_optcomp.env=env ~coq:(Defined \"%{coq:version.major}.%{coq:version.minor}\")"))
78
(libraries coq-core.plugins.ltac coq-core.vernac elpi))
89

@@ -30,7 +31,20 @@
3031
(target coq_elpi_config.ml)
3132
(action (with-stdout-to %{target}
3233
(progn
34+
(echo "(* Automatically generated, don't edit *)\n")
35+
(echo "[%%import \"coq_elpi_config.mlh\"]\n")
36+
(echo "let elpi_version = \"%{version:elpi}\"\n")
3337
(echo "let elpi2html = \"%{lib:elpi:elpi2html.elpi}\";;")))))
3438

39+
(rule
40+
(target coq_elpi_config.mlh)
41+
(action (with-stdout-to %{target}
42+
(progn
43+
(echo "(* Automatically generated, don't edit *)\n")
44+
(echo "[%%define elpi ")
45+
(run coq_elpi_version_parser %{version:elpi})
46+
(echo "]\n")))))
47+
48+
3549
(coq.pp
3650
(modules coq_elpi_vernacular_syntax coq_elpi_arg_syntax))

0 commit comments

Comments
 (0)