[nem-en] A macro-related question
Kamil Skalski
kamil.skalski at gmail.com
Fri Jun 2 18:32:01 CEST 2006
Ah, there it is:
Typer.n
public AddRedirection (name : PT.Name, subst : PT.PExpr) : void
so in macro you can use:
macro x (y) {
def x = Macros.UseSiteSymbol ("tobereplaced");
Macros.ImplicitCTX().AddRedirection (x, y);
<[ () ]>
}
and then
x(System.Console.WriteLine ("aa"));
tobereplaced
would yield printing "aa"
But if you want to replace 'this'... it may be harder. I would try
mixed approach:
create redirection (in case somebody use just 'foo') and replace
'this' by using TraverseExpr, so uses like 'this.foo' also gets
changed.
If you want to change 'x' binding to 'this.x' for every possible 'x'
you would have even more problems (need to search all fields defined
in 'this' and perform redirection for each).
2006/6/2, Kamil Skalski <kamil.skalski at gmail.com>:
> Try
>
> public RecursiveRename (tc : TypeBuilder, expr : PExpr, from : Name,
> to : Name) : PExpr
> or
> public TraverseExpr (ctx : option[Typer], expr : PExpr, in_pattern : bool,
> call : bool * bool * PExpr -> PExpr) : PExpr
>
> from Macros.n
>
> Also, I remember I was writing the Alias kind of functionality some
> time ago, but I don't remember if it was actually finished... I will
> search and post later.
>
>
> 2006/6/2, d <d at hell.art.pl>:
> >
> > Hi
> >
> > I see the activity has shifted to the forum and mailing list
> > (there's noone on the irc channel, which I like the most of those
> > mediums :/), so I'll post my question here, as I'm not a forum fan ;]
> > I started writing the Alias macro yesterday (which we discussed
> > with Kamil), it looks very promissing really, but I need help with
> > one detail - how can I substitute all the occurences of a variable/
> > parameter/field name in a method body with an other ? There is one
> > situation, where I'd like to change all the references to [this] in a
> > method body with references to some arbitrary name (a method
> > parameter name to be exact). Is that doable ? If so - what are my
> > options ?
> >
> > thanks,
> > d
> >
> > --
> > https://hell.art.pl == terror.org.pl == terror.icm.edu.pl/~d/gpg
> >
> >
> >
> >
> >
> > _______________________________________________
> > https://nemerle.org/mailman/listinfo/devel-en
> >
> >
> >
> >
>
>
> --
> Kamil Skalski
> http://nazgul.omega.pl
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list