ocaml-ppx / ppx_tools

Tools for authors of ppx rewriters
MIT License
134 stars 39 forks source link

[%%s ... ] antiquotation not working right #44

Closed jonathan-dilorenzo closed 8 years ago

jonathan-dilorenzo commented 8 years ago

I've recently gotten started using PPX and metaquot so I apologize in advance if I'm just making a stupid mistake, but it seems to me like the [%%s ... ] antiquotation isn't begin expanded.

I'm using OCaml 4.03.0 and ppx_tools 5.0+4.03.0.

I tried to produce a fairly small example of the problem. I have my ppx file:

> open Ast_mapper
> open Parsetree
> 
> let test_mapper argv =
>   { default_mapper with
>     structure = fun mapper strl ->  
>       let rec stri_replace acc str =
>         match str with
>         | { pstr_desc = Pstr_extension (({txt = "test"},_ ),_) } -> 
>           let x = [%stri type x = string] in
>           [%str [%%s [x]]] @ acc
>         | x -> default_mapper.structure_item mapper x :: acc
>       in
>       List.rev (List.fold_left stri_replace [] strl)
>   }
> 
> let () = register "test" test_mapper

And when I run the ppx_rewriter on my test file: [%%test ]

using:

ocamlfind ppx_tools/rewriter ./ppx_forest.native examples/test.ml

I get: [%%s [x]] instead of: type x = string

which is what I would have expected. Am I just doing something stupid or is it not working right?

alainfrisch commented 8 years ago

This form of antiquotation has been introduced this week only; it is not available in the released version of ppx_tools.

jonathan-dilorenzo commented 8 years ago

Ah, well that explains it. My bad. Saw it in the metaquot.ml and assumed the newest version had it.