package ppxx

  1. Overview
  2. Docs

Source file ppx.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(* PPX related tools *)

open Utils
open Migrate_parsetree
   
let handle_error f =
  try f () with 
  | e ->
      Format.eprintf "%a@."  Location.report_exception e;
      exit 2
      
module Make(A : sig 
  val name : string
  val options : (Arg.key * Arg.spec * Arg.doc) list
  val make_mapper : Driver.config -> Driver.cookies -> Ast_405.Ast_mapper.mapper
end) = struct
  open A

  let debug = ref false
  let opt_debug = ( "-debug", Arg.Set debug, "ppx debug mode which takes .ml and .mli" )

  (* Some command line argument hack *)
  let check_debug () =
    let options' =
      opt_debug :: List.map (fun (k,_,d) -> k, Arg.Unit (fun () -> ()), d) options
    in
    Arg.parse options' (fun _ -> ())
      (Printf.sprintf "%s [options] <input ast file> <output ast file>" name);
    Arg.current := 0; (* reset for the next Arg.parse *)
    !debug

  let register () = 
    Driver.register
      ~name
      ~args:A.options
      Versions.ocaml_405
      make_mapper
  
  let legacy_main () =
    let debug = check_debug () in
    Driver.register
      ~name
      ~args:(opt_debug :: options)
      Versions.ocaml_405
      make_mapper;
    if debug then Migrate_parsetree.Driver.run_main ()
    else Driver.run_as_ppx_rewriter ()
end
OCaml

Innovation. Community. Security.