package ppxlib

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

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 'node pp = ?config:Config.t -> Stdlib.Format.formatter -> 'node -> unit
OCaml

Innovation. Community. Security.