Course of Raku / Regexes and grammars / Grammars

Tokens and rules

Inside a grammar you have been writing token. There are actually three keywords for declaring a named pattern — regex, token, and rule — and they differ in two small but important ways: whether they backtrack, and whether spaces in the pattern are significant.

Knowing which to choose makes grammars both faster and easier to read. This section explains all three.

Topics in this section

Practice

Complete the quizzes that cover the contents of this section.

Exercises

This section contains 3 exercises. Examine all the topics of this section before doing the coding practice.

  1. Regex versus token
  2. A spaced rule
  3. A spaced assignment

Course navigation

Solution: Parse a time   |   regex, token, and rule