Course of Raku / Regexes and grammars / Grammars / What is a grammar / The grammar keyword

Quiz — What is a grammar

What does the following program print?

my token greet { 'hi' }

say so 'hi there' ~~ / <greet> /;
1True
0False
0「greet」
0hi

The named token greet matches the literal text hi. Calling it as <greet> inside the pattern looks for that text, which is present at the start of 'hi there', so the match succeeds and so returns True.

Course navigation

The grammar keyword   |   A named token