package ocaml-migrate-parsetree

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Abstracting an OCaml frontend

module type Ast = sig ... end

Abstract view of a version of an OCaml Ast

type 'a _types = 'a constraint 'a = < structure : _ ; signature : _ ; toplevel_phrase : _ ; core_type : _ ; expression : _ ; pattern : _ ; case : _ ; type_declaration : _ ; type_extension : _ ; extension_constructor : _ ; out_value : _ ; out_type : _ ; out_class_type : _ ; out_module_type : _ ; out_sig_item : _ ; out_type_extension : _ ; out_phrase : _ ; mapper : _ >
type 'a get_structure = 'x constraint 'a _types = < structure : 'x.. >
type 'a get_signature = 'x constraint 'a _types = < signature : 'x.. >
type 'a get_toplevel_phrase = 'x constraint 'a _types = < toplevel_phrase : 'x.. >
type 'a get_core_type = 'x constraint 'a _types = < core_type : 'x.. >
type 'a get_expression = 'x constraint 'a _types = < expression : 'x.. >
type 'a get_pattern = 'x constraint 'a _types = < pattern : 'x.. >
type 'a get_case = 'x constraint 'a _types = < case : 'x.. >
type 'a get_type_declaration = 'x constraint 'a _types = < type_declaration : 'x.. >
type 'a get_type_extension = 'x constraint 'a _types = < type_extension : 'x.. >
type 'a get_extension_constructor = 'x constraint 'a _types = < extension_constructor : 'x.. >
type 'a get_out_value = 'x constraint 'a _types = < out_value : 'x.. >
type 'a get_out_type = 'x constraint 'a _types = < out_type : 'x.. >
type 'a get_out_class_type = 'x constraint 'a _types = < out_class_type : 'x.. >
type 'a get_out_module_type = 'x constraint 'a _types = < out_module_type : 'x.. >
type 'a get_out_sig_item = 'x constraint 'a _types = < out_sig_item : 'x.. >
type 'a get_out_type_extension = 'x constraint 'a _types = < out_type_extension : 'x.. >
type 'a get_out_phrase = 'x constraint 'a _types = < out_phrase : 'x.. >
type 'a get_mapper = 'x constraint 'a _types = < mapper : 'x.. >
type _ witnesses = private ..

A version of the OCaml frontend packs the ast with type witnesses so that equalities can be recovered dynamically.

type _ migration_info

migration_info is an opaque type that is used to generate migration functions.

module type OCaml_version = sig ... end

An OCaml frontend versions an Ast, version number and some witnesses for conversion.

Concrete frontend instances

module OCaml_402 : OCaml_version with module Ast = Ast_402
module OCaml_403 : OCaml_version with module Ast = Ast_403
module OCaml_404 : OCaml_version with module Ast = Ast_404
module OCaml_405 : OCaml_version with module Ast = Ast_405
module OCaml_406 : OCaml_version with module Ast = Ast_406
module OCaml_407 : OCaml_version with module Ast = Ast_407
module OCaml_408 : OCaml_version with module Ast = Ast_408
module OCaml_409 : OCaml_version with module Ast = Ast_409
module OCaml_410 : OCaml_version with module Ast = Ast_410
module OCaml_current = OCaml_410
val all_versions : (module OCaml_version) list

Migrating between different versions

type ('a, 'b) type_comparison =
  1. | Lt : ('a, 'b) type_comparison
  2. | Eq : ('a, 'a) type_comparison
  3. | Gt : ('a, 'b) type_comparison
val compare_ocaml_version : 'a ocaml_version -> 'b ocaml_version -> ('a, 'b) type_comparison
type ('from, 'to_) migration_functions = {
  1. copy_structure : 'from get_structure -> 'to_ get_structure;
  2. copy_signature : 'from get_signature -> 'to_ get_signature;
  3. copy_toplevel_phrase : 'from get_toplevel_phrase -> 'to_ get_toplevel_phrase;
  4. copy_core_type : 'from get_core_type -> 'to_ get_core_type;
  5. copy_expression : 'from get_expression -> 'to_ get_expression;
  6. copy_pattern : 'from get_pattern -> 'to_ get_pattern;
  7. copy_case : 'from get_case -> 'to_ get_case;
  8. copy_type_declaration : 'from get_type_declaration -> 'to_ get_type_declaration;
  9. copy_type_extension : 'from get_type_extension -> 'to_ get_type_extension;
  10. copy_extension_constructor : 'from get_extension_constructor -> 'to_ get_extension_constructor;
  11. copy_out_value : 'from get_out_value -> 'to_ get_out_value;
  12. copy_out_type : 'from get_out_type -> 'to_ get_out_type;
  13. copy_out_class_type : 'from get_out_class_type -> 'to_ get_out_class_type;
  14. copy_out_module_type : 'from get_out_module_type -> 'to_ get_out_module_type;
  15. copy_out_sig_item : 'from get_out_sig_item -> 'to_ get_out_sig_item;
  16. copy_out_type_extension : 'from get_out_type_extension -> 'to_ get_out_type_extension;
  17. copy_out_phrase : 'from get_out_phrase -> 'to_ get_out_phrase;
  18. copy_mapper : 'from get_mapper -> 'to_ get_mapper;
}

A record for migrating each AST construct between two known versions

val migration_identity : ('a, 'a) migration_functions

Migrating to the same version is no-op

val migration_compose : ('a, 'b) migration_functions -> ('b, 'c) migration_functions -> ('a, 'c) migration_functions

Migrations can be composed

Represent the next or previous version of an Ast

type 'from immediate_migration =
  1. | No_migration : 'from immediate_migration
    (*

    Cannot migrate earliest or latest supported version

    *)
  2. | Immediate_migration : ('from, 'to_) migration_functions * 'to_ ocaml_version -> 'from immediate_migration
    (*

    Pack the migration functions and the new version

    *)
val immediate_migration : 'types ocaml_version -> [< `Next | `Previous ] -> 'types immediate_migration
val migrate : 'from ocaml_version -> 'to_ ocaml_version -> ('from, 'to_) migration_functions

Convenience definitions

module Convert (A : OCaml_version) (B : OCaml_version) : sig ... end

Module level migration

OCaml

Innovation. Community. Security.