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 692157FD92 for ; Mon, 20 Jun 2016 17:31:55 +0200 (CEST) IronPort-PHdr: 9a23:hd7D6hDtP9vHYBvYyLxzUyQJP3N1i/DPJgcQr6AfoPdwSP74r8bcNUDSrc9gkEXOFd2CrakU2qyH7uu/CCQp2tWojjMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3DwdpPOO9QteU1JTmkbHvsMKCKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu5NznlpL1/A1zz158O34YIxu38I46FppIZ8VvDxdqE8CLhZFygOMmYv5cStuwOQYxGI4y45W38d2j5BGBPC6lmuW57ruW3+v/Fm3y+yOcDmTL41Hz+l6vE4G1fTlC4bOmthoynsgctqgfcDrQ== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=marc.lasson@lexifi.com; spf=None smtp.mailfrom=marc.lasson@lexifi.com; spf=None smtp.helo=postmaster@mx20.yaziba.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of marc.lasson@lexifi.com) identity=pra; client-ip=85.233.204.164; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="marc.lasson@lexifi.com"; x-sender="marc.lasson@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of marc.lasson@lexifi.com) identity=mailfrom; client-ip=85.233.204.164; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="marc.lasson@lexifi.com"; x-sender="marc.lasson@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mx20.yaziba.net) identity=helo; client-ip=85.233.204.164; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="marc.lasson@lexifi.com"; x-sender="postmaster@mx20.yaziba.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CzAQALDGhXh6TM6VVdhD+9NYYXAoEzOxEBAQEBAQEBAREBAQEKCwkJIS+CMYIbAQEEIwQRUQsaAiYCAlcTCAEBiDCwR5ANDCWBAYUmgXeCVoRATII1gloFmHaBWIxSiUWFXY91AjSCOYFZizQBAQE X-IPAS-Result: A0CzAQALDGhXh6TM6VVdhD+9NYYXAoEzOxEBAQEBAQEBAREBAQEKCwkJIS+CMYIbAQEEIwQRUQsaAiYCAlcTCAEBiDCwR5ANDCWBAYUmgXeCVoRATII1gloFmHaBWIxSiUWFXY91AjSCOYFZizQBAQE X-IronPort-AV: E=Sophos;i="5.26,499,1459807200"; d="scan'208";a="181888216" Received: from mx20.yaziba.net ([85.233.204.164]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jun 2016 17:31:41 +0200 Received: from mta10.int.yaziba.net (mta10.int.yaziba.net [10.4.20.30]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx20.yaziba.net (mx10.yaziba.net) with ESMTPS id 58CB51A761D for ; Mon, 20 Jun 2016 17:31:40 +0200 (CEST) Received: from mta10.int.yaziba.net (localhost [127.0.0.1]) by mta10.int.yaziba.net (Postfix) with ESMTPS id 6218CCA753 for ; Mon, 20 Jun 2016 17:31:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mta10.int.yaziba.net (Postfix) with ESMTP id 545B2CA75D for ; Mon, 20 Jun 2016 17:31:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at mta10.int.yaziba.net Received: from mta10.int.yaziba.net ([127.0.0.1]) by localhost (mta10.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UfIy1pXqX2pn for ; Mon, 20 Jun 2016 17:31:40 +0200 (CEST) Received: from [10.0.48.152] (unknown [185.23.92.144]) by mta10.int.yaziba.net (Postfix) with ESMTPSA id 3DAC9CA757 for ; Mon, 20 Jun 2016 17:31:40 +0200 (CEST) To: caml-list@inria.fr References: <5svasb3if71ppb0qpbzii4kmx-2147483647@mailer.nylas.com> <1aevxka1nl8e30hefzpghm5yr-2147483647@mailer.nylas.com> From: Marc Lasson Message-ID: <94db527d-c165-7e7d-5c2d-8ed3f7f1f711@lexifi.com> Date: Mon, 20 Jun 2016 17:31:45 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <1aevxka1nl8e30hefzpghm5yr-2147483647@mailer.nylas.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-DRWEB-SCAN: ok X-VRSPAM-SCORE: 0 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrfeekledrleehgdeltdcutefuodetggdotefrucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpjgetkgfkueetnecuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomhepofgrrhgtucfnrghsshhonhcuoehmrghrtgdrlhgrshhsohhnsehlvgigihhfihdrtghomheqnecukfhppedukeehrddvfedrledvrddugeegnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhht X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht Subject: Re: [Caml-list] Information for writting a ppx 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.