package ppx_tools

  1. Overview
  2. Docs
Tools for authors of ppx rewriters and other syntactic tools

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_tools-6.6.tar.gz
md5=b2af2febba308b294931e7934974f9d5
sha512=7bbb9a8d9aaa68c54048fde383f7ba2499ac53bbc2d7e3ba907de342ea48ffded69acc2e4ca4c38c2b2b1004b5e004230988a36ad34a4b5361c2a3ad1f858a53

Description

Tags

syntax

Published: 03 Oct 2022

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.06 :

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. cppo build & >= "1.1.0"
  2. dune >= "1.6"
  3. ocaml >= "4.08.0" & < "5.1.0"

Dev Dependencies

None

  1. aperf >= "0.1.2"
  2. arp < "0.2.1"
  3. bisect_ppx < "1.3.0"
  4. bistro < "0.3.0"
  5. cconv-ppx
  6. charrua-core >= "0.5" & < "0.8"
  7. csvprovider
  8. diet < "0.2"
  9. dns >= "0.18.0" & != "0.19.1" & < "1.0.0"
  10. dns-forward < "0.9.0"
  11. eliom >= "5.0.0" & < "8.9.0"
  12. fat-filesystem >= "0.11.0" & < "0.13.0"
  13. gdb
  14. gensqlite
  15. graphql_ppx < "0.7.1"
  16. js_of_ocaml >= "2.6" & < "3.0"
  17. js_of_ocaml-ppx_deriving_json < "3.5.0"
  18. learn-ocaml
  19. learn-ocaml-client
  20. lens >= "1.2.1" & < "1.2.5"
  21. lwt >= "2.4.6" & < "3.1.0"
  22. mdx < "1.2.0"
  23. mirage-block-unix >= "2.10.0" & < "2.11.1"
  24. mirage-block-xen >= "1.4.0" & < "1.6.0"
  25. mirage-net-xen >= "1.6.0" & < "1.7.1"
  26. mirage-profile = "0.7.0"
  27. nbd >= "2.1.0" & < "4.0.3"
  28. netchannel < "1.9.0"
  29. noCanren < "0.3.0~alpha1"
  30. ocaml-monadic >= "0.3.2" & < "0.4.0"
  31. ocamllint
  32. ocf < "0.8.0"
  33. ocsigen-i18n >= "3.5.0" & < "4.0.0"
  34. omonad >= "0.3.0"
  35. orakuda >= "2.0.0"
  36. otr >= "0.3.1" & < "0.3.3"
  37. override < "0.2.0"
  38. pcap-format = "0.5.1"
  39. pgocaml >= "3.1" & < "4.0"
  40. pgocaml_ppx < "4.3.0"
  41. ppx_assert < "v0.9.0"
  42. ppx_bench < "v0.9.0"
  43. ppx_bin_prot < "v0.9.0"
  44. ppx_bitstring < "2.0.0"
  45. ppx_blob = "0.2"
  46. ppx_compare < "v0.9.0"
  47. ppx_const < "2.0"
  48. ppx_conv_func < "v0.9.0"
  49. ppx_core < "v0.9.0"
  50. ppx_cstruct < "3.0.1"
  51. ppx_csv_conv < "v0.9.0"
  52. ppx_custom_printf < "v0.9.0"
  53. ppx_defer < "0.3.0"
  54. ppx_deriving < "5.0"
  55. ppx_deriving_crowbar
  56. ppx_deriving_madcast < "0.2"
  57. ppx_deriving_morphism >= "0.4"
  58. ppx_deriving_protobuf = "2.7"
  59. ppx_deriving_rpc < "6.0.0"
  60. ppx_deriving_yojson >= "3.3" & < "3.6.0"
  61. ppx_distr_guards < "0.2"
  62. ppx_driver < "113.24.00"
  63. ppx_enumerate < "v0.9.0"
  64. ppx_expect < "v0.9.0"
  65. ppx_fail < "v0.9.0"
  66. ppx_fields_conv < "v0.9.0"
  67. ppx_fun < "0.0.9"
  68. ppx_getenv < "2.0"
  69. ppx_hardcaml < "1.3.0"
  70. ppx_here < "113.24.00"
  71. ppx_implicits < "0.2.0"
  72. ppx_import < "1.5-3-gbd627d5"
  73. ppx_inline_test < "v0.9.0"
  74. ppx_json_types
  75. ppx_monadic < "1.1.0"
  76. ppx_monoid < "0.3.2"
  77. ppx_netblob
  78. ppx_optcomp < "v0.9.0"
  79. ppx_orakuda < "3.1.0"
  80. ppx_pipebang < "v0.9.0"
  81. ppx_regexp < "0.3.0"
  82. ppx_sexp_conv < "v0.9.0"
  83. ppx_sexp_message < "v0.9.0"
  84. ppx_sexp_value < "v0.9.0"
  85. ppx_type_conv < "v0.9.0"
  86. ppx_typerep_conv < "v0.9.0"
  87. ppx_variants_conv < "v0.9.0"
  88. ppx_xml_conv < "v0.9.0"
  89. ppxx < "2.0.0"
  90. protocol-9p >= "0.6.0" & < "1.0.0"
  91. protocol-9p-unix < "1.0.0"
  92. qcow
  93. qcow-format >= "0.4"
  94. sedlex >= "1.99.1" & < "1.99.4"
  95. sequoia
  96. shared-block-ring >= "2.3.0" & < "3.0.0"
  97. shared-memory-ring >= "1.2.0" & < "2.0.0"
  98. sqlexpr >= "0.7.1" & < "0.9.0"
  99. tar < "2.0.0"
  100. tar-format = "0.6.0"
  101. tcpip >= "2.7.0" & < "3.2.0"
  102. tls >= "0.7.1" & < "0.9.0"
  103. tyxml-ppx < "4.3.0"
  104. utop >= "1.19" & < "1.19.2"
  105. vchan >= "2.1.0" & < "5.0.0"
  106. vchan-unix < "5.0.0"
  107. vchan-xen < "5.0.0"
  108. vhd-format = "0.8.0"
  109. visitors < "20210127"
  110. vmnet >= "1.1.0" & < "1.3.2"
  111. xenstore >= "1.3.0" & < "2.1.0"
  112. xtmpl >= "0.17.0" & < "0.19.0"

Conflicts

None

OCaml

Innovation. Community. Security.