From 5ff428dc0c9dd90eb52923592e0ba21ba7a5c5e4 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Thu, 23 Mar 2023 12:44:32 +0100 Subject: [PATCH] RakuAST: add deparse/raku/test for RakuAST::MetaInfix::Cross Also simplify the .raku for all RakuAST::MetaInfix classes as these all .raku to the same structure apart from the invocant class --- src/core.c/RakuAST/Deparse.pm6 | 4 +++ src/core.c/RakuAST/Raku.pm6 | 14 +-------- t/12-rakuast/meta-operators.rakutest | 43 +++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/core.c/RakuAST/Deparse.pm6 b/src/core.c/RakuAST/Deparse.pm6 index e68f5c5cd4e..1bb2061b692 100644 --- a/src/core.c/RakuAST/Deparse.pm6 +++ b/src/core.c/RakuAST/Deparse.pm6 @@ -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) ~ '!' } diff --git a/src/core.c/RakuAST/Raku.pm6 b/src/core.c/RakuAST/Raku.pm6 index feefaf502d6..cb50048b0c0 100644 --- a/src/core.c/RakuAST/Raku.pm6 +++ b/src/core.c/RakuAST/Raku.pm6 @@ -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) } diff --git a/t/12-rakuast/meta-operators.rakutest b/t/12-rakuast/meta-operators.rakutest index 10e9565502c..bdca085965c 100644 --- a/t/12-rakuast/meta-operators.rakutest +++ b/t/12-rakuast/meta-operators.rakutest @@ -1,7 +1,7 @@ use v6.e.PREVIEW; use Test; -plan 7; +plan 8; my $ast; my $deparsed; @@ -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(