On Mon, May 31, 2010 at 01:59:10PM +0100, Allison Randal wrote:
> On 5/31/10 12:40 PM, Allison Randal wrote:
> >... or something completely new and different.
>
> The extra mile is syntax that's actually pleasant to work with.
>
> transform as_post PAST::Op
> where pirop is 'add'
> and children.count is 2
> and children.returns are ('PAST::Val' or 'PAST::Var')
> to POST::Op
> with name = tree.name,
> pos = tree.pos,
> children = (tree.left.as_post, tree.right.as_post)
> rewrite op PAST::Op
> where pirop is 'add'
> by { running this code }
Just for fun:
multi method as_post( PAST::Op $x
where $x.pirop
and @$x.elems == 2
and all(@$x) ~~ (PAST::Val | PAST::Var) ) {
my $post = POST::Op.new(@$x>>.as_post, :name($x.name), :pos($x.pos));
given $x {
when .pirop eq 'add' { ...run this code... }
when ... { ... run this other code ... }
}
return $post;
}
You're quite welcome to run away screaming at the use of Perl 6
syntax here... I thought I'd just see what might be possible with it.
For those having difficulty reading the above, @$x ends up meaning
"children of $x". If order of evaluation of children nodes is important
(because of side effects), @$x>>.as_post might need to be written as
@$x.map(*.as_post) instead.
Anyway, just stirring the pot a bit...
Pm
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev