This page was generated by Text::SmartLinks v0.01 at 2014-08-27 17:01:07 GMT.
(syn 6989f5a)
  [ Index of Synopses ]


DRAFT: Synopsis 32: Setting Library - Rules


    Tim Nelson <>
    Larry Wall <>
    Brent Laabs <>


    Created: 27 Feb 2009
    Last Modified: 5 Jul 2013
    Version: 2

The document is a draft.

If you read the HTML version, it is generated from the Pod in the specs repository under so edit it there in the git repository if you would like to make changes.


This synopsis deals with objects produced by the regexes and grammars described in much greater detail in S05.



    class Regex is Method {...}

Regex objects are created through the syntax described in S05:

    / ... /
    rx/ ... /
    regex { ... }

They can be stored in variables for later use, as with the qr// syntax in Perl 5.

method Bool(Regex:D: )

In boolean context, a regex object will match against $_, and return the result as a Bool.


    class Match is Cool does Positional does Associative {
        method from( --> Int )  {...}
        method to( --> Int )    {...}
        method chars( --> Int ) {...}
        method orig()           {...}
        method ast()            {...}
        method caps()           {...}
        method chunks()         {...}
        method pos()            {...}
        method bool()           {...}
        method Str()            {...}
        method Num()            {...}
        method ast()            {...}


    class Cursor {
        method pos( --> Int ) {...}
        method orig() {...}


    class Grammar is Cursor

Much as a class is a collection of named attributes and methods, a grammar is a collection of named regexes and rules. For more on creating and using grammars, see "Grammars" in S05.

parse / subparse
    method parse ($target, :$rule = 'TOP', Mu :$actions = Mu, *%opts)
    method subparse ($target, :$rule = 'TOP', Mu :$actions = Mu, *%opts)

Parses the the $target string with given <:rule>, and returns the result as a Match object. Defaults to the TOP rule. A class containing actions may be attached using the actions named argument.

The parse method automatically anchors the rule to the beginning and end of the target string (adding ^ and $ around the rule). The subparse method does not add anchors, and will match substrings against the rule.

    method parsefile (Cool $filename, :$rule = 'TOP', Mu :$actions = Mu, *%opts)

Parse the file as with .parse, but matches the grammar against the contents of $filename instead.

See Abstractions.pod


Please post errors and feedback to perl6-language. If you are making a general laundry list, please separate messages by topic.

[ Top ]   [ Index of Synopses ]