Skip to content

Commit 7a3bea8

Browse files
authored
Merge pull request #360 from LPCIC/fix-old-ocaml
fix old ocaml
2 parents ac56bc3 + fc5d7ef commit 7a3bea8

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(lang dune 2.8)
1+
(lang dune 2.9)
22
(name elpi)
33
(using menhir 2.0)

elpi.opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ x-maintenance-intent: ["(latest)"]
1616
depends: [
1717
"ocaml" {>= "4.13.0" }
1818
"stdlib-shims"
19-
"ppxlib" {>= "0.36.0"}
19+
"ppxlib" {>= "0.12.0"}
20+
"ppx_optcomp"
2021
"menhir" {>= "20211230" }
2122
"re" {>= "1.7.2"}
2223
"ppx_deriving" {>= "4.3"}

trace/ppx/dune

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
(library
2-
(name trace_ppx)
3-
(public_name elpi.trace.ppx)
4-
(libraries ppxlib)
5-
(preprocess (pps ppxlib.metaquot))
6-
(kind ppx_rewriter)
7-
(ppx_runtime_libraries elpi.trace.runtime)
8-
(modules trace_ppx)
9-
(optional)
10-
)
2+
(name trace_ppx)
3+
(public_name elpi.trace.ppx)
4+
(libraries ppxlib)
5+
(preprocessor_deps trace_ppx_config.mlh)
6+
(preprocess
7+
(pps ppxlib.metaquot ppx_optcomp))
8+
(kind ppx_rewriter)
9+
(ppx_runtime_libraries elpi.trace.runtime)
10+
(modules trace_ppx)
11+
(optional))
12+
13+
(rule
14+
(target trace_ppx_config.mlh)
15+
(action
16+
(with-stdout-to
17+
%{target}
18+
(progn
19+
(echo "(* Automatically generated, don't edit *)\n")
20+
(echo "[%%define ppxlib ")
21+
(run ./version_parser.exe %{version:ppxlib})
22+
(echo "]\n")))))
23+
24+
(executable
25+
(name version_parser)
26+
(modules version_parser)
27+
(libraries str))

trace/ppx/trace_ppx.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
4646
*)
4747

48+
[%%import "trace_ppx_config.mlh"]
49+
4850
open Ppxlib
4951
open Ast_builder.Default
5052

@@ -173,7 +175,11 @@ let map_trace = object(self)
173175
let args = List.map (fun (x,y) -> x, self#expression y) args in
174176
if args = [] then hd
175177
else { e with pexp_desc = Pexp_apply (hd,args)}
176-
| Pexp_function (params, constraint_, rest) when not !enabled ->
178+
| Pexp_fun(_,_,pat,rest) [@if ppxlib < (0,36,0)] when not !enabled ->
179+
let has_iftrace { ppat_attributes = l; _ } = has_iftrace_attribute l in
180+
if has_iftrace pat then self#expression rest
181+
else e
182+
| Pexp_function (params, constraint_, rest) [@if ppxlib >= (0,36,0)] when not !enabled ->
177183
let has_iftrace_pat { ppat_attributes = l; _ } = has_iftrace_attribute l in
178184
let does_not_have_iftrace_param = function
179185
| { pparam_desc = Pparam_val (_, _, pat); _ } -> not (has_iftrace_pat pat)

trace/ppx/version_parser.ml

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

0 commit comments

Comments
 (0)