From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 3C3487FD92 for ; Mon, 20 Jun 2016 17:33:10 +0200 (CEST) IronPort-PHdr: 9a23:PuO0YxbuENoj8LHAsHNlEn//LSx+4OfEezUN459isYplN5qZpMy8bnLW6fgltlLVR4KTs6sC0LqH9fG9EjNRqb+681k8M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJPK/jvHcaK1oLsh7H0qsCYPFQArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIZoGJ/3dKUgTLFeEC9ucyVsvJWq5i/4UBCX63AAfmITmxtOS0iZvVCpFqv25w7zrOE1/CCBJsrwBeQxUC6pqaNiUwTvjg8DOi44/mCRgct12vF1uhWk8ix23Y/ZesmrPfw2cq6VQtQXXnZQWMsZAzxIHIKxdc0RA/UpMuNRro27rFwL+0jtTTKwDf/in2cbzkT92rc3hqF8SAw= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=xavier.vdw@gmail.com; spf=Pass smtp.mailfrom=xavier.vdw@gmail.com; spf=None smtp.helo=postmaster@mail-pa0-f46.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of xavier.vdw@gmail.com) identity=pra; client-ip=209.85.220.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="xavier.vdw@gmail.com"; x-sender="xavier.vdw@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of xavier.vdw@gmail.com designates 209.85.220.46 as permitted sender) identity=mailfrom; client-ip=209.85.220.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="xavier.vdw@gmail.com"; x-sender="xavier.vdw@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pa0-f46.google.com) identity=helo; client-ip=209.85.220.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="xavier.vdw@gmail.com"; x-sender="postmaster@mail-pa0-f46.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AQAQALDGhXhi7cVdFdgnmBG32neoFThXWGJoUBgXokhW0EAgKBMzgUAQEBAQEBAQERAQEBCAsLCSEvgjGCGwEBAwEPAQIVBhMBGxILAQMBCwYFBCEhIxEBBQEKEgYTEhCHcwEDDwgDC6JigTE+MYpTAQGCUIJZBYcoChknAwpSgnQBAQEBAQEBAQEBAQEBAQEBAQEBAQEUAgYQgQSJYIdUgkcFhksMiBKEX4UuhgaIJII3hwAOhV2IIIYYMIEPDw+CMR6Bd06KSAEBAQ X-IPAS-Result: A0AQAQALDGhXhi7cVdFdgnmBG32neoFThXWGJoUBgXokhW0EAgKBMzgUAQEBAQEBAQERAQEBCAsLCSEvgjGCGwEBAwEPAQIVBhMBGxILAQMBCwYFBCEhIxEBBQEKEgYTEhCHcwEDDwgDC6JigTE+MYpTAQGCUIJZBYcoChknAwpSgnQBAQEBAQEBAQEBAQEBAQEBAQEBAQEUAgYQgQSJYIdUgkcFhksMiBKEX4UuhgaIJII3hwAOhV2IIIYYMIEPDw+CMR6Bd06KSAEBAQ X-IronPort-AV: E=Sophos;i="5.26,499,1459807200"; d="scan'208,217";a="181888461" Received: from mail-pa0-f46.google.com ([209.85.220.46]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 20 Jun 2016 17:33:08 +0200 Received: by mail-pa0-f46.google.com with SMTP id b13so51932602pat.0 for ; Mon, 20 Jun 2016 08:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:references:in-reply-to:user-agent:message-id:cc:to:from :subject:mime-version; bh=wPZsT/iO9A5F8ECKDebgAhgUuZTGccvI26vTbUfrHuA=; b=rUraJrao82XGPFRaNqDX5iVVEt16BTpM+GaMfMUdbXYlppooExPunwDyc3zK1T6Yym Qea/zAqtQHEKj20a1v7257JcefMEADYcaDAFe5MbyA7ZW/g4u48EVV4/KlfBzHATPB7Z MqBAJbYR2E7+e4AWdVi1wh1z1gkZYz2SOs5melGTYVQb7ln+geOt5u1acc3QVNFo8quG ABLcTjSTdZy+XNpwr5zQ1UEakMCHeIU/GhIT1FhXuaw+6Cw+b5hV0MEYvse84zw/mxnl fvvMkzgLo+e8hU6+7IZp4onuY727UXuTzzeFtjnuHmTWEZ57jD7OMLHTCWi1mhoYTeZ1 Qi3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:references:in-reply-to:user-agent :message-id:cc:to:from:subject:mime-version; bh=wPZsT/iO9A5F8ECKDebgAhgUuZTGccvI26vTbUfrHuA=; b=EAPn3yQeacv21KkNZgfMAvxj2b5GEyfLcvWQb17IQOTiUsg1Mr2rUZ5zbFAhYqH4qK oWQxri8/2ffjn0306S6fCZRaxJfrQPn610kTSwcaDwJm0q/xEWvCh9T4gp0cJ8bBS8yS ldRGpBwQBof0fNIhgRtO7kMdCeLAbvnJKXXg9PhVk0Z8oauq+HL3ul7ABnf4z9GiPmDg YK2R2VBZ63F75CkNRsb66Urq6AVmxVOwX66xVP/p7YpCOgVJx/wx7GEsalQFpj0EXvtJ UBE5SiVp8T7U8cBQl1j7Dh793drmZrab3IOlE08IjyJQJxhnnI3gnC6Qo1gXw88Zj2bN xSsw== X-Gm-Message-State: ALyK8tIxBNNO0mKOH/Zu2fl7TX/LNFK0S8mgX6WD7fpZqKoehtil8yIP+/DEXNWrgtPGVw== X-Received: by 10.66.138.43 with SMTP id qn11mr12776406pab.1.1466436786416; Mon, 20 Jun 2016 08:33:06 -0700 (PDT) Received: from [127.0.0.1] (ec2-52-36-99-221.us-west-2.compute.amazonaws.com. [52.36.99.221]) by smtp.gmail.com with ESMTPSA id ym9sm59645991pac.25.2016.06.20.08.33.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 08:33:05 -0700 (PDT) Date: Mon, 20 Jun 2016 08:33:05 -0700 (PDT) References: <5svasb3if71ppb0qpbzii4kmx-2147483647@mailer.nylas.com> <1aevxka1nl8e30hefzpghm5yr-2147483647@mailer.nylas.com> <94db527d-c165-7e7d-5c2d-8ed3f7f1f711@lexifi.com> In-Reply-To: <94db527d-c165-7e7d-5c2d-8ed3f7f1f711@lexifi.com> User-Agent: NylasMailer/0.4 Message-Id: X-Inbox-Id: f3gx2qw6nhznmrcn9g50952ci-2147483647 Cc: "caml-list@inria.fr" To: Marc Lasson From: Xavier Van de Woestyne Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="cf4467800869416e932338d433a640a4" Subject: Re: [Caml-list] Information for writting a ppx --cf4467800869416e932338d433a640a4 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="ascii" Mime-Version: 1.0 Thanks for the point ! Xavier Van de Woestyne http://xvw.github.io ![](https://link.nylas.com/open/5y0wh7okaezysfzysovho20yh/local-37964069-61f2?r=Y2FtbC1saXN0QGlucmlhLmZy) On juin 20 2016, at 5:32 pm, Marc Lasson <marc.lasson@lexifi.com> wrote: > 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](http://groups.yahoo.com/group/ocaml_beginners&r=Y2FtbC1saXN0QGlucmlhLmZy) > Bug reports: [http://caml.inria.fr/bin/caml-bugs](http://caml.inria.fr/bin /caml-bugs&r=Y2FtbC1saXN0QGlucmlhLmZy) --cf4467800869416e932338d433a640a4 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset="ascii" Mime-Version: 1.0 Thanks for the point ! 

Xavier Van de Woestyne 
http://xvw.github.io

On juin 20 2016, at 5:32 pm, Marc Lasson <marc.lasson@lexifi.com> wrote:

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

--cf4467800869416e932338d433a640a4--