Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some fixes to precedence handling.
With these, we now pass all but 1 test of S06-traits/precedence.t.
  • Loading branch information
jnthn committed Oct 25, 2012
1 parent 0e866af commit 8c6ccf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Perl6/Grammar.pm
Expand Up @@ -2962,6 +2962,13 @@ grammar Perl6::Grammar is HLL::Grammar {
# This also becomes the current MAIN. Also place it in %?LANG.
%*LANG<MAIN> := self.WHAT;
$*W.install_lexical_symbol($*W.cur_lexpad(), '%?LANG', $*W.p6ize_recursive(%*LANG));

# Declarand should get precedence traits.
if $is_oper && nqp::isconcrete($declarand) {
my $base_prec := self.O($prec).MATCH<prec>;
$*W.apply_trait(self.MATCH, '&trait_mod:<is>', $declarand,
:prec(nqp::hash('prec', $base_prec)));
}

# May also need to add to the actions.
if $category eq 'circumfix' {
Expand Down
8 changes: 6 additions & 2 deletions src/core/traits.pm
Expand Up @@ -87,13 +87,17 @@ multi trait_mod:<is>(Routine $r, :&equiv) {
!! die "Routine given to equiv does not appear to be an operator";
}
multi trait_mod:<is>(Routine $r, :&tighter) {
if !nqp::can($r, 'prec') || !$r.prec<prec> {
die "Routine given to tigher does not appear to be an operator"
unless nqp::can(&tighter, 'prec');
if !nqp::can($r, 'prec') || ($r.prec<prec> // "") !~~ /<[@:]>/ {
trait_mod:<is>($r, :prec(&tighter.prec))
}
$r.prec<prec> := $r.prec<prec>.subst(/\=/, '@=');
}
multi trait_mod:<is>(Routine $r, :&looser) {
if !nqp::can($r, 'prec') || !$r.prec<prec> {
die "Routine given to looser does not appear to be an operator"
unless nqp::can(&looser, 'prec');
if !nqp::can($r, 'prec') || ($r.prec<prec> // "") !~~ /<[@:]>/ {
trait_mod:<is>($r, :prec(&looser.prec))
}
$r.prec<prec> := $r.prec<prec>.subst(/\=/, ':=');
Expand Down

0 comments on commit 8c6ccf5

Please sign in to comment.