caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Van de Woestyne <xavier.vdw@gmail.com>
To: Anton Bachin <antronbachin@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Information for writting a ppx
Date: Mon, 20 Jun 2016 08:01:36 -0700 (PDT)	[thread overview]
Message-ID: <1aevxka1nl8e30hefzpghm5yr-2147483647@mailer.nylas.com> (raw)
In-Reply-To: <B6AE27F2-6F68-4D11-B788-AA6950E2E0A0@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2660 bytes --]

Thanks a lot, Mr Marc L explain me how to do that :

  

```

(* 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 -&gt;  
     let pl = Ast_helper.Str.eval (Ppx.Fabric.print_endline "Hello World") in  
     pl :: (general_mapper.structure general_mapper str)  
 }  

```

  
Xavier Van de Woestyne

http://xvw.github.io

  

![](https://link.nylas.com/open/5y0wh7okaezysfzysovho20yh/local-56fe3f0e-
0d5c?r=Y2FtbC1saXN0QGlucmlhLmZy)

On juin 20 2016, at 4:16 pm, Anton Bachin &lt;antronbachin@gmail.com&gt;
wrote:  

> Hi Xavier,

>

>  
>

>

> Bisect_ppx does this by looking at the location of each module it sees in
“structure". The file names are stored in a set. If a file name is not yet in
the set, Bisect_ppx assumes that the module is the top-level module of a file.
We haven’t had any problems with it.

>

>  
>

>

> You can see it here:
[https://github.com/aantron/bisect_ppx/blob/afa95d9f02ab4c95df3af283641c73ec1dc8cfb1/src/syntax/instrumentPpx.ml#L480](https://github.com/aantron/bisect_ppx/blob/afa95d9f02ab4c95df3af283641c73ec1dc8cfb1/src/syntax/instrumentPpx.ml#L480&r=Y2FtbC1saXN0QGlucmlhLmZy)

>

>  
>

>

> The code is a bit old, but there it is.

>

>  
>

>

> Best,

>

> Anton

>

>  
>

>

>> On Jun 17, 2016, at 12:10, Xavier Van de Woestyne
&lt;[xavier@derniercri.io](mailto:xavier@derniercri.io)&gt; wrote:

>>

>>  
>

>>

>> Hello,

>>

>> I have writted some ppx extension but I have a question,

>>

>> Is there a proper way to add a start "file" structure.  
>

>>

>> I have try using the "structure" member of the mapper :

>>

>>  
>

>>

>> `

>>

>> let new_mapper =

>>

>>  Ast_mapper.{  
>     default_mapper with  
>     structure = general_structure  
>   }`

>>

>>  
>

>>

>> Where general_structure is just a

>>

>> `my_begining_structure :: List.map (...)` but my begining

>>

>> structure is repeated into each module. It is logic but I need

>>

>> to add my own structure only at the begining of my file. In an

>>

>> other project, I use a mandatory attribute ([@@@active_this_ppx]

>>

>> for example), but imho, it is not a good approach.

>>

>>  
>

>>

>> Thanks a lot for your feedback and advices !

>>

>>  
>

>>

>> Xavier Van de Woestyne

>>

>> Développeur à Derniercri.io

>>

>> [http://derniercri.io](http://derniercri.io&r=Y2FtbC1saXN0QGlucmlhLmZy)

>>

>> ![](https://link.nylas.com/open/3hl20o5fseo0be0el9ic747vo/local-
19c25162-3d3f?r=Y2FtbC1saXN0QGlucmlhLmZy)

>

>  
>


[-- Attachment #2: Type: text/html, Size: 3667 bytes --]

  reply	other threads:[~2016-06-20 15:01 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 [this message]
2016-06-20 15:31     ` Marc Lasson
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=1aevxka1nl8e30hefzpghm5yr-2147483647@mailer.nylas.com \
    --to=xavier.vdw@gmail.com \
    --cc=antronbachin@gmail.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).