Skip to content

Commit

Permalink
Let the tool name pass throught when used as a -ppx (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremie Dimino <[email protected]>
  • Loading branch information
jeremiedimino committed Sep 10, 2018
1 parent 108d1d1 commit af75301
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.2.2
-----

- Let the tool name pass throught when used as a -ppx (#41, @diml)

0.2.1
-----

Expand Down
46 changes: 22 additions & 24 deletions src/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ module C = struct
|> Option.value ~default
end

let config ~hook ~expect_mismatch_handler =
Migrate_parsetree.Driver.make_config ()
~tool_name:"ppxlib_driver"
~extras:[C.T { hook
; expect_mismatch_handler
}]

let as_ppx_config () =
Migrate_parsetree.Driver.make_config ()
~tool_name:(Ocaml_common.Ast_mapper.tool_name ())
~include_dirs:!Ocaml_common.Clflags.include_dirs
~load_path:!Ocaml_common.Config.load_path
~debug:!Ocaml_common.Clflags.debug
?for_package:!Ocaml_common.Clflags.for_package

(*$*)
let real_map_structure config cookies st =
let { C. hook; expect_mismatch_handler } = C.find config in
Expand Down Expand Up @@ -466,23 +481,14 @@ let real_map_structure config cookies st =
st
;;

let map_structure_gen st ~hook ~expect_mismatch_handler
: Migrate_parsetree.Driver.some_structure =
let config =
Migrate_parsetree.Driver.make_config ()
~tool_name:"ppxlib_driver"
~extras:[C.T { hook
; expect_mismatch_handler
}]
in
let map_structure_gen st ~config : Migrate_parsetree.Driver.some_structure =
Migrate_parsetree.Driver.rewrite_structure
config
(module Ppxlib_ast.Selected_ast)
st

let map_structure st =
map_structure_gen st ~hook:Context_free.Generated_code_hook.nop
~expect_mismatch_handler:Context_free.Expect_mismatch_handler.nop
map_structure_gen st ~config:(as_ppx_config ())

(*$ str_to_sig _last_text_block *)
let real_map_signature config cookies sg =
Expand Down Expand Up @@ -520,23 +526,14 @@ let real_map_signature config cookies sg =
sg
;;

let map_signature_gen sg ~hook ~expect_mismatch_handler
: Migrate_parsetree.Driver.some_signature =
let config =
Migrate_parsetree.Driver.make_config ()
~tool_name:"ppxlib_driver"
~extras:[C.T { hook
; expect_mismatch_handler
}]
in
let map_signature_gen sg ~config : Migrate_parsetree.Driver.some_signature =
Migrate_parsetree.Driver.rewrite_signature
config
(module Ppxlib_ast.Selected_ast)
sg

let map_signature sg =
map_signature_gen sg ~hook:Context_free.Generated_code_hook.nop
~expect_mismatch_handler:Context_free.Expect_mismatch_handler.nop
map_signature_gen sg ~config:(as_ppx_config ())

(*$*)

Expand Down Expand Up @@ -844,9 +841,10 @@ let process_file (kind : Kind.t) fn ~input_name ~output_mode ~embed_errors ~outp
try
let ast = with_preprocessed_input fn ~f:(load_input kind fn input_name) in
let ast = extract_cookies ast in
let config = config ~hook ~expect_mismatch_handler in
match ast with
| Intf x -> Intf (map_signature_gen x ~hook ~expect_mismatch_handler)
| Impl x -> Impl (map_structure_gen x ~hook ~expect_mismatch_handler)
| Intf x -> Intf (map_signature_gen x ~config)
| Impl x -> Impl (map_structure_gen x ~config)
with exn when embed_errors ->
match Location.Error.of_exn exn with
| None -> raise exn
Expand Down
3 changes: 2 additions & 1 deletion src/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
(deps (cinaps_helpers (glob_files *.ml) (glob_files *.mli)))
(action (progn
(bash "${bin:cinaps} -no-color -diff-cmd - *.ml *.mli")
(diff? code_matcher.ml code_matcher.ml.cinaps-corrected)))))
(diff? code_matcher.ml code_matcher.ml.cinaps-corrected)
(diff? driver.ml driver.ml.cinaps-corrected)))))

;; This is to make the code compatible with different versions of
;; OCaml
Expand Down

0 comments on commit af75301

Please sign in to comment.