Module Ppxlib.Driver
val add_arg : Caml.Arg.key -> Caml.Arg.spec -> doc:Ppxlib__.Import.string -> Ppxlib__.Import.unitAdd one argument to the command line
module Lint_error : sig ... endError reported by linters
module Cookies : sig ... endval register_transformation : ?extensions:Extension.t Ppxlib__.Import.list -> ?rules:Context_free.Rule.t Ppxlib__.Import.list -> ?enclose_impl:(Location.t Ppxlib__.Import.option -> Ppxlib__.Import.structure * Ppxlib__.Import.structure) -> ?enclose_intf:(Location.t Ppxlib__.Import.option -> Ppxlib__.Import.signature * Ppxlib__.Import.signature) -> ?impl:(Ppxlib__.Import.structure -> Ppxlib__.Import.structure) -> ?intf:(Ppxlib__.Import.signature -> Ppxlib__.Import.signature) -> ?lint_impl:(Ppxlib__.Import.structure -> Lint_error.t Ppxlib__.Import.list) -> ?lint_intf:(Ppxlib__.Import.signature -> Lint_error.t Ppxlib__.Import.list) -> ?preprocess_impl:(Ppxlib__.Import.structure -> Ppxlib__.Import.structure) -> ?preprocess_intf:(Ppxlib__.Import.signature -> Ppxlib__.Import.signature) -> ?aliases:Ppxlib__.Import.string Ppxlib__.Import.list -> Ppxlib__.Import.string -> Ppxlib__.Import.unitregister_transformation nameregisters a code transformation.nameis a logical name for the transformation (such assexp_convorbin_prot). It is mostly used for debugging purposes.rulesis a list of context independent rewriting rules, such as extension point expanders. This is what most code transformation should use. Rules from all registered transformations are all applied at the same time, before any other transformations. Moreover they are applied in a top-down manner, giving more control to extensions on how they interpret their payload.For instance:
- some extensions capture a pretty-print of the payload in their expansion and using top-down ensures that the payload is as close as possible to the original code
- some extensions process other extension in a special way inside their payload. For instance
%here(from ppx_here) will normally expand to a record of typeLexing.position. However when used inside%sexp(from ppx_sexp_value) it will expand to the human-readable sexp representation of a source code position.
extensionsis a special cases ofrulesand is deprecated. It is only kept for backward compatibility.enclose_implandenclose_intfproduces a header and footer for implementation/interface files. They are a special case ofimplandintf. The header is placed after any initial module-level attributes; the footer is placed after everything else. Both functions receive a location that denotes all of the items between header and footer, orNoneif the that list of items is empty.implis an optional function that is applied on implementation files andintfis an optional function that is applied on interface files. These two functions are applied on the AST of the whole file. They should only be used when the other mechanism are not enough. For instance if the transformation expands extension points that depend on the context.If no rewriter is using
implandintf, then the whole transformation is completely independent of the order in which the various rewriter are specified. Moreover the resulting driver will be faster as it will do only one pass (excluding safety checks) on the whole AST.lint_implandlint_intfare applied to the unprocessed source. Errors they return will be reported to the user as preprocessor warnings.Rewritings are applied in the following order:
- linters (
lint_impl,lint_intf) - preprocessing (
preprocess_impl,preprocess_intf) - context-independent rules (
rules,extensions) - whole-file transformations (
impl,intf,enclose_impl,enclose_intf)
val register_transformation_using_ocaml_current_ast : ?impl:(Migrate_parsetree.OCaml_current.Ast.Parsetree.structure -> Migrate_parsetree.OCaml_current.Ast.Parsetree.structure) -> ?intf:(Migrate_parsetree.OCaml_current.Ast.Parsetree.signature -> Migrate_parsetree.OCaml_current.Ast.Parsetree.signature) -> ?aliases:Ppxlib__.Import.string Ppxlib__.Import.list -> Ppxlib__.Import.string -> Ppxlib__.Import.unitSame as
register_transformationexcept that it uses the same AST as the current ocaml compiler.This is not the intended way of using driver. This is only for ppx rewriters that are not written using ppxlib but want to export a driver compatible library.
val register_code_transformation : name:Ppxlib__.Import.string -> ?aliases:Ppxlib__.Import.string Ppxlib__.Import.list -> impl:(Ppxlib__.Import.structure -> Ppxlib__.Import.structure) -> intf:(Ppxlib__.Import.signature -> Ppxlib__.Import.signature) -> Ppxlib__.Import.unitSame as:
register_transformation ~name ~impl ~intf ()
val register_correction : loc:Location.t -> repl:Ppxlib__.Import.string -> Ppxlib__.Import.unitRewriters might call this function to suggest a correction to the code source. When they do this, the driver will generate a
file.ml.ppx-correctedfile with the suggested replacement. The build system will then show the diff to the user who is free to accept the correction or not.
val register_process_file_hook : (Ppxlib__.Import.unit -> Ppxlib__.Import.unit) -> Ppxlib__.Import.unitHook called before processing a file
module Create_file_property : functor (Name : sig ... end) -> functor (T : Ppxlib__.Import.Sexpable.S) -> sig ... endCreate a new file property.
val standalone : Ppxlib__.Import.unit -> Ppxlib__.Import.unitSuitable for -pp and also usable as a standalone command line tool.
If the first command line argument is
-as-ppxthen it will run as a ppx rewriter.
val run_as_ppx_rewriter : Ppxlib__.Import.unit -> Ppxlib__.Import.unitSuitable for -ppx. Used only for the public release.
val pretty : Ppxlib__.Import.unit -> Ppxlib__.Import.boolIf
true, code transformations should avoid generating code that is not strictly necessary, such as extra type annotations.