Module Ppxlib.Pp_ast

This module implements pretty printers for the OCaml AST's version used by ppxlib.

Those pretty printers show the AST as its OCaml representation and do not pretty print the corresponding source code. For printing ASTs as source code use the Ppxlib.Pprintast module instead.

For example, calling Pp_ast.expression Format.std_formatter [%expr x + 2] will print:

   Pexp_apply
     ( Pexp_ident (Lident "+")
     , [ ( Nolabel, Pexp_ident (Lident "x"))
       ; ( Nolabel, Pexp_constant (Pconst_integer ( "2", None)))
       ]
     )

To keep the output easily readable, records with _desc fields such as Ppxlib.Ast.expression or Ppxlib.Ast.pattern are not printed as such and only the value of the corresponding _desc field is printed instead. This prevents AST nodes metadata, such as locations or attributes, from polluting the output, keeping it relatively concise and clean. The same goes for Location.loc values which are printed as the value of their txt field.

Location.t and Ppxlib.Ast.attributes are not displayed by default even outside of the records mentioned above.

The Config module below allows to override part or all of this behaviour. When configured to display locations or attributes, the entire record will be displayed, not only its _desc field.

module Config : sig ... end
type 'a pp = Format.formatter -> 'a -> unit
type 'a configurable = ?config:Config.t -> 'a pp
type 'a configured = 'a pp
module type S = sig ... end
module type Conf = sig ... end
module type Configured = S with type 'a printer = 'a configured
module type Configurable = S with type 'a printer = 'a configurable
module Make (Conf : Conf) : Configured
val make : Config.t -> (module Configured)
include Configurable
type 'a printer = 'a configurable