| 1 | package Pugs::AST::Expression; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Data::Dumper; | ||
| 6 | |||
| 7 | sub term { | ||
| 8 | { term => $_[1]{'term'}->() ,} | ||
| 9 | } | ||
| 10 | |||
| 11 | sub operator { | ||
| 12 | my $self = shift; | ||
| 13 | my $match = shift; | ||
| 14 | # die "not a match" unless ref($match) eq 'Pugs::Runtime::Match'; | ||
| 15 | my %h = %$match; | ||
| 16 | my %opt = @_; | ||
| 17 | |||
| 18 | #print "capture ", Dumper($match) if $opt{'fixity'} eq 'circumfix'; | ||
| 19 | for ( keys %h ) { | ||
| 20 | $h{$_} = $h{$_}->(); | ||
| 21 | } | ||
| 22 | my @a = @$match; | ||
| 23 | if ( @a ) { | ||
| 24 | $a = shift @a; | ||
| 25 | for ( @$a ) { | ||
| 26 | $_ = $self->operator( $_ ); | ||
| 27 | ${$_}{fixity} = $opt{fixity}; | ||
| 28 | } | ||
| 29 | $h{list} = $a; | ||
| 30 | delete $opt{fixity}; | ||
| 31 | } | ||
| 32 | $h{$_} = $opt{$_} for keys %opt; | ||
| 33 | return \%h; | ||
| 34 | } | ||
| 35 | |||
| 36 | 1; |