Raku Cases › RakuAST

RakuAST

The syntax tree as objects: building, printing and running it.

34 rules from 19 tests. 12 of those tests are confirmed on both engines: Raku++ and Rakudo 2026.11 both pass, or Raku++ gives Rakudo's answer on every probe of a family. The verdict is the test's, not each rule's. How to read a case.

rakuast-declaration-terminatorRaku++ passesRakudo does not pass2026-10-31 · 21cd03cd
  1. 1

    .AST.DEPARSE ends an enum or subset declaration with ;, so .AST.EVAL can parse what was rendered.

    subset Pos of Int where * > 0; my Pos $p = 5; survives .AST.EVAL

  2. 2

    .AST.DEPARSE keeps the my of my subset and my enum.

  3. 3

    .AST.DEPARSE renders enum C (a => 1) with one pair of parentheses, as written.

    enum C (a => 1) deparses as enum C (a => 1), not enum C ((a => 1))

rakuast-declaration-traitsRaku++ passesRakudo passes2026-11-09 · e4ec869c
  1. 1

    .AST.DEPARSE keeps a declaration's traits: is export with its tags on a class, sub, enum and subset, is DEPRECATED on a sub, and an attribute's is default(…) and handles <…>.

rakuast-deparseRaku++ passesRakudo passes2026-09-11 · f8df5c0d
  1. 1

    .DEPARSE on a RakuAST tree constructed from RakuAST:: classes renders Raku source text for it. inferred

rakuast-deparse-l10nRaku++ passesRakudo cannot run it2026-10-31 · 3431c375
  1. 1

    .DEPARSE("RU") renders the tree with the keywords of the language it is handed.

    $ast.DEPARSE("RU") contains мой, для and скажи

  2. 2

    .DEPARSE handed a language that is not installed is an error. inferred

rakuast-docRaku++ passesRakudo passes2026-09-12 · 1e5272e2
  1. 1

    .rakudoc on an AST answers the source's pod as RakuAST::Doc:: nodes, with the same classes in the same order for a document. inferred

More from this test: divergences (1).

rakuast-empty-and-pointy-blocksRaku++ passesRakudo passes2026-11-09 · f371f8b2
  1. 1

    .AST.DEPARSE writes an empty block body as { }.

  2. 2

    .AST.DEPARSE keeps the arrow of a pointy block that has no parameters, a for loop's included.

    -> { } and for 1, 2 -> { } keep their ->

  3. 3

    .AST.DEPARSE writes an anonymous sub as sub { … } and, with a signature, sub ($x) { … }.

rakuast-empty-edgeRaku++ passesRakudo does not pass2026-10-01 · bca3a99f · rakudo#6771
  1. 1

    RakuAST::Name::Part::EmptyEdge is accepted beside RakuAST::Name::Part::Empty for the empty name part before a leading :: or after a trailing one, and a tree built with either deparses and EVALs the same.

rakuast-evalRaku++ passesRakudo passes2026-09-11 · b7404ced
  1. 1

    .EVAL on a constructed RakuAST tree runs it in the caller's lexical scope, so the fragment sees the enclosing variables.

rakuast-eval-keeps-tree-groupingRaku++ passesRakudo passes2026-11-11 · 58e2fdd4 · #247
  1. 1

    .EVAL on a RakuAST tree evaluates the tree's own grouping, so an operand that is itself an infix, prefix, list infix or ternary stays grouped.

    the tree of (not 0) && (not 1) built from nodes EVALs to False

  2. 2

    .DEPARSE of a RakuAST tree writes no grouping parentheses that the nodes do not hold.

    the tree of (not 0) && (not 1) deparses to not 0 && not 1

rakuast-grammar-rule-viewRaku++ passesRakudo passes2026-11-14 · 657626c7 · rakudo#5479 · rakudo#5978 · rakudo#5991
  1. 1

    .AST of a grammar rule builds the rule's regex tree out of RakuAST::Regex:: nodes, and .DEPARSE renders it as source.

