Skip to content

Commit 9852c9e

Browse files
committed
Don't clobber prec in precedence hash
Fixes RT #80614 Fixes RT #120704 Fixes RT #125407 The issue is that the operator precedence table from HLL::Grammar (used for both Grammar.O and Grammar.EXPR) has a hash of hashes, the values of which specify things like precedence and associativity. For example, the hash contains something like the following for the key '%list_assignment': { :prec<i=>, :assoc<right>, :sub<e=> } The 'sub' key is the...umm, key here. After handling some things with %inO<prec> in HLL::Grammar.EXPR, %inO<sub> is assigned to %inO<prec> - changing the precedence of list assignment from 'i=' to 'e=' *globally*. Instead of modifying the precedence hashes returned through the matches, this patch checks subprecedence ('sub') before precedence ('prec') when fetching the precedence for an operator in the precedence table.
1 parent efbfabd commit 9852c9e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/HLL/Grammar.nqp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ An operator precedence parser.
454454
while @prefixish && @postfixish {
455455
my %preO := @prefixish[0]<OPER><O>;
456456
my %postO := @postfixish[nqp::elems(@postfixish)-1]<OPER><O>;
457-
my $preprec := nqp::ifnull(nqp::atkey(%preO, 'prec'), '');
458-
my $postprec := nqp::ifnull(nqp::atkey(%postO, 'prec'), '');
457+
my $preprec := nqp::ifnull(nqp::atkey(%preO, 'sub'), nqp::ifnull(nqp::atkey(%preO, 'prec'), ''));
458+
my $postprec := nqp::ifnull(nqp::atkey(%postO, 'sub'), nqp::ifnull(nqp::atkey(%postO, 'prec'), ''));
459459

460460
if $postprec gt $preprec ||
461461
$postprec eq $preprec && %postO<uassoc> eq 'right'
@@ -508,11 +508,11 @@ An operator precedence parser.
508508
$term_done := 1;
509509
last;
510510
}
511-
512-
%inO<prec> := nqp::ifnull(nqp::atkey(%inO, 'sub'), nqp::atkey(%inO, 'prec'));
513-
511+
514512
while @opstack {
515-
$opprec := ~@opstack[+@opstack-1]<OPER><O><prec>;
513+
my %opO := @opstack[+@opstack-1]<OPER><O>;
514+
515+
$opprec := nqp::ifnull(nqp::atkey(%opO, 'sub'), nqp::atkey(%opO, 'prec'));
516516
last unless $opprec gt $inprec;
517517
self.EXPR_reduce(@termstack, @opstack);
518518
}

0 commit comments

Comments
 (0)