Creating a grammar
Like regexes, grammars define some rules to extract information from given text. A typical application for regexes is finding fragments in text chunks and splitting them into meaningful pieces, for example, finding an email or checking if its format is correct. Grammars have a bigger goal—their task is often to read the whole text and understand all its content. For example, if a grammar is applied to a code source written in some programming language, the grammar must check its validity and create the syntax tree of the program. This difference is still a convention—grammars can parse small text sections just as regexes can be used for analyzing big text sections.
The syntax for grammars in Perl 6 is like defining a class. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access