Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <alain.frisch@lexifi.com>
To: Dmitry Bely <dmitry.bely@gmail.com>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] ppx_metaquot location passing
Date: Wed, 2 Sep 2015 11:09:31 +0200	[thread overview]
Message-ID: <55E6BCCB.1040602@lexifi.com> (raw)
In-Reply-To: <CAMT7qiROs6YEWrRLVPhSeW71W8SzSeeiftKfK-=xFck3ZkMMFQ@mail.gmail.com>

Hi Dmitry,

Looking at the comments in ppx_metaquot.ml, there are two ways to 
achieve that:

   - By default, the location of all created notes is set to the 
expression "!Ast_helper.default_loc".  You can set this reference 
directly or with Ast_helper.with_default_loc.

   - You can change this expression with a @metaloc attribute (typically 
to specify a locally bound variable).


Hope this helps,

Alain



On 02/09/2015 10:23, Dmitry Bely wrote:
> I'm writing a ppx rewriter. It iterates over structure items and for
> some of them generates the new ones. A simplified example:
>
> let defs = ref []
>
> let mapper argv =
>    let expr mapper expr =
>      ...
>    let rec structure mapper li =
>      let li =
>        List.fold_left (fun acc ({pstr_loc = loc} as si) ->
>          let si = default_mapper.structure_item mapper si in
>          let sli =
>            List.map
>              (fun (n, v) ->
>                [%stri let [%p pvar n] = [%e str v]])
>              !defs in
>          defs := [];
>          (si::sli) @ acc) [] li in
>      List.rev li
> ...
>
> The question is how to pass the location information for [%stri]
> generated code (loc in my example)? Of course I can write
>
> {[%stri let [%p pvar n] = [%e str v]] with pstr_loc = loc}
>
> but I would like the location of all nested expressions to be set to
> loc as well.
>
> - Dmitry Bely
>

  reply	other threads:[~2015-09-02  9:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02  8:23 Dmitry Bely
2015-09-02  9:09 ` Alain Frisch [this message]
2015-09-02  9:47   ` Dmitry Bely

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=55E6BCCB.1040602@lexifi.com \
    --to=alain.frisch@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=dmitry.bely@gmail.com \
    /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