Skip to content

Commit

Permalink
RakuAST: change reducecheck to specific ternary handling
Browse files Browse the repository at this point in the history
Not sure exactly how I'm going to handle ternaries in the
OperatorProperties case yet, but this is a first step towards
being more clear about this rather than burying it in some
obscure general feature that only appears to be used in one
situation in the Raku grammar.
  • Loading branch information
lizmat committed Aug 31, 2023
1 parent 960a40d commit abc13a3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Raku/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
#-------------------------------------------------------------------------------
# Expression parsing
# Helper methods for throwing exceptions
method EXPR-nonassoc($cur, $left, $right) {
self.typed-panic: 'X::Syntax::NonAssociative',
:left(~$left), :right(~$right);
Expand Down Expand Up @@ -1479,7 +1480,6 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
my str $opassoc := ~nqp::atkey(%opO, 'assoc');
my str $key;
my str $sym;
my $reducecheck;
my $arg;
if $opassoc eq 'unary' {
Expand All @@ -1503,8 +1503,12 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
else { # infix op assoc: left|right|ternary|...
$op[1] := nqp::pop(@termstack); # right
$op[0] := nqp::pop(@termstack); # left
$reducecheck := nqp::atkey(%opO, 'reducecheck');
self."$reducecheck"($op) unless nqp::isnull($reducecheck);
# we haz a ternary, adjust for that
if nqp::atkey(%opO,'ternary') {
$op[2] := $op[1];
$op[1] := $op<infix><EXPR>;
}
$key := 'INFIX';
}
self.'!reduce_with_match'('EXPR', $key, $op);
Expand Down Expand Up @@ -2169,7 +2173,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
|| <.typed-panic: "X::Syntax::Confused",
reason => "Confused: Found ?? but no !!">
]
<O(|%conditional, :reducecheck<ternary>)>
<O(|%conditional, :ternary)>
}
token infix:sym<,> {
Expand Down

0 comments on commit abc13a3

Please sign in to comment.