← All programs · Grammars and match trees
Grammars and match trees #7
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 {
regex TOP { <k0=r1> }
token r0 { \d+ }
regex r1 { \w+ }
regex r2 { <[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 = "b__b", "ca", "a";
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 "b__b" | ||
$/ kind | Match | Match |
$/ str | "b__b" | "b__b" |
$/ from | 0 | 0 |
$/ to | 4 | 4 |
$/ orig | "b__b" | "b__b" |
$/ target | "b__b" | "b__b" |
$/ pre | "" | "" |
$/ post | "" | "" |
$/ made | Nil | Nil |
$/<k0> kind | Match | Match |
$/<k0> str | "b__b" | "b__b" |
$/<k0> from | 0 | 0 |
$/<k0> to | 4 | 4 |
$/<k0> orig | "b__b" | "b__b" |
$/<k0> target | "b__b" | "b__b" |
$/<k0> pre | "" | "" |
$/<k0> post | "" | "" |
$/<k0> made | Nil | Nil |
$/<k0> caps | | |
$/<r1> kind | Match | Match |
$/<r1> str | "b__b" | "b__b" |
$/<r1> from | 0 | 0 |
$/<r1> to | 4 | 4 |
$/<r1> orig | "b__b" | "b__b" |
$/<r1> target | "b__b" | "b__b" |
$/<r1> pre | "" | "" |
$/<r1> post | "" | "" |
$/<r1> made | Nil | Nil |
$/<r1> caps | | |
$/ caps | k0="b__b" r1="b__b" | k0="b__b" r1="b__b" |
input "ca" | ||
$/ kind | Match | Match |
$/ str | "ca" | "ca" |
$/ from | 0 | 0 |
$/ to | 2 | 2 |
$/ orig | "ca" | "ca" |
$/ target | "ca" | "ca" |
$/ pre | "" | "" |
$/ post | "" | "" |
$/ made | Nil | Nil |
$/<k0> kind | Match | Match |
$/<k0> str | "ca" | "ca" |
$/<k0> from | 0 | 0 |
$/<k0> to | 2 | 2 |
$/<k0> orig | "ca" | "ca" |
$/<k0> target | "ca" | "ca" |
$/<k0> pre | "" | "" |
$/<k0> post | "" | "" |
$/<k0> made | Nil | Nil |
$/<k0> caps | | |
$/<r1> kind | Match | Match |
$/<r1> str | "ca" | "ca" |
$/<r1> from | 0 | 0 |
$/<r1> to | 2 | 2 |
$/<r1> orig | "ca" | "ca" |
$/<r1> target | "ca" | "ca" |
$/<r1> pre | "" | "" |
$/<r1> post | "" | "" |
$/<r1> made | Nil | Nil |
$/<r1> caps | | |
$/ caps | k0="ca" r1="ca" | k0="ca" r1="ca" |
input "a" | ||
$/ kind | Match | Match |
$/ str | "a" | "a" |
$/ from | 0 | 0 |
$/ to | 1 | 1 |
$/ orig | "a" | "a" |
$/ target | "a" | "a" |
$/ pre | "" | "" |
$/ post | "" | "" |
$/ made | Nil | Nil |
$/<k0> kind | Match | Match |
$/<k0> str | "a" | "a" |
$/<k0> from | 0 | 0 |
$/<k0> to | 1 | 1 |
$/<k0> orig | "a" | "a" |
$/<k0> target | "a" | "a" |
$/<k0> pre | "" | "" |
$/<k0> post | "" | "" |
$/<k0> made | Nil | Nil |
$/<k0> caps | | |
$/<r1> kind | Match | Match |
$/<r1> str | "a" | "a" |
$/<r1> from | 0 | 0 |
$/<r1> to | 1 | 1 |
$/<r1> orig | "a" | "a" |
$/<r1> target | "a" | "a" |
$/<r1> pre | "" | "" |
$/<r1> post | "" | "" |
$/<r1> made | Nil | Nil |
$/<r1> caps | | |
$/ caps | k0="a" r1="a" | k0="a" r1="a" |
grammars-v1 · seed 46 · recorded 2026-09-23 with Rakudo 2026.08 and Raku++ 4.0.1-132-g3e242220-modified · Source on GitHub ↗