Parsing with Perl 6 Regexes and Grammars by Moritz Lenz

Parsing with Perl 6 Regexes and Grammars by Moritz Lenz

Author:Moritz Lenz
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


Here the implicit <.ws> between a and b doesn’t match, so the rule as a whole does not match either.

8.3 8.3 Grammars

Named regexes offer a first level of abstraction, but we often want more than one level. Most high-level programming languages have modules, namespaces, classes, or even all three to manage reuse of functions and methods.

Perl 6 offers these higher-level abstractions too, and makes them available to regexes. A grammar is a class that offers some tools for invoking regexes. Regexes are then methods in this grammar:

grammar IPv4Address {

token byte {

\d ** 1..3

<?{ $/.Int <= 255 }>

}

token TOP {

<byte> ** 4 % '.'

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.