rakuast-l10nRaku++ passesRakudo cannot run it2026-09-12 · f38a0b48
  1. 1

    .AST($lang) parses source written with a localized keyword set, read from the role L10N::<lang> a distribution ships, and answers the same tree the English source would.

    'mein $a = 42; wenn … { sag … }'.AST("DE") parses the German keywords

  2. 2

    A localized keyword for .AST($lang) may be a bare word, a quoted non-simple word such as "il-mio", or a word outside ASCII such as füralle.

rakuast-needs-no-pragmaRaku++ passesRakudo passes2026-11-14 · e60a6163 · rakudo#6134 · rakudo#6137
  1. 1

    The RakuAST:: names are usable without use experimental :rakuast.

    RakuAST::Sub.new(…).EVAL runs with no pragma

    Also held by rakuast-names.

rakuast-registryRaku++ passesRakudo cannot run it2026-09-11 · 2028a356
  1. 1

    The RakuAST:: class names are gated behind use experimental :rakuast under 6.d and are freely visible under 6.e.

  2. 2

    The RakuAST:: classes carry their ancestry, so ~~ RakuAST::Expression and .^mro answer for them.

rakuast-start-block-deparseRaku++ passesRakudo passes2026-11-08 · 88751a81
  1. 1

    .AST.DEPARSE of a start block leaves out the implicit fresh my $/; my $!, so repeated .AST.DEPARSE rounds render the same text, and a declaration the program wrote stays.

rakuast-start-expression-deparseRaku++ passesRakudo passes2026-11-08 · a63dab44
  1. 1

    .AST.DEPARSE writes start EXPR as the expression it was written as, and a written start { … } block as a block.

    my $p = start 5 deparses as my $p = start 5

rakuast-viewRaku++ passesRakudo cannot run it2026-09-11 · 0c49e707
  1. 1

    .AST on source text returns a RakuAST::StatementList, and .AST(:compunit) wraps it in a RakuAST::CompUnit.

    q[say 1].AST.^name is RakuAST::StatementList

  2. 2

    .AST is a method of Cool, so it works on a number or an allomorph, while a Buf has no such method.

    42.AST.^name is RakuAST::StatementList

  3. 3

    .AST.DEPARSE renders the tree back to Raku source: a CompUnit terminates every statement with ;, a bare StatementList omits the last one, and a block statement ends in a newline without ;.

    q[say [+] @a].AST.DEPARSE is say [+] @a plus a newline

  4. 4

    A RakuAST::CompUnit answers .statement-list, whose .statements lists the statements and whose .unshift-statement puts one in front.

  5. 5

    The .AST method itself needs no use experimental :rakuast; only the RakuAST:: names are gated.

    Q[say 1].AST answers a StatementList with no pragma

rakuast-view-declarationsRaku++ passesRakudo does not pass2026-10-31 · acf27e4b
  1. 1

    .AST keeps what a declaration says beyond its name — traits (is rw, is Int, does R), our, the pointy parameters of if and for, no pragmas, the path of use lib and .= — so .AST.DEPARSE renders them and .AST.EVAL runs the program as written.

    has $.x is rw deparses with its is rw; $x.=abs stays .=

rakuast-view-parenthesesRaku++ passesRakudo passes2026-10-31 · 586c5160
  1. 1

    .AST keeps the parentheses a program writes, so .AST.EVAL evaluates the expression with its written grouping.

    '(1 + 2) * 3'.AST.EVAL is 9

  2. 2

    .AST.DEPARSE renders an angle subscript with its bare key.

    %h<a> deparses as %h<a>, not %h<"a">

  3. 3

    .AST keeps a subscript's adverbs, so .AST.EVAL applies them.

    %h{"a"}:delete through .AST.EVAL deletes the key

rakuast-visitRaku++ passesRakudo passes2026-09-12 · 126fd333
  1. 1

    visit-children on a RakuAST node hands each syntactic child to the callback exactly once, in source order, one level deep.

  2. 2

    visit-children does not itself set @*LINEAGE; a walker maintains it.