From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Joel Reymont" <joelr1@gmail.com>
Cc: "Caml List" <caml-list@inria.fr>
Subject: Re: [Caml-list] camlp4 3.10: <:ctyp< ( $list:tys$ )
Date: Tue, 1 May 2007 14:47:49 +0200 [thread overview]
Message-ID: <cd67f63a0705010547h61cd42al8da2b7238b93e020@mail.gmail.com> (raw)
In-Reply-To: <F72C18D9-5405-45B8-A123-3D1AE8142B39@gmail.com>
On 5/1/07, Joel Reymont <joelr1@gmail.com> wrote:
> This is the old code:
>
> | <:ctyp< ( $list:tys$ ) >> -> tupl _loc (List.map aux tys)
>
> I figure it tries to match something like "int * int".
>
> Following Nicolas's suggestion I thought I would see what this
> expands to:
>
> camlp4of -str '<:ctyp< ( int * int ) >>'
> Ast.TyTup (_loc,
> Ast.TySta (_loc, Ast.TyId (_loc, Ast.IdLid (_loc, "int")),
> Ast.TyId (_loc, Ast.IdLid (_loc, "int"))))
>
> How do I work back from this to the right expression within parens in
> the original pattern above? I tried
>
> | <:ctyp< ( $tup:tys$ ) >> -> tupl _loc (List.map aux tys)
>
> but this produces ctyp instead of ctyp list so it's not suitable for
> the tupl.
>
There is one simple answer about camlp4 AST. There is no more lists inside.
Then how to guess, how to pattern match these AST.
Take tuples for instance...
( t1 * ... * tN )
Hum that a list of types separated by stars, so in camlp4 the
constructor node will be the star.
t ::= ... | ( $tup:t$ ) | $t1$ * $t2$
So that's the representation. Now if you really want a list you can
use a function like Ast.ctyp_of_list
match t with
| <:ctyp< ( $tup:t$ ) >> -> Ast.ctyp_of_list t
...
Regards,
--
Nicolas Pouillard
prev parent reply other threads:[~2007-05-01 12:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 12:16 Joel Reymont
2007-05-01 12:47 ` Nicolas Pouillard [this message]
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=cd67f63a0705010547h61cd42al8da2b7238b93e020@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@inria.fr \
--cc=joelr1@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