ocaml-migrate-parsetree

Convert OCaml parsetrees between different versions
IN THIS PACKAGE

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
type cookies

Registering rewriters

type 'types rewriter = config -> cookies -> 'types Migrate_parsetree__Migrate_parsetree_versions.get_mapper
val register : name:string -> ?reset_args:( unit -> unit ) -> ?args:(Arg.key * Arg.spec * Arg.doc) list -> ?position:int -> (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Ast_mapper.mapper = 'types Migrate_parsetree__Migrate_parsetree_versions.get_mapper and type Ast.Outcometree.out_class_type = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_class_type and type Ast.Outcometree.out_module_type = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_module_type and type Ast.Outcometree.out_phrase = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_phrase and type Ast.Outcometree.out_sig_item = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_sig_item and type Ast.Outcometree.out_type = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_type and type Ast.Outcometree.out_type_extension = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_type_extension and type Ast.Outcometree.out_value = 'types Migrate_parsetree__Migrate_parsetree_versions.get_out_value and type Ast.Parsetree.case = 'types Migrate_parsetree__Migrate_parsetree_versions.get_case and type Ast.Parsetree.core_type = 'types Migrate_parsetree__Migrate_parsetree_versions.get_core_type and type Ast.Parsetree.expression = 'types Migrate_parsetree__Migrate_parsetree_versions.get_expression and type Ast.Parsetree.extension_constructor = 'types Migrate_parsetree__Migrate_parsetree_versions.get_extension_constructor and type Ast.Parsetree.pattern = 'types Migrate_parsetree__Migrate_parsetree_versions.get_pattern and type Ast.Parsetree.signature = 'types Migrate_parsetree__Migrate_parsetree_versions.get_signature and type Ast.Parsetree.structure = 'types Migrate_parsetree__Migrate_parsetree_versions.get_structure and type Ast.Parsetree.toplevel_phrase = 'types Migrate_parsetree__Migrate_parsetree_versions.get_toplevel_phrase and type Ast.Parsetree.type_declaration = 'types Migrate_parsetree__Migrate_parsetree_versions.get_type_declaration and type Ast.Parsetree.type_extension = 'types Migrate_parsetree__Migrate_parsetree_versions.get_type_extension) -> 'types rewriter -> unit

Register a ppx rewriter. position is a integer that indicates when the ppx rewriter should be applied. It is guaranteed that if two ppx rewriters a and b have 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 is 0.

Note that more different position numbers means more AST conversions and slower rewriting, so think twice before setting position to a non-zero number.

val registered_args : unit -> (Arg.key * Arg.spec * Arg.doc) list

Return the list of command line arguments registered by rewriters

val reset_args : unit -> unit

Call all the registered reset_args callbacks

Running registered rewriters

val run_as_ast_mapper : ?exit_on_error:bool -> string list -> Ast_mapper.mapper
val run_as_ppx_rewriter : ?exit_on_error:bool -> ?argv:string array -> unit -> unit
val run_main : ?exit_on_error:bool -> ?argv:string array -> unit -> unit

Manual mapping

type some_signature =
| Sig : (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Parsetree.signature = 'concrete) * 'concrete -> some_signature
type some_structure =
| Str : (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Parsetree.structure = 'concrete) * 'concrete -> some_structure
val migrate_some_signature : (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Ast_mapper.mapper = 'version Migrate_parsetree__Migrate_parsetree_versions.get_mapper and type Ast.Outcometree.out_class_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_class_type and type Ast.Outcometree.out_module_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_module_type and type Ast.Outcometree.out_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_phrase and type Ast.Outcometree.out_sig_item = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_sig_item and type Ast.Outcometree.out_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type and type Ast.Outcometree.out_type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type_extension and type Ast.Outcometree.out_value = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_value and type Ast.Parsetree.case = 'version Migrate_parsetree__Migrate_parsetree_versions.get_case and type Ast.Parsetree.core_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_core_type and type Ast.Parsetree.expression = 'version Migrate_parsetree__Migrate_parsetree_versions.get_expression and type Ast.Parsetree.extension_constructor = 'version Migrate_parsetree__Migrate_parsetree_versions.get_extension_constructor and type Ast.Parsetree.pattern = 'version Migrate_parsetree__Migrate_parsetree_versions.get_pattern and type Ast.Parsetree.signature = 'version Migrate_parsetree__Migrate_parsetree_versions.get_signature and type Ast.Parsetree.structure = 'version Migrate_parsetree__Migrate_parsetree_versions.get_structure and type Ast.Parsetree.toplevel_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_toplevel_phrase and type Ast.Parsetree.type_declaration = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_declaration and type Ast.Parsetree.type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_extension) -> some_signature -> 'version Migrate_parsetree__Migrate_parsetree_versions.get_signature
val migrate_some_structure : (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Ast_mapper.mapper = 'version Migrate_parsetree__Migrate_parsetree_versions.get_mapper and type Ast.Outcometree.out_class_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_class_type and type Ast.Outcometree.out_module_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_module_type and type Ast.Outcometree.out_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_phrase and type Ast.Outcometree.out_sig_item = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_sig_item and type Ast.Outcometree.out_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type and type Ast.Outcometree.out_type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type_extension and type Ast.Outcometree.out_value = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_value and type Ast.Parsetree.case = 'version Migrate_parsetree__Migrate_parsetree_versions.get_case and type Ast.Parsetree.core_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_core_type and type Ast.Parsetree.expression = 'version Migrate_parsetree__Migrate_parsetree_versions.get_expression and type Ast.Parsetree.extension_constructor = 'version Migrate_parsetree__Migrate_parsetree_versions.get_extension_constructor and type Ast.Parsetree.pattern = 'version Migrate_parsetree__Migrate_parsetree_versions.get_pattern and type Ast.Parsetree.signature = 'version Migrate_parsetree__Migrate_parsetree_versions.get_signature and type Ast.Parsetree.structure = 'version Migrate_parsetree__Migrate_parsetree_versions.get_structure and type Ast.Parsetree.toplevel_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_toplevel_phrase and type Ast.Parsetree.type_declaration = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_declaration and type Ast.Parsetree.type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_extension) -> some_structure -> 'version Migrate_parsetree__Migrate_parsetree_versions.get_structure
val rewrite_signature : config -> (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Ast_mapper.mapper = 'version Migrate_parsetree__Migrate_parsetree_versions.get_mapper and type Ast.Outcometree.out_class_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_class_type and type Ast.Outcometree.out_module_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_module_type and type Ast.Outcometree.out_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_phrase and type Ast.Outcometree.out_sig_item = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_sig_item and type Ast.Outcometree.out_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type and type Ast.Outcometree.out_type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type_extension and type Ast.Outcometree.out_value = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_value and type Ast.Parsetree.case = 'version Migrate_parsetree__Migrate_parsetree_versions.get_case and type Ast.Parsetree.core_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_core_type and type Ast.Parsetree.expression = 'version Migrate_parsetree__Migrate_parsetree_versions.get_expression and type Ast.Parsetree.extension_constructor = 'version Migrate_parsetree__Migrate_parsetree_versions.get_extension_constructor and type Ast.Parsetree.pattern = 'version Migrate_parsetree__Migrate_parsetree_versions.get_pattern and type Ast.Parsetree.signature = 'version Migrate_parsetree__Migrate_parsetree_versions.get_signature and type Ast.Parsetree.structure = 'version Migrate_parsetree__Migrate_parsetree_versions.get_structure and type Ast.Parsetree.toplevel_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_toplevel_phrase and type Ast.Parsetree.type_declaration = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_declaration and type Ast.Parsetree.type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_extension) -> 'version Migrate_parsetree__Migrate_parsetree_versions.get_signature -> some_signature
val rewrite_structure : config -> (module Migrate_parsetree__Migrate_parsetree_versions.OCaml_version with type Ast.Ast_mapper.mapper = 'version Migrate_parsetree__Migrate_parsetree_versions.get_mapper and type Ast.Outcometree.out_class_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_class_type and type Ast.Outcometree.out_module_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_module_type and type Ast.Outcometree.out_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_phrase and type Ast.Outcometree.out_sig_item = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_sig_item and type Ast.Outcometree.out_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type and type Ast.Outcometree.out_type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_type_extension and type Ast.Outcometree.out_value = 'version Migrate_parsetree__Migrate_parsetree_versions.get_out_value and type Ast.Parsetree.case = 'version Migrate_parsetree__Migrate_parsetree_versions.get_case and type Ast.Parsetree.core_type = 'version Migrate_parsetree__Migrate_parsetree_versions.get_core_type and type Ast.Parsetree.expression = 'version Migrate_parsetree__Migrate_parsetree_versions.get_expression and type Ast.Parsetree.extension_constructor = 'version Migrate_parsetree__Migrate_parsetree_versions.get_extension_constructor and type Ast.Parsetree.pattern = 'version Migrate_parsetree__Migrate_parsetree_versions.get_pattern and type Ast.Parsetree.signature = 'version Migrate_parsetree__Migrate_parsetree_versions.get_signature and type Ast.Parsetree.structure = 'version Migrate_parsetree__Migrate_parsetree_versions.get_structure and type Ast.Parsetree.toplevel_phrase = 'version Migrate_parsetree__Migrate_parsetree_versions.get_toplevel_phrase and type Ast.Parsetree.type_declaration = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_declaration and type Ast.Parsetree.type_extension = 'version Migrate_parsetree__Migrate_parsetree_versions.get_type_extension) -> 'version Migrate_parsetree__Migrate_parsetree_versions.get_structure -> some_structure