Course of Raku / Regexes and grammars / Grammars / The parse tree, make and made / make and made

Quiz — make and made

What does the following program print?

grammar G {
    token TOP    { <number> { make $<number>.Int ** 2 } }
    token number { \d+ }
}

say G.parse('5').made;
0「5」
05
125
055

The inline block stores $<number>.Int ** 2 on the match. The token captured 5, converting it to the integer 5 and squaring it gives 25, which made returns.

Course navigation

make and made   |   Extract the number