Course of Raku / Regexes and grammars / Grammars

What is a grammar

A single regex is good at recognising one kind of text. But real data — a date, an e-mail address, a whole configuration file — has structure made of many smaller pieces. A grammar is a way to give names to those pieces and combine them into one description.

Before the grammar itself, this section introduces the building block it is made of: the named regex. Once you can name a pattern and reuse it, you are ready for the grammar — the next level up. A grammar is more than a tidy collection of named patterns: it binds them into a single, named unit that describes a whole structured format. That is the new quality it brings to regexes — the power to parse a thing as a whole, not merely match one piece of it.

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. A named token
  2. Reuse a token
  3. Year and month

Course navigation

Grammars   |   Named regexes