This page was generated by Text::SmartLinks v0.01 at 2014-12-22 22:18:05 GMT.
(syn 213ff41)
  [ Index of Synopses ]

TITLE

DRAFT: Synopsis 32: Setting Library - Rules

VERSION

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

The document is a draft.

Overview

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

Classes

Regex

    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.

Match

    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()            {...}
    }

Cursor

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

Grammar

    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 $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.

parsefile
    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

AUTHORS

    Tim Nelson <wayland@wayland.id.au>
    Larry Wall <larry@wall.org>
    Brent Laabs <bslaabs@gmail.com>
[ Top ]   [ Index of Synopses ]