Course of Raku / Regexes and grammars / Grammars / Action classes / Exercises

Humanise a date

Problem

Write a grammar that parses an ISO date such as '2026-07-05' into three tokens: year, month, and day. Write an action class in which each token method makes a value: year and day make their number as an integer, while month makes the English month name (1January, …, 12December). The TOP method then reads those three values with .made and makes a human-readable string like '5 July 2026'. Parse '2026-07-05' with the action class and print .made.

Example

The program prints:

5 July 2026

Solution

See the solution

Course navigation

Solution: One grammar, two actions   |   Solution: Humanise a date