metaquot

OCaml syntax extension for quoting code
README

metaquot is a PPX rewriter that provides several extensions for
quoting OCaml code in expressions, à la ppxtools.ppx_metaquot
and ppxlib.metaquot. In comparison to these libraries, metaquot
is built by meta-programmation over the Parsetree module (thanks
to metapp) and is meant to be trivial to update for future
versions of OCaml (on the other hand, metaquot only builds AST for
the current version of OCaml: you may use helpers provided by
Ast_helper or Metapp to manipulate the AST in a
version-independent manner).

metaquot can be used with dune by using the preprocess field.

(executable
  ...
  (preprocess (pps metaquot.ppx))
  ...)

The following extensions are provided.

|Quotation |Type |
|--------------|--------------------------|
|[%expr ...] |Parsetree.expression |
|[%pat? ...] |Parsetree.pattern |
|[%type: ...]|Parsetree.core_type |
|[%sig: ...] |Parsetree.signature |
|[%sigi: ...]|Parsetree.signature_item|
|[%str ...] |Parsetree.structure |
|[%stri ...] |Parsetree.structure_item|
|[%lid ...] |Parsetree.longident |

The produced AST uses !Ast_helper.default_loc as location: you may
change the location with Ast_helper.with_default_loc.

Moreover, in quoted code, the following extensions allow to evaluate
and insert expressions or patterns (anti-quotations).

|Anti-quotation|Type |
|--------------|--------------------------------------------------------|
|[%e ...] |Parsetree.expression |
|[%p ...] |Parsetree.pattern |
|[%t ...] |Parsetree.core_type |
|[%m ...] |Parsetree.module_type or Parsetree.module_expr |
|[%i ...] |Parsetree.signature_item or Parsetree.structure_item|

In addition to the syntax extension, the metaquot package provides
the Metaquot module, which contains lifters: the Metaquot.Exp
module lifts to expressions and Metaquot.Pat lifts to patterns. For
instance, Metaquot.Exp.pattern : Parsetree.pattern -> Parsetree.expression is a function that returns an OCaml expression
that builds the AST corresponding to the given pattern.

Install
Published
11 May 2020
Sources
v0.2.0.tar.gz
sha512=3a2d17268f6acae8178d8c2675aed63cb52d640b50c3167a5c430fb62958312afdb85ca03fe6b57f5448dd18005325842b959ecbc93cb12f669da8de56e7324d
Dependencies
metapp
>= "0.2.0" & < "0.3.0"
dune
>= "1.11.0"
ocamlfind
>= "1.8.1"
ocaml-migrate-parsetree
>= "1.7.3" & < "2.0.0"
stdcompat
>= "12"
ocaml
>= "4.03.0" & < "4.12.0"
Reverse Dependencies
clangml
>= "4.1.0" & < "4.3.0"
override
= "0.3.0"
pattern
= "0.2.0"
refl
< "0.3.0"
traverse
= "0.2.0"