Skip to content

Commit

Permalink
Allow calling .DEPARSE with a class
Browse files Browse the repository at this point in the history
This allows for subclassing RakuAST::Deparse for customization.

    use experimental :rakuast;
    class A is RakuAST::Deparse { }
    say Q/say "foo"/.AST.DEPARSE(A);  # say("foo")
  • Loading branch information
lizmat committed Jan 10, 2023
1 parent b436566 commit 34efa23
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Raku/ast/base.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,13 @@ class RakuAST::Node {

# Hook into the Raku RakuAST::Deparse class (by default) or any other
# class that has been put into the hllsym hash for 'Raku'
method DEPARSE() {
method DEPARSE($class?) {
# TODO: figure out how to take a single optional positional that
# expects a class, and how to check for that here.
nqp::gethllsym('Raku','DEPARSE').deparse(self)
($class =:= NQPMu
?? nqp::gethllsym('Raku','DEPARSE')
!! $class
).deparse(self)
}

method IMPL-SORTED-KEYS(Mu $hash) {
Expand Down

0 comments on commit 34efa23

Please sign in to comment.