* camlp4 3.10: <:ctyp< ( $list:tys$ )
@ 2007-05-01 12:16 Joel Reymont
2007-05-01 12:47 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 2+ messages in thread
From: Joel Reymont @ 2007-05-01 12:16 UTC (permalink / raw)
To: Caml List
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.
Thanks, Joel
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] camlp4 3.10: <:ctyp< ( $list:tys$ )
2007-05-01 12:16 camlp4 3.10: <:ctyp< ( $list:tys$ ) Joel Reymont
@ 2007-05-01 12:47 ` Nicolas Pouillard
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2007-05-01 12:47 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-05-01 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-01 12:16 camlp4 3.10: <:ctyp< ( $list:tys$ ) Joel Reymont
2007-05-01 12:47 ` [Caml-list] " Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox