diff --git a/CHANGES.md b/CHANGES.md index 6a4391c..5c9d1f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,7 @@ # vNext -* Use 4.06 AST from ocaml-migrate-parsetree and ppx\_tools\_versioned -* Add `make repl` target to automatically compile + load the source tree's ppx - into a custom utop session +* Upgrade to dune +* Use 4.08 AST from ocaml-migrate-parsetree and ppx\_tools\_versioned # v0.3.0 diff --git a/Makefile b/Makefile index 0b3a5d4..e1f7d1d 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,10 @@ -.PHONY: all clean examples repl test +.PHONY: all clean test all: - jbuilder build --dev + dune build clean: - jbuilder clean + dune clean -examples: - jbuilder build @example --dev - -repl: - jbuilder utop src -- -require ppx_defer - -test: examples - jbuilder exec examples/ic.exe +test: + dune runtest diff --git a/README.md b/README.md index 5f9a056..bf10e98 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,3 @@ This will `close_in ic` at the end of the current expression, even if an exception is raised. See the `examples/` directory for more examples. - -## Trying it out from source - -`make repl` will start a custom utop session with the current source tree's -version of the ppx extension loaded and ready to use. diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..50aff96 --- /dev/null +++ b/dune-project @@ -0,0 +1,3 @@ +(lang dune 2.0) +(name ppx_defer) +(allow_approximate_merlin) diff --git a/examples/dune b/examples/dune new file mode 100644 index 0000000..d1673cd --- /dev/null +++ b/examples/dune @@ -0,0 +1,12 @@ +(test + (name ic) + (modules ic) + (preprocess + (pps ppx_defer))) + +(test + (name ic_lwt) + (modules ic_lwt) + (preprocess + (pps ppx_defer lwt_ppx)) + (libraries lwt.unix)) diff --git a/examples/ic.expected b/examples/ic.expected new file mode 100644 index 0000000..353b355 --- /dev/null +++ b/examples/ic.expected @@ -0,0 +1,7 @@ +let () = + let ic = open_in_bin "ic.ml" in + [%defer close_in ic]; + let length = in_channel_length ic in + let bytes = really_input_string ic length in + print_endline bytes + diff --git a/examples/ic.ml b/examples/ic.ml index 50edd4e..104ffbb 100644 --- a/examples/ic.ml +++ b/examples/ic.ml @@ -1,5 +1,5 @@ let () = - let ic = open_in_bin "README.md" in + let ic = open_in_bin "ic.ml" in [%defer close_in ic]; let length = in_channel_length ic in let bytes = really_input_string ic length in diff --git a/examples/ic_lwt.expected b/examples/ic_lwt.expected new file mode 100644 index 0000000..f93bebd --- /dev/null +++ b/examples/ic_lwt.expected @@ -0,0 +1,8 @@ +let promise = + let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "ic_lwt.ml" in + [%defer.lwt Lwt_io.close ic]; + let%lwt bytes = Lwt_io.read ic in + Lwt_io.printl bytes + +let () = Lwt_main.run promise + diff --git a/examples/ic_lwt.ml b/examples/ic_lwt.ml index 7251cbb..bef5f25 100644 --- a/examples/ic_lwt.ml +++ b/examples/ic_lwt.ml @@ -1,5 +1,7 @@ -let%lwt () = - let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "README.md" in +let promise = + let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "ic_lwt.ml" in [%defer.lwt Lwt_io.close ic]; let%lwt bytes = Lwt_io.read ic in Lwt_io.printl bytes + +let () = Lwt_main.run promise diff --git a/examples/jbuild b/examples/jbuild deleted file mode 100644 index ee379c8..0000000 --- a/examples/jbuild +++ /dev/null @@ -1,9 +0,0 @@ -(jbuild_version 1) - -(executable - ((name ic) - (preprocess (pps (ppx_defer))))) - -(alias - ((name example) - (deps (ic.exe)))) diff --git a/pkg/pkg.ml b/pkg/pkg.ml deleted file mode 100644 index 1a04c2b..0000000 --- a/pkg/pkg.ml +++ /dev/null @@ -1,2 +0,0 @@ -#use "topfind" -#require "topkg-jbuilder.auto" diff --git a/ppx_defer.opam b/ppx_defer.opam index 03b37da..b194b1f 100644 --- a/ppx_defer.opam +++ b/ppx_defer.opam @@ -1,14 +1,15 @@ -opam-version: "1.2" +opam-version: "2.0" maintainer: "Hezekiah M. Carty " authors: [ "Hezekiah M. Carty " ] license: "MIT" +synopsis: "Go-like [%defer later]; now syntax" homepage: "https://github.com/hcarty/ppx_defer" bug-reports: "https://github.com/hcarty/ppx_defer/issues" -dev-repo: "https://github.com/hcarty/ppx_defer.git" -build:[ "jbuilder" "build" "-p" name "-j" jobs ] +dev-repo: "git+https://github.com/hcarty/ppx_defer.git" +build:[ "dune" "build" "-p" name "-j" jobs ] depends: [ - "jbuilder" {build & >= "1.0+beta9"} + "ocaml" {>= "4.02.3"} + "dune" {>= "2.0"} "ocaml-migrate-parsetree" "ppx_tools_versioned" ] -available: [ ocaml-version >= "4.02.3" ] diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..b6c20e8 --- /dev/null +++ b/src/dune @@ -0,0 +1,9 @@ +(library + (name ppx_defer) + (public_name ppx_defer) + (synopsis "Defer evaluation of expressions") + (modules ppx_defer) + (libraries compiler-libs.common ocaml-migrate-parsetree) + (kind ppx_rewriter) + (preprocess + (pps ppx_tools_versioned.metaquot_408))) diff --git a/src/jbuild b/src/jbuild deleted file mode 100644 index 7857958..0000000 --- a/src/jbuild +++ /dev/null @@ -1,11 +0,0 @@ -(jbuild_version 1) - -(library - ((name ppx_defer) - (public_name ppx_defer) - (synopsis "Defer evaluation of expressions") - (modules (ppx_defer)) - (libraries (compiler-libs.common - ocaml-migrate-parsetree)) - (kind ppx_rewriter) - (preprocess (pps (ppx_tools_versioned.metaquot_406))))) diff --git a/src/ppx_defer.ml b/src/ppx_defer.ml index 1bee578..0e7cf47 100644 --- a/src/ppx_defer.ml +++ b/src/ppx_defer.ml @@ -1,5 +1,5 @@ open Migrate_parsetree -open OCaml_406.Ast +open OCaml_408.Ast open Ast_mapper open Parsetree @@ -68,5 +68,5 @@ let defer_mapper = } let () = - Driver.register ~name:"ppx_defer" Versions.ocaml_406 + Driver.register ~name:"ppx_defer" Versions.ocaml_408 (fun _config _cookies -> defer_mapper)