Skip to content

Commit

Permalink
Add ability to recognize operator subs. The ability to define
Browse files Browse the repository at this point in the history
operator subs comes in the next commits.
  • Loading branch information
pmichaud committed May 14, 2009
1 parent 1e3683e commit bf281cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/parser/actions.pm
Expand Up @@ -2033,6 +2033,20 @@ method variable($/, $key) {
:viviself('Failure'), :node($/) )
);
}
elsif $key eq 'subnoun' {
my $varname := ~$<sublongname>;
my $match :=
Perl6::Grammar::opname($varname, :grammar('Perl6::Grammar'));
if $match { $varname := ~$match<category> ~ ':' ~ ~$match[0]; }
$var := PAST::Var.new( :name($varname), :node($/) );
$var<sigil> := '';
my $sym := outer_symbol($varname);
$var.scope( ($sym && $sym<scope>) || 'package');
if $var.scope() eq 'package' {
$var.viviself(PAST::Op.new( :pasttype('call'), :name('undef') ));
}
}

make $var;
}

Expand Down Expand Up @@ -2711,9 +2725,6 @@ method colonpair($/, $key) {
$/.panic('complex varname colonpair case not yet implemented');
}
}
else {
$/.panic($key ~ " pairs not yet implemented.");
}

my $past := PAST::Op.new(
:node($/),
Expand Down
23 changes: 19 additions & 4 deletions src/parser/grammar.pg
Expand Up @@ -803,10 +803,11 @@ token constant_declarator {
token variable {
<?sigil>
[
| <sigil> <twigil>? <desigilname> {*} #= desigilname
| <special_variable> {*} #= special_variable
| <sigil> $<matchidx>=[\d+] {*} #= $0
| <sigil> <?before '<'> <postcircumfix> {*} #= $<>
|| '&' <twigil>? <sublongname=subshortname> {*} #= subnoun
|| <sigil> <twigil>? <desigilname> {*} #= desigilname
|| <special_variable> {*} #= special_variable
|| <sigil> $<matchidx>=[\d+] {*} #= $0
|| <sigil> <?before '<'> <postcircumfix> {*} #= $<>
]
}

Expand Down Expand Up @@ -867,6 +868,20 @@ token morename {
]?
}

token subshortname {
<category> <colonpair>+
}

token category { 'infix' | 'prefix' | 'postfix' }

## used internally to convert p6 opnames to internal ones
regex opname {
<category> ':'
[ '<' \s* [ (\S+) \s* ] '>'
| '«' \s* [ (\S+) \s* ] '»'
]
}

token value {
| <quote> {*} #= quote
| <number> {*} #= number
Expand Down

0 comments on commit bf281cf

Please sign in to comment.