Course of Raku / Regexes and grammars / Grammars / Grammars, classes, and inheritance / Exercises

A boolean with proto

Problem

Write a grammar that parses a bool, which is either the word true or the word false. Use a proto token with two :sym<…> variants. Parse 'true', 'false', and also 'unknown' (which is neither), printing whether each succeeded.

Example

The program prints:

True
True
False

Solution

See the solution

Course navigation

Solution: A number with proto   |   Solution: A boolean with proto