← All programs · Grammars and match trees
Grammars and match trees #10
Raku++ 4.0.1 prints exactly what Rakudo 2026.08 prints
This is valid Raku: Rakudo 2026.08, the reference compiler, runs it without complaint, and the two outputs match character for character.
The program
The grammar and its inputs come first. rm-dump, the same in every program of this topic, prints one line for every field of every node of the resulting Match — its text, position, .orig, .prematch, .made, its captures — so a difference in the shape of the match shows as a difference in output.
grammar G {
token TOP { '=' | [ $<k1>=[ <r1> ] | 'x' ] | $<k1>=[ <?r0> <!r0> <r0> ] }
rule r0 { <[a..c]>+ }
rule r1 { <[a..c]> }
}
sub rm-q($v) { $v.defined ?? $v.raku !! 'Nil' }
sub rm-dump($m, Str $p) {
unless $m.defined { say "$p kind Nil"; return }
if $m ~~ Match {
say "$p kind Match";
say "$p str {$m.Str.raku}";
say "$p from {$m.from}";
say "$p to {$m.to}";
say "$p orig {rm-q($m.orig)}";
say "$p target {rm-q($m.target)}";
say "$p pre {rm-q($m.prematch)}";
say "$p post {rm-q($m.postmatch)}";
say "$p made {rm-q($m.made)}";
for $m.list.kv -> $i, $c { rm-dump($c, $p ~ '[' ~ $i ~ ']') }
for $m.hash.keys.sort -> $k { rm-dump($m.hash{$k}, $p ~ '<' ~ $k ~ '>') }
# Captures that start at the same position have no specified order
# (rakupp's varies from run to run), so ties are ordered by name.
say "$p caps {$m.caps.sort({ .value.from, ~.key }).map({ .key ~ '=' ~ .value.Str.raku }).join(' ')}";
}
elsif $m ~~ Positional {
say "$p kind List({$m.elems})";
for $m.list.kv -> $i, $c { rm-dump($c, $p ~ '.' ~ $i) }
}
else { say "$p kind {$m.^name}" }
}
my @inputs = "c", "=", ",c";
for @inputs.kv -> $i, $in {
say "#$i input {$in.raku}";
rm-dump(G.parse($in), '@' ~ $i);
}
Run executes the program in your browser, with the Raku++ build this site ships. Edit it and try variations.
What each compiler printed
| Rakudo 2026.08 | Raku++ 4.0.1 | |
|---|---|---|
input "c" | ||
$/ kind | Match | Match |
$/ str | "c" | "c" |
$/ from | 0 | 0 |
$/ to | 1 | 1 |
$/ orig | "c" | "c" |
$/ target | "c" | "c" |
$/ pre | "" | "" |
$/ post | "" | "" |
$/ made | Nil | Nil |
$/<k1> kind | Match | Match |
$/<k1> str | "c" | "c" |
$/<k1> from | 0 | 0 |
$/<k1> to | 1 | 1 |
$/<k1> orig | "c" | "c" |
$/<k1> target | "c" | "c" |
$/<k1> pre | "" | "" |
$/<k1> post | "" | "" |
$/<k1> made | Nil | Nil |
$/<k1> caps | | |
$/<r1> kind | Match | Match |
$/<r1> str | "c" | "c" |
$/<r1> from | 0 | 0 |
$/<r1> to | 1 | 1 |
$/<r1> orig | "c" | "c" |
$/<r1> target | "c" | "c" |
$/<r1> pre | "" | "" |
$/<r1> post | "" | "" |
$/<r1> made | Nil | Nil |
$/<r1> caps | | |
$/ caps | k1="c" r1="c" | k1="c" r1="c" |
input "=" | ||
$/ kind | Match | Match |
$/ str | "=" | "=" |
$/ from | 0 | 0 |
$/ to | 1 | 1 |
$/ orig | "=" | "=" |
$/ target | "=" | "=" |
$/ pre | "" | "" |
$/ post | "" | "" |
$/ made | Nil | Nil |
$/ caps | | |
input ",c" | ||
$/ kind | Nil | Nil |
grammars-v1 · seed 49 · recorded 2026-09-23 with Rakudo 2026.08 and Raku++ 4.0.1-132-g3e242220-modified · Source on GitHub ↗