Skip to content

Commit

Permalink
RakuAST: add deparse/raku/test for RakuAST::MetaInfix::Cross
Browse files Browse the repository at this point in the history
Also simplify the .raku for all RakuAST::MetaInfix classes as these
all .raku to the same structure apart from the invocant class
  • Loading branch information
lizmat committed Mar 23, 2023
1 parent fb30afa commit 5ff428d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/core.c/RakuAST/Deparse.pm6
Expand Up @@ -579,6 +579,10 @@ class RakuAST::Deparse {
self.deparse($ast.infix) ~ '='
}

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

multi method deparse(RakuAST::MetaInfix::Negate:D $ast --> Str:D) {
self.deparse($ast.infix) ~ '!'
}
Expand Down
14 changes: 1 addition & 13 deletions src/core.c/RakuAST/Raku.pm6
Expand Up @@ -367,19 +367,7 @@ augment class RakuAST::Node {

#- M ---------------------------------------------------------------------------

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

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

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

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

Expand Down
43 changes: 42 additions & 1 deletion t/12-rakuast/meta-operators.rakutest
@@ -1,7 +1,7 @@
use v6.e.PREVIEW;
use Test;

plan 7;
plan 8;

my $ast;
my $deparsed;
Expand Down Expand Up @@ -49,6 +49,47 @@ subtest 'Reverse meta-op evaluates to expected value' => {
for EVAL($ast), EVAL($deparsed), EVAL(EVAL $raku);
}

subtest 'Cross meta-op evaluates to expected value' => {
# (1, 2) X+ (1, 3)
ast RakuAST::ApplyListInfix.new(
infix => RakuAST::MetaInfix::Cross.new(
RakuAST::Infix.new("+")
),
operands => (
RakuAST::Circumfix::Parentheses.new(
RakuAST::SemiList.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::ApplyListInfix.new(
infix => RakuAST::Infix.new(","),
operands => (
RakuAST::IntLiteral.new(1),
RakuAST::IntLiteral.new(2),
)
)
)
)
),
RakuAST::Circumfix::Parentheses.new(
RakuAST::SemiList.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::ApplyListInfix.new(
infix => RakuAST::Infix.new(","),
operands => (
RakuAST::IntLiteral.new(1),
RakuAST::IntLiteral.new(3),
)
)
)
)
),
)
);

is-deeply $deparsed, '(1, 2) X+ (1, 3)', 'deparse';
is-deeply $_, (2,4,3,5), @type[$++]
for EVAL($ast), EVAL($deparsed), EVAL(EVAL $raku);
}

subtest 'Zip meta-op evaluates to expected value' => {
# (1, 2) Z== (1, 3)
ast RakuAST::ApplyListInfix.new(
Expand Down

0 comments on commit 5ff428d

Please sign in to comment.