package ppx_type_conv

  1. Overview
  2. Docs
Support Library for type-driven code generators

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_type_conv-v0.10.0.tar.gz
sha256=0976d79d20d50a40926f5a7a83de0420b6a5d33456c73667f9840deb56f37f3c
md5=ae87662d39eebc6a2df6851c0f4da88c

Description

Part of the Jane Street's PPX rewriters collection.

Published: 15 Dec 2017

README

ppx_type_conv - Support Library for type-driven code generators

What is type_conv?

The type_conv library factors out functionality needed by different preprocessors that generate code from type specifications. Example libraries currently depending on type_conv:

  • ppx_bin_prot

  • ppx_compare

  • ppx_fields_conv

  • ppx_sexp_conv

  • ppx_variants_conv

type_conv for users of ppx_deriving

type_conv based code generators are meant to be used with [ppx_driver://github.com/janestreet/ppx_driver). However type_conv allows to export a compatible ppx_deriving plugin. By default, when not linked as part of a driver, packages using type_conv will just use ppx_deriving.

So for instance this will work as expected using ppx_deriving:

ocamlfind ocamlc -c -package ppx_sexp_conv foo.ml

For end users, the main advantage of using type_conv based generators with ppx_driver is that it will catch typos and attributes misplacement. For instance:

# type t = int [@@derivin sexp]
Error: Attribute `derivin' was not used
Hint: Did you mean deriving?
# type t = int [@@deriving sxp]
Error: ppx_type_conv: 'sxp' is not a supported type type-conv generator
Hint: Did you mean sexp?
# type t = int [@deriving sexp]
Error: Attribute `deriving' was not used
Hint: `deriving' is available for type declarations, type extensions
and extension constructors but is used here in the context of a core type.
Did you put it at the wrong level?"

For instruction on how to use ppx_driver, refer to the ppx_driver's documentation.

Syntax

This part is only relevant if you are using ppx_driver. If you are using ppx_deriving the syntax is the one of ppx_deriving.

type_conv interprets the [@@deriving ...] attributes on type declarations, exception declarations and extension constructor declarations:

type t = A | B [@@deriving sexp, bin_io]

sexp and bin_io are called generators. They are functions that generate code given the declaration. These functions are implemented by external libraries such as ppx_sexp_conv or ppx_bin_prot. type_conv itself provides no generator, it does only the dispatch.

Generators can take arguments. This is done using the following syntax:

type t = A | B [@@deriving foo ~arg:42]

For arguments that are just switches, it is common to use the following syntax:

type t = A | B [@@deriving foo ~bar]

Plugin as findlib libraries

You must essentially follow the same rule for ppx_type_conv plugins as for ppx_driver ones when writing the META file.

Contact Information and Contributing

In the case of bugs, feature requests, contributions and similar, please contact the maintainers:

Up-to-date information should be available at https://github.com/janestreet/ppx_type_conv.

Dependencies (7)

  1. ppx_derivers
  2. ocaml-migrate-parsetree >= "0.4" & < "2.0.0"
  3. jbuilder >= "1.0+beta12"
  4. ppx_metaquot >= "v0.10" & < "v0.11"
  5. ppx_driver >= "v0.10" & < "v0.11"
  6. ppx_core >= "v0.10" & < "v0.11"
  7. ocaml >= "4.04.1"

Dev Dependencies

None

Used by (23)

  1. charrua-core >= "0.3" & < "0.5"
  2. cohttp >= "1.0.2" & < "1.1.1"
  3. diet < "0.2"
  4. mirage-block-unix >= "2.10.0" & < "2.11.1"
  5. ppx_assert = "v0.10.0"
  6. ppx_base = "v0.10.0"
  7. ppx_bin_prot = "v0.10.0"
  8. ppx_compare = "v0.10.0"
  9. ppx_conv_func = "v0.10.0"
  10. ppx_csv_conv = "v0.10.0"
  11. ppx_deriving_protocol < "0.8.1"
  12. ppx_enumerate = "v0.10.0"
  13. ppx_fields_conv = "v0.10.0"
  14. ppx_hash = "v0.10.0"
  15. ppx_jsobject_conv < "0.2.1" | >= "0.4.2" & < "0.6.0"
  16. ppx_protocol_conv < "3.1.3"
  17. ppx_sexp_conv = "v0.10.0"
  18. ppx_traverse = "v0.10.0"
  19. ppx_typerep_conv = "v0.10.0"
  20. ppx_variants_conv = "v0.10.0"
  21. ppx_xml_conv = "v0.10.0"
  22. qcow < "0.11.0"
  23. qcow-format >= "0.4"

Conflicts

None

OCaml

Innovation. Community. Security.