caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Marc Lasson <marc.lasson@lexifi.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Information for writting a ppx
Date: Mon, 20 Jun 2016 17:31:45 +0200	[thread overview]
Message-ID: <94db527d-c165-7e7d-5c2d-8ed3f7f1f711@lexifi.com> (raw)
In-Reply-To: <1aevxka1nl8e30hefzpghm5yr-2147483647@mailer.nylas.com>

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.

  reply	other threads:[~2016-06-20 15:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-17 17:10 Xavier Van de Woestyne
2016-06-20 14:15 ` Anton Bachin
2016-06-20 15:01   ` Xavier Van de Woestyne
2016-06-20 15:31     ` Marc Lasson [this message]
2016-06-20 15:33       ` Xavier Van de Woestyne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94db527d-c165-7e7d-5c2d-8ed3f7f1f711@lexifi.com \
    --to=marc.lasson@lexifi.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).