Skip to content

Commit

Permalink
Merge pull request #22 from LexiFi/mlasson-ppxlib
Browse files Browse the repository at this point in the history
Use ppxlib instead of OMP
  • Loading branch information
mlasson committed Apr 1, 2021
2 parents 613d9a4 + 7695165 commit ea90c65
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 200 deletions.
42 changes: 22 additions & 20 deletions compatibility/compatibility.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(* See the attached LICENSE file. *)
(* Copyright 2016 by LexiFi. *)

open Migrate_parsetree.Ast_404
open Ast_mapper
open Ppxlib

open Parsetree
open Longident
open Location
Expand All @@ -14,25 +14,27 @@ let ocaml_major, ocaml_minor =
with Scanf.Scan_failure _ -> 4, 7

let substitute =
{ default_mapper with
expr =
begin fun mapper -> function

(* Subsitute String.capitalize_ascii to support 4.02 *)
| ({pexp_desc =
Pexp_ident ({txt = Ldot (Lident "String", "capitalize_ascii"); _} as ident); _} as expr) when ocaml_major = 4 && ocaml_minor = 2 ->
{ expr with pexp_desc = Pexp_ident { ident with txt = Ldot (Lident "String", "capitalize")}}

(* Subsitute Stdlib into Pervasives *)
| ({pexp_desc =
Pexp_ident ({txt = Ldot (Lident "Stdlib", smth); _} as ident); _} as expr) when ocaml_major = 4 && ocaml_minor < 7 ->
{ expr with pexp_desc = Pexp_ident { ident with txt = Ldot (Lident "Pervasives", smth)}}

| expr -> default_mapper.expr mapper expr
end
}
object
inherit Ast_traverse.map as super

method! expression expr =
match expr with
(* Subsitute String.capitalize_ascii to support 4.02 *)
| ({pexp_desc =
Pexp_ident ({txt = Ldot (Lident "String", "capitalize_ascii"); _} as ident); _} as expr) when ocaml_major = 4 && ocaml_minor = 2 ->
{ expr with pexp_desc = Pexp_ident { ident with txt = Ldot (Lident "String", "capitalize")}}
(* Subsitute Stdlib into Pervasives *)
| ({pexp_desc =
Pexp_ident ({txt = Ldot (Lident "Stdlib", smth); _} as ident); _} as expr) when ocaml_major = 4 && ocaml_minor < 7 ->
{ expr with pexp_desc = Pexp_ident { ident with txt = Ldot (Lident "Pervasives", smth)}}
| expr -> super # expression expr

end

let mapper _ _ = substitute

let () =
Migrate_parsetree.(Driver.register ~name:"compatibility" Versions.ocaml_404 mapper)
Ppxlib.Driver.register_transformation
"compatibility"
~impl:(substitute # structure)
~intf:(substitute # signature)
2 changes: 1 addition & 1 deletion compatibility/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(library
(name compatibility)
(kind ppx_rewriter)
(libraries ocaml-migrate-parsetree)
(libraries ppxlib)
(preprocess no_preprocessing))
2 changes: 1 addition & 1 deletion landmarks.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ doc: "http://lexifi.github.io/landmarks/"
run-test: ["dune" "runtest" "-p" name]
depends: [
"ocaml" { >= "4.05" }
"ocaml-migrate-parsetree" { >= "1.6.0" }
"ppxlib" { >= "0.21.0" }
"dune" {build & >= "2.0"}
]

Expand Down
3 changes: 1 addition & 2 deletions ppx/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
(name ppx_landmarks)
(public_name landmarks.ppx)
(private_modules mapper register)
(flags -open Migrate_parsetree -open Ast_408)
(kind ppx_rewriter)
(libraries ocaml-migrate-parsetree)
(libraries ppxlib)
(preprocess
(pps compatibility)))
Loading

0 comments on commit ea90c65

Please sign in to comment.