package ppxlib

  1. Overview
  2. Docs
Standard infrastructure for ppx rewriters

Install

Dune Dependency

Authors

Maintainers

Sources

757f6c284b1fe748d5027eef3bbef924b6bbd7ce.tar.gz
sha256=89a98c95ddd0bfbac17b5a936f6811af7097be3258c482d5859b73e9de9b4552
sha512=b19306473d867252d382e58e9b697531c5edccdc9283b5eaf72f524803c2fca2a58a5e8f25bee198b00de82cf8ef805b43f7488791c3ac5beb0ffba938ded826

doc/ppxlib/Ppxlib/Ast_traverse/index.html

Module Ppxlib.Ast_traverseSource

This module provides AST traversal classes, such as maps, iterations, folds, etc. on the Parsetree types.

For a detailed explanation on this module, refer to the relevant part of the manual.

API

To use these classes, inherit from them and override the methods corresponding to the types from Parsetree you want to process. For instance to collect all the string constants in a structure:

  let string_constants_of =
    object
      inherit [string list] Ast_traverse.fold as super

      method! expression e acc =
        let acc = super#expression e acc in
        match e.pexp_desc with
        | Pexp_constant (Const_string (s, _)) -> s :: acc
        | _ -> acc

      method! pattern p acc =
        let acc = super#pattern p acc in
        match p.ppat_desc with
        | Ppat_constant (Const_string (s, _)) -> s :: acc
        | _ -> acc
    end

  let string_constants_of_structure = string_constants_of#structure
Sourceclass map : object ... end
Sourceclass iter : object ... end
Sourceclass 'acc fold : object ... end
Sourceclass 'acc fold_map : object ... end
Sourceclass 'ctx map_with_context : object ... end
Sourceval do_not_enter_value_binding : (Astlib.Ast_502.Parsetree.value_binding, unit) Attribute.t
Sourceval do_not_enter_value_description : (Astlib.Ast_502.Parsetree.value_description, unit) Attribute.t
Sourceval do_not_enter_module_binding : (Astlib.Ast_502.Parsetree.module_binding, unit) Attribute.t
Sourceval do_not_enter_module_declaration : (Astlib.Ast_502.Parsetree.module_declaration, unit) Attribute.t
Sourceval do_not_enter_module_type_declaration : (Astlib.Ast_502.Parsetree.module_type_declaration, unit) Attribute.t
Sourceval do_not_enter_let_module : (Astlib.Ast_502.Parsetree.expression, unit) Attribute.t
Sourceclass virtual 'res lift : object ... end
Sourceclass virtual ['ctx, 'res] lift_map_with_context : object ... end
Sourceclass sexp_of : object ... end
Sourceval sexp_of : sexp_of
OCaml

Innovation. Community. Security.