*** Welcome to piglix ***

Perl 6 rules


Perl 6 rules are the regular expression, string matching and general-purpose parsing facility of Perl 6, and are a core part of the language. Since Perl's pattern-matching constructs have exceeded the capabilities of formal regular expressions for some time, Perl 6 documentation refers to them exclusively as regexes, distancing the term from the formal definition.

Perl 6 provides a superset of Perl 5 features with respect to regexes, folding them into a larger framework called rules, which provide the capabilities of a parsing expression grammar, as well as acting as a closure with respect to their lexical scope. Rules are introduced with the rule keyword, which has a usage quite similar to subroutine definition. Anonymous rules can be introduced with the regex (or rx) keyword, or simply be used inline as regexps were in Perl 5 via the m (matching) or s (substitution) operators.

In Apocalypse 5, a document outlining the preliminary design decisions for Perl 6 pattern matching, Larry Wall enumerated 20 problems with "current regex culture". Among these were that Perl's regexes were "too compact and 'cute'", had "too much reliance on too few metacharacters", "little support for named captures", "little support for grammars", and "poor integration with [the] 'real' language".

Between late 2004 and mid-2005, a compiler for Perl 6 style rules was developed for the Parrot virtual machine called Parrot Grammar Engine (PGE), which was later renamed to the more generic, Parser Grammar Engine. PGE is a combination of runtime and compiler for Perl 6 style grammars that allows any parrot-based compiler to use these tools for parsing, and also to provide rules to their runtimes.

Among other Perl 6 features, support for named captures was added to Perl 5.10 in 2007.

In May 2012, the reference implementation of Perl 6, Rakudo, shipped its Rakudo Star monthly snapshot with a working JSON parser built entirely in Perl 6 rules.

There are only six unchanged features from Perl 5's regexes:


...
Wikipedia

...