State a rewriter can access
type extra = ..type config = {tool_name : string;include_dirs : string list;load_path : string list;debug : bool;for_package : string option;Additional parameters that can be passed by a caller of
rewrite_{signature,structure}to a specific register rewriter.extras : extra list;}
val make_config : tool_name:string -> ?include_dirs:string list -> ?load_path:string list -> ?debug:bool -> ?for_package:string -> ?extras:extra list -> unit -> config
val get_cookie : cookies -> string -> 'types Versions.ocaml_version -> 'types Versions.get_expression optionval set_cookie : cookies -> string -> 'types Versions.ocaml_version -> 'types Versions.get_expression -> unitval set_global_cookie : string -> 'types Versions.ocaml_version -> 'types Versions.get_expression -> unit
Registering rewriters
type 'types rewriter = config -> cookies -> 'types Versions.get_mapper
val register : name:string -> ?reset_args:(unit -> unit) -> ?args:(Stdlib.Arg.key * Stdlib.Arg.spec * Stdlib.Arg.doc) list -> ?position:int -> 'types Versions.ocaml_version -> 'types rewriter -> unitRegister a ppx rewriter.
positionis a integer that indicates when the ppx rewriter should be applied. It is guaranteed that if two ppx rewritersaandbhave different position numbers, then the one with the lowest number will be applied first. The rewriting order of ppx rewriters with the same position number is not specified. The default position is0.Note that more different position numbers means more AST conversions and slower rewriting, so think twice before setting
positionto a non-zero number.
val registered_args : unit -> (Stdlib.Arg.key * Stdlib.Arg.spec * Stdlib.Arg.doc) listReturn the list of command line arguments registered by rewriters
Running registered rewriters
val run_as_ast_mapper : ?exit_on_error:bool -> string list -> Ast_mapper.mapperval run_as_ppx_rewriter : ?exit_on_error:bool -> ?argv:string array -> unit -> unitval run_main : ?exit_on_error:bool -> ?argv:string array -> unit -> unit
Manual mapping
type some_signature =| Sig : (module Versions.OCaml_version with type Ast.Parsetree.signature = 'concrete) * 'concrete -> some_signaturetype some_structure =| Str : (module Versions.OCaml_version with type Ast.Parsetree.structure = 'concrete) * 'concrete -> some_structure
val migrate_some_signature : 'version Versions.ocaml_version -> some_signature -> 'version Versions.get_signatureval migrate_some_structure : 'version Versions.ocaml_version -> some_structure -> 'version Versions.get_structureval rewrite_signature : config -> 'version Versions.ocaml_version -> 'version Versions.get_signature -> some_signatureval rewrite_structure : config -> 'version Versions.ocaml_version -> 'version Versions.get_structure -> some_structure