Course of Raku / Regexes and grammars / Grammars

Action classes

Inline { make … } blocks work, but they clutter a grammar with logic and make it harder to read. The tidy solution is an action class: a separate class whose methods are named after the grammar’s tokens and supply the make for each one.

This section shows how to write an action class, how to hand it to .parse, and when to prefer it over inline actions.

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. One grammar, two actions
  2. An upper-case action
  3. A multiply action

Course navigation

Solution: Reverse a word   |   Writing an action class