Skip to content

Commit

Permalink
Implement bracketed infixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 28, 2010
1 parent 0c65df6 commit e659dd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Perl6/Actions.pm
Expand Up @@ -2106,7 +2106,7 @@ method infixish($/) {

if $<infix_prefix_meta_operator> {
my $metaop := ~$<infix_prefix_meta_operator><sym>;
my $sym := ~$<infix_prefix_meta_operator><infixish>;
my $sym := ~$<infix_prefix_meta_operator><infixish><OPER>;
my $opsub := "&infix:<$metaop$sym>";
my $base_opsub := "&infix:<$sym>";
if $opsub eq "&infix:<!=>" {
Expand Down Expand Up @@ -2140,6 +2140,10 @@ method infixish($/) {

make PAST::Op.new( :name($opsub), :pasttype('call') );
}

if $<infixish> {
make $<infixish>.ast;
}
}

method prefix_circumfix_meta_operator:sym<reduce>($/) {
Expand Down Expand Up @@ -2174,7 +2178,7 @@ method infix_circumfix_meta_operator:sym<« »>($/) {
sub make_hyperop($/) {
my $opsub := '&infix:<' ~ ~$/ ~ '>';
unless %*METAOPGEN{$opsub} {
my $base_op := '&infix:<' ~ $<infixish>.Str ~ '>';
my $base_op := '&infix:<' ~ $<infixish><OPER>.Str ~ '>';
my $dwim_lhs := $<opening> eq '<<' || $<opening> eq '«';
my $dwim_rhs := $<closing> eq '>>' || $<closing> eq '»';
get_outermost_block().loadinit.push(PAST::Op.new(
Expand Down
16 changes: 16 additions & 0 deletions src/Perl6/Grammar.pm
Expand Up @@ -1449,10 +1449,13 @@ token prefixish {
}

token infixish {
[
| '[' ~ ']' <infixish> <OPER=.copyOPER('infixish')>
| <OPER=infix_circumfix_meta_operator>
| <OPER=infix> <![=]>
| <OPER=infix_prefix_meta_operator>
| <infix> <OPER=infix_postfix_meta_operator>
]
}

token postfixish {
Expand Down Expand Up @@ -1545,6 +1548,19 @@ method copyO($from) {
};
}
method copyOPER($from) {
# There must be a a better way, but until pmichaud++ shows us it,
# this is the best I can come up with. :-) -- jnthn
my $m := self.MATCH();
my $r := $m{$from}<OPER>;
Q:PIR {
(%r, $I0) = self.'!cursor_start'()
%r.'!cursor_pass'($I0, '')
$P0 = find_lex '$r'
setattribute %r, '$!match', $P0
};
}
proto token dotty { <...> }
token dotty:sym<.> {
<sym> <dottyop>
Expand Down

0 comments on commit e659dd5

Please sign in to comment.