To paraphrase the code, I just advised Xavier to use a mapper that does
recursively not call itself.> (* Mapper for all transformation *)
> let general_mapper = Ast_mapper.{ default_mapper with structure =
> structure }
>
> (* New Mapper only for the toplevel *)
> let toplevel_mapper =
> Ast_mapper.{
> default_mapper with
> structure = fun _ str ->
> let pl = Ast_helper.Str.eval (Ppx.Fabric.print_endline "Hello
> World") in
> pl :: (general_mapper.structure general_mapper str)
> }
> ```Note that if you do not plan to extend general_mapper with a mapper that
actually does something you could simply write :let toplevel_mapper =
Ast_mapper.{
default_mapper with
structure = fun _ str ->
let pl = Ast_helper.Str.eval (Ppx.Fabric.print_endline "Hello
World") in
pl :: str
}Also, if the ppx is also applied to compile mli interfaces, then this
will be structures occurring within the toplevel signature (eg. in the
payloads of attributes). So to be "safe", you should probably do :let toplevel_mapper =
Ast_mapper.{
default_mapper with
signature = fun _ -> default_mapper.signature default_mapper;
structure = fun _ str ->
let pl = Ast_helper.Str.eval (Ppx.Fabric.print_endline "Hello
World") in
pl :: str
}--
Marc.--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs