Ppxlib.Pp_astThis 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 ... endtype 'a pp = Stdlib.Format.formatter -> 'a -> unittype 'a configured = 'a ppmodule type S = sig ... endmodule type Conf = sig ... endmodule type Configured = S with type 'a printer = 'a configuredmodule type Configurable = S with type 'a printer = 'a configurablemodule Make (Conf : Conf) : Configuredval make : Config.t -> (module Configured)module Default : Configuredinclude Configurabletype 'a printer = 'a configurableval structure : Astlib.Ast_500.Parsetree.structure_item list printerval structure_item : Astlib.Ast_500.Parsetree.structure_item printerval signature : Astlib.Ast_500.Parsetree.signature_item list printerval signature_item : Astlib.Ast_500.Parsetree.signature_item printerval expression : Astlib.Ast_500.Parsetree.expression printerval pattern : Astlib.Ast_500.Parsetree.pattern printerval core_type : Astlib.Ast_500.Parsetree.core_type printer