Module Ppx_driver

val add_arg : Caml.Arg.key ‑> Caml.Arg.spec ‑> doc:Ppx_driver__.Import.string ‑> Ppx_driver__.Import.unit

Add one argument to the command line

module Lint_error : sig ... end

Error reported by linters

module Cookies : sig ... end
val register_transformation : ?⁠extensions:Ppx_driver__.Import.Extension.t Ppx_driver__.Import.list ‑> ?⁠rules:Ppx_driver__.Import.Context_free.Rule.t Ppx_driver__.Import.list ‑> ?⁠enclose_impl:(Ppx_driver__.Import.Location.t Ppx_driver__.Import.option ‑> Ppx_driver__.Import.structure * Ppx_driver__.Import.structure) ‑> ?⁠enclose_intf:(Ppx_driver__.Import.Location.t Ppx_driver__.Import.option ‑> Ppx_driver__.Import.signature * Ppx_driver__.Import.signature) ‑> ?⁠impl:(Ppx_driver__.Import.structure ‑> Ppx_driver__.Import.structure) ‑> ?⁠intf:(Ppx_driver__.Import.signature ‑> Ppx_driver__.Import.signature) ‑> ?⁠lint_impl:(Ppx_driver__.Import.structure ‑> Lint_error.t Ppx_driver__.Import.list) ‑> ?⁠lint_intf:(Ppx_driver__.Import.signature ‑> Lint_error.t Ppx_driver__.Import.list) ‑> Ppx_driver__.Import.string ‑> Ppx_driver__.Import.unit

register_transformation name registers a code transformation.

name is a logical name for the transformation (such as sexp_conv or bin_prot). It is mostly used for debugging purposes.

rules is 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:

extensions is a special cases of rules and is deprecated. It is only kept for backward compatibility.

enclose_impl and enclose_intf produces a header and footer for implementation/interface files. They are a special case of impl and intf. Both functions receive a location that denotes the whole file, or None if the file contains nothing.

impl is an optional function that is applied on implementation files and intf is 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 impl and intf, 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_impl and lint_intf are applied to the unprocessed source. Errors they return will be reported to the user as preprocessor warnings.

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) ‑> Ppx_driver__.Import.string ‑> Ppx_driver__.Import.unit

Same as register_transformation except that it uses the same AST as the current ocaml compiler.

This is not the intended way of using ppx_driver. This is only for ppx rewriters that are not written using ppx_core/ppx_driver but want to export a ppx_driver compatible library.

val register_code_transformation : name:Ppx_driver__.Import.string ‑> impl:(Ppx_driver__.Import.structure ‑> Ppx_driver__.Import.structure) ‑> intf:(Ppx_driver__.Import.signature ‑> Ppx_driver__.Import.signature) ‑> Ppx_driver__.Import.unit

Same as:

      register_transformation
        ~name
        ~impl
        ~intf
        ()
val standalone : Ppx_driver__.Import.unit ‑> Ppx_driver__.Import.unit

Suitable for -pp and also usable as a standalone command line tool.

If the first command line argument is -as-ppx then it will run as a ppx rewriter.

val run_as_ppx_rewriter : Ppx_driver__.Import.unit ‑> Ppx_driver__.Import.unit

Suitable for -ppx. Used only for the public release.

val pretty : Ppx_driver__.Import.unit ‑> Ppx_driver__.Import.bool

If true, code transformations should avoid generating code that is not strictly necessary, such as extra type annotations.