Skip to content

Commit

Permalink
RakuAST: add deparse/raku/test for RakuAST::MetaInfix::Reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Mar 23, 2023
1 parent 36b6244 commit 81f2ea2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/core.c/RakuAST/Deparse.pm6
Expand Up @@ -580,6 +580,10 @@ class RakuAST::Deparse {
self.deparse($ast.infix) ~ '!'
}

multi method deparse(RakuAST::MetaInfix::Reverse:D $ast --> Str:D) {
'R' ~ self.deparse($ast.infix)
}

multi method deparse(RakuAST::Method:D $ast --> Str:D) {
self!method($ast, 'method')
}
Expand Down
4 changes: 4 additions & 0 deletions src/core.c/RakuAST/Raku.pm6
Expand Up @@ -375,6 +375,10 @@ augment class RakuAST::Node {
self!positional(self.infix)
}

multi method raku(RakuAST::MetaInfix::Reverse:D: --> Str:D) {
self!positional(self.infix)
}

multi method raku(RakuAST::Method:D: --> Str:D) {
my str @nameds = 'name';
@nameds.unshift("multiness") if self.multiness;
Expand Down
17 changes: 16 additions & 1 deletion t/12-rakuast/meta-operators.rakutest
@@ -1,7 +1,7 @@
use v6.e.PREVIEW;
use Test;

plan 5;
plan 6;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -34,6 +34,21 @@ subtest 'Assignment meta-op evaluates to expected value' => {
}
}

subtest 'Reverse meta-op evaluates to expected value' => {
# 42 R- 666
ast RakuAST::ApplyInfix.new(
left => RakuAST::IntLiteral.new(42),
infix => RakuAST::MetaInfix::Reverse.new(
RakuAST::Infix.new("-")
),
right => RakuAST::IntLiteral.new(666)
);

is-deeply $deparsed, '42 R- 666', 'deparse';
is-deeply $_, 624, @type[$++]
for EVAL($ast), EVAL($deparsed), EVAL(EVAL $raku);
}

subtest 'Assignment meta-op with short-circuit || evaluates to true LHS' => {
my $test = 10;
my $update = 2;
Expand Down

0 comments on commit 81f2ea2

Please sign in to comment.