Skip to content

Commit

Permalink
Allow parsing of postcircumfix:<...> and also allow methods as well a…
Browse files Browse the repository at this point in the history
…s subs to be used to define operators.
  • Loading branch information
jnthn committed May 15, 2009
1 parent ee6739d commit e86dd9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/parser/actions.pm
Expand Up @@ -818,8 +818,11 @@ method method_def($/) {
my $block := $<block>.ast;
$block.blocktype('method');

if $<longname> {
$block.name( ~$<longname> );
if $<deflongname> {
my $name := ~$<deflongname>;
my $match := Perl6::Grammar::opname($name, :grammar('Perl6::Grammar') );
if $match { $name := add_optoken($block, $match); }
$block.name( $name );
}

# Add lexical 'self' and a slot for the candidate dispatcher list.
Expand Down Expand Up @@ -3118,7 +3121,7 @@ sub add_optoken($block, $match) {
my $equiv := 'infix:+';
if $category eq 'prefix' { $equiv := 'prefix:+' }
elsif $category eq 'postfix' { $equiv := 'postfix:++' }
elsif $category eq 'circumfix' { $equiv := 'term:' }
elsif $category eq 'circumfix' || $category eq 'postcircumfix' { $equiv := 'term:' }
my $past := PAST::Op.new( :name('newtok'), :pasttype('callmethod'),
PAST::Op.new(
:inline(" %r = get_hll_global ['Perl6';'Grammar'], '$optable'")
Expand Down
4 changes: 2 additions & 2 deletions src/parser/grammar.pg
Expand Up @@ -426,7 +426,7 @@ rule routine_def {

rule method_def {
[
| $<longname>=[<[ ! ]>?<name>] [ <multisig> | <trait> ]*
| $<deflongname>=[<[ ! ]>?<longname>] [ <multisig> | <trait> ]*
| <multisig> <trait>*
| ::
]
Expand Down Expand Up @@ -873,7 +873,7 @@ token subshortname {
<category> <colonpair>+
}

token category { 'infix' | 'prefix' | 'postfix' | 'circumfix' | 'trait_auxiliary' }
token category { 'infix' | 'prefix' | 'postfix' | 'circumfix' | 'postcircumfix' | 'trait_auxiliary' }

## used internally to convert p6 opnames to internal ones
regex opname {
Expand Down

0 comments on commit e86dd9e

Please sign in to comment.