package ppx_tools_versioned

  1. Overview
  2. Docs
A variant of ppx_tools based on ocaml-migrate-parsetree

Install

Dune Dependency

Authors

Maintainers

Sources

5.2.tar.gz
sha256=e8a4b7adac8c7a86a8db427834b42a114922e988c89fe0cdb02b7ceeb146c0fd
md5=f2f1a1cd11aeb9f91a92ab691720a401

Description

Tags

syntax

Published: 09 Jul 2018

README

ppx_tools

Tools for authors of syntactic tools (such as ppx rewriters).

This package is licensed by LexiFi under the terms of the MIT license.

The tools are installed as a findlib package called 'ppx_tools'. Executables are thus accessible through the ocamlfind driver (e.g.: ocamlfind ppx_tools/dumpast).

Main contributors:

  • Alain Frisch

  • Peter Zotov (whitequark)

  • Gabriel Radanne (Drup)

Master :

4.05 :

4.04 :

4.03 :

4.02 :

ppx_metaquot

A ppx filter to help writing programs which manipulate the Parsetree, by allowing the programmer to use concrete syntax for expressions creating Parsetree fragments and patterns deconstructing Parsetree fragments. See the top of ppx_metaquot.ml for a description of the supported extensions.

Usage:

ocamlfind ocamlc -c -package ppx_tools.metaquot my_ppx_code.ml

rewriter

An utility to help testing ppx rewriters that runs the rewriter on user-provided code and returns the result.

Usage:

ocamlfind ppx_tools/rewriter ./my_ppx_rewriter sample.ml

See the integrated help message for more details:

ocamlfind ppx_tools/rewriter -help

Ast_mapper_class

This module implements an API similar to Ast_mapper from the compiler-libs, i.e. a generic mapper from Parsetree to Parsetree implemeting a deep identity copy, which can be customized with a custom behavior for each syntactic category. The difference with Ast_mapper is that Ast_mapper_class implements the open recursion using a class.

dumpast

This tool parses fragments of OCaml code (or entire source files) and dump the resulting internal Parsetree representation. Intended uses:

  • Help to learn about the OCaml Parsetree structure and how it corresponds to OCaml source syntax.

  • Create fragments of Parsetree to be copy-pasted into the source code of syntax-manipulating programs (such as ppx rewriters).

Usage:

ocamlfind ppx_tools/dumpast -e "1 + 2"

The tool can be used to show the Parsetree representation of small fragments of syntax passed on the command line (-e for expressions, -p for patterns, -t for type expressions) or for entire .ml/mli files. The standard -pp and -ppx options are supported, but only applied on whole files. The tool has further option to control how location and attribute fields in the Parsetree should be displayed.

genlifter

This tool generates a virtual "lifter" class for one or several OCaml type constructors. It does so by loading the .cmi files which define those types. The generated lifter class exposes one method to "reify" type constructors passed on the command-line and other type constructors accessible from them. The class is parametrized over the target type of the reification, and it must provide method to deal with basic types (int, string, char, int32, int64, nativeint) and data type builders (record, constr, tuple, list, array). As an example, calling:

ocamlfind ppx_tools/genlifter -I +compiler-libs Location.t

produces the following class:

class virtual ['res] lifter =
  object (this)
    method lift_Location_t : Location.t -> 'res=
      fun
        { Location.loc_start = loc_start; Location.loc_end = loc_end;
          Location.loc_ghost = loc_ghost }
         ->
        this#record "Location.t"
          [("loc_start", (this#lift_Lexing_position loc_start));
          ("loc_end", (this#lift_Lexing_position loc_end));
          ("loc_ghost", (this#lift_bool loc_ghost))]
    method lift_bool : bool -> 'res=
      function
      | false  -> this#constr "bool" ("false", [])
      | true  -> this#constr "bool" ("true", [])
    method lift_Lexing_position : Lexing.position -> 'res=
      fun
        { Lexing.pos_fname = pos_fname; Lexing.pos_lnum = pos_lnum;
          Lexing.pos_bol = pos_bol; Lexing.pos_cnum = pos_cnum }
         ->
        this#record "Lexing.position"
          [("pos_fname", (this#string pos_fname));
          ("pos_lnum", (this#int pos_lnum));
          ("pos_bol", (this#int pos_bol));
          ("pos_cnum", (this#int pos_cnum))]
  end

dumpast is a direct example of using genlifter applied on the OCaml Parsetree definition itself. ppx_metaquot is another similar example.

Dependencies (3)

  1. ocaml-migrate-parsetree >= "1.0.7" & < "1.3.0"
  2. jbuilder >= "1.0+beta17"
  3. ocaml >= "4.02.0" & < "4.08.0"

Dev Dependencies

None

Used by (37)

  1. bisect_ppx >= "1.3.0" & < "1.4.2"
  2. bitstring >= "3.0.0" & < "4.0.0"
  3. cstruct = "2.4.1"
  4. elpi != "1.0.4" & < "1.11.0"
  5. flow_parser = "0.80.0"
  6. flowtype >= "0.80.0"
  7. frenetic >= "5.0.0" & < "5.0.3"
  8. hdf5 >= "0.1.5"
  9. js_of_ocaml >= "3.0" & < "3.5.0"
  10. js_of_ocaml-ppx < "3.5.0"
  11. learn-ocaml >= "0.13.0"
  12. lwt >= "3.1.0" & < "4.0.0"
  13. lwt_ppx < "1.2.3"
  14. ocaml-monadic = "0.4.0"
  15. pgocaml >= "3.1" & < "4.0"
  16. pgocaml_ppx < "4.3.0"
  17. ppx_bitstring >= "2.0.0" & < "4.0.0"
  18. ppx_cstruct >= "3.0.1" & < "5.2.0"
  19. ppx_cstubs < "0.2.1"
  20. ppx_defer >= "0.3.0" & < "0.5.0"
  21. ppx_dotbracket
  22. ppx_dryunit
  23. ppx_hardcaml = "1.3.0"
  24. ppx_implicits >= "0.2.0"
  25. ppx_integer
  26. ppx_monadic >= "1.1.0"
  27. ppx_orakuda >= "3.1.0"
  28. ppx_regexp >= "0.3.1" & < "0.4.3"
  29. ppx_sqlexpr
  30. ppx_tyre < "0.4.3"
  31. ppx_wideopen
  32. ppxx >= "2.0.0" & < "2.5.0"
  33. reason = "1.13.7"
  34. reason-parser >= "1.13.5"
  35. sedlex = "1.99.4"
  36. tyxml-jsx < "4.5.0"
  37. tyxml-ppx >= "4.3.0" & < "4.5.0"

Conflicts

None

OCaml

Innovation. Community. Security.