PGE::Match - implementation of PGE match objects


This file implements match objects returned by the Parrot Grammar Engine.

Functions ^

newfrom(PMC mob [, int from [, string grammar]])

Creates a new Match object, based on mob. If grammar is specified then the newly created object is an instance of that class, otherwise if isa mob, 'PGE::Match' then the new object is the same class as mob, otherwise the new object is a 'PGE::Match' object. The optional from parameter says how to initialize the $.from attribute of the new object if it can't start from the current position of mob.

Methods ^

new(PMC src, [ PMC adverbs :slurpy :named ])

Creates a new Match object based on src. If the grammar adverb is specified, then the new Match object is of the given grammar class, otherwise if src is an instance of Match (or a subclass) then that class is used to create the object, otherwise it uses the class of the invocant.

The pos, p, continue, or c adverbs specify where the match object should begin. If no starting position is given, the current position of src is used if it has one, otherwise the start position is at offset zero. The from adverb can be used to initialize the Match's $.from attribute to a value other than the starting position.

The rw adverb causes the invocant to be modified and returned instead of creating a new Match object.

The new method returns several values to the caller: the initialized match object, the target the object is matching against, a reference to its $.from attribute, a reference to its $.pos attribute, the value of pos/p/continue/c used to initialize the object, and whether or not a continue flag is set or implied.


Tell a Match object to continue the previous match from where it left off.

from([int pos])

Returns or sets the offset in the target string of the first item this object matched.

to([int pos])

Returns or sets the offset at the end of this match.


Returns the portion of the target string matched by this object.

value([pmc value])

Returns or sets the "return value" for the match object. If no return value has been explicitly set (by an embedded closure), return the substring that was matched by this match object.

_failcut(int cutvalue)

Immediately "fail" this Match object, removing any captured entities and coroutine continuation. Set the position of the match object to cutvalue.


Returns 1 if this object successfully matched the target string, 0 otherwise.


Returns the integer value of this match.


Returns the numeric value of this match.


Returns the portion of the target string matched by this object.

__get_string_keyed_int(int key)

Returns the portion of the target string matched by key, in string context. If the Match object contains an array of matches, a space seperated list of matches is returned.

__get_pmc_keyed_int(int key)

Returns the subpattern capture associated with key. This returns either a single Match object or an array of match objects depending on the rule.


Returns the hash component of the match object.


Returns the array component of the match object.


Patrick Michaud ( is the author and maintainer. Patches and suggestions should be sent to the Perl 6 compiler list (