diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm index 58083c165b3..9ea9a0d4976 100644 --- a/src/Perl6/Actions.pm +++ b/src/Perl6/Actions.pm @@ -1976,6 +1976,23 @@ method infixish($/) { } } +method prefix_circumfix_meta_operator:sym($/) { + my $opsub := '&prefix:<' ~ ~$/ ~ '>'; + unless %*METAOPGEN{$opsub} { + my $base_op := '&infix:<' ~ $.Str ~ '>'; + @BLOCK[0].loadinit.push(PAST::Op.new( + :pasttype('bind'), + PAST::Var.new( :name($opsub), :scope('package') ), + PAST::Op.new( + :pasttype('callmethod'), :name('assuming'), + PAST::Op.new( :pirop('find_sub_not_null__Ps'), '&reduce' ), + PAST::Op.new( :pirop('find_sub_not_null__Ps'), $base_op ) + ) + )); + } + make PAST::Op.new( :name($opsub), :pasttype('call') ); +} + method postfixish($/) { if $ { my $past := $.ast; diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm index 5c9475ed62c..02cf3b883bf 100644 --- a/src/Perl6/Grammar.pm +++ b/src/Perl6/Grammar.pm @@ -1048,6 +1048,13 @@ INIT { Perl6::Grammar.O(':prec, :assoc', '%loose_or'); } +token prefixish { + [ + | + | + ] + <.ws> +} token infixish { | @@ -1075,12 +1082,29 @@ token postop { | } +proto token prefix_circumfix_meta_operator { <...> } + proto token infix_postfix_meta_operator { <...> } proto token infix_prefix_meta_operator { <...> } proto token postfix_prefix_meta_operator { <...> } +regex prefix_circumfix_meta_operator:sym { + :my $*IN_REDUCE := 1; + + + '[' + [ + || +# || \\ + || + ] + ']' + + , :uassoc')> +} + token postfix_prefix_meta_operator:sym<ยป> { [ | '>>' ] } diff --git a/src/core/metaops.pm b/src/core/metaops.pm index df421308677..b6c6e6215ea 100644 --- a/src/core/metaops.pm +++ b/src/core/metaops.pm @@ -20,3 +20,7 @@ our multi sub crosswith(&op, Iterable $a-iterable, Iterable $b-iterable) { } } } + +our multi reduce(&op, $list) { + $list.reduce(&op) +}