Skip to content

Commit

Permalink
Lots of cleanup
Browse files Browse the repository at this point in the history
* Remove some improperly applied dependencies
* More README details
* Use the 4.06 AST from OMP and ppx_tools_versioned
* Add repl, examples and test targets for make
* Simplify how jbuilder builds examples
  • Loading branch information
hcarty committed Mar 22, 2018
1 parent 48e577e commit a1d3aa2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 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

# v0.3.0

* Use ocaml-migrate-parsetree
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
.PHONY: all clean examples repl test

all:
jbuilder build
jbuilder build --dev

clean:
rm -rf _build/ *.install
jbuilder clean

examples:
jbuilder build @example --dev

repl:
jbuilder utop src -- -require ppx_defer

test: examples
jbuilder exec examples/ic.exe
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ Thanks to Drup for guidance in figuring out ppx details!

## Using ppx_defer

As a simple example this code
```ocaml
let () =
[%defer print_endline "world"];
print_endline "Hello"
```
will print
```
Hello
world
```
as `print_endline "world"` was deferred until after `print_endline "Hello"`.

A more common use case would be closing an external resource at the end of the
current expression.
```ocaml
let () =
let ic = open_in_bin "some_file" in
Expand All @@ -18,5 +33,12 @@ let () =
let bytes = really_input_string ic length in
print_endline bytes
```
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.
4 changes: 4 additions & 0 deletions examples/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
(executable
((name ic)
(preprocess (pps (ppx_defer)))))

(alias
((name example)
(deps (ic.exe))))
5 changes: 0 additions & 5 deletions jbuild

This file was deleted.

6 changes: 2 additions & 4 deletions src/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
(synopsis "Defer evaluation of expressions")
(modules (ppx_defer))
(libraries (compiler-libs.common
ocaml-migrate-parsetree
ppx_tools_versioned
ppx_tools_versioned.metaquot_404))
ocaml-migrate-parsetree))
(kind ppx_rewriter)
(preprocess (pps (ppx_tools_versioned.metaquot_404)))))
(preprocess (pps (ppx_tools_versioned.metaquot_406)))))
4 changes: 2 additions & 2 deletions src/ppx_defer.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Migrate_parsetree
open OCaml_404.Ast
open OCaml_406.Ast
open Ast_mapper
open Parsetree

Expand Down Expand Up @@ -68,5 +68,5 @@ let defer_mapper =
}

let () =
Driver.register ~name:"ppx_defer" Versions.ocaml_404
Driver.register ~name:"ppx_defer" Versions.ocaml_406
(fun _config _cookies -> defer_mapper)

0 comments on commit a1d3aa2

Please sign in to comment.