Matt S Trout > Rakudo-Star-2012.08_001 > Regex


Annotate this POD



Regex - Regex library


This file brings together the various Regex modules needed for Regex.pbc .


Regex::Cursor - Regex Cursor nodes


This file implements the Regex::Cursor class, used for managing regular expression control flow. Regex::Cursor is also a base class for grammars.



A method that creates an empty Match object, by default of type Regex::Match. This method can be overridden for generating HLL-specific Match objects.


A method that creates an empty array object, by default of type ResizablePMCArray. This method can be overridden for generating HLL-specific arrays for usage within Match objects.


Return this cursor's current Match object, generating a new one for the Cursor if one hasn't been created yet.

parse(target [, 'rule'=>regex])

Parse target in the current grammar starting with regex. If regex is omitted, then use the TOP rule for the grammar.


Return the next match from a successful Cursor.


Return the cursor's current position.


Return the cursor's from position.

Private methods


Create a new cursor for matching target.


Create and initialize a new cursor from self. If lang is provided, then the new cursor has the same type as lang.


Permanently fail this cursor.

!cursor_pass(pos, name)

Set the Cursor as passing at pos; calling any reduction action name associated with the cursor. This method simply sets $!match to a boolean true value to indicate the regex was successful; the MATCH method above replaces this boolean true with a "real" Match object when requested.


Configure this cursor for backtracking via !cursor_next.


Continue a regex match from where the current cursor left off.

!cursor_caparray(caparray :slurpy)

Set the list of subcaptures that produce arrays to caparray.


Set the Cursor's name (for binding) to names.


Set the cursor's position to pos.

!cursor_debug(args :slurpy)

Log a debug message.

!mark_push(rep, pos, mark)

Push a new backtracking point onto the cursor with the given rep, pos, and backtracking mark. (The mark is typically the address of a label to branch to when backtracking occurs.)


Return information about the latest frame for mark. If mark is zero, return information about the latest frame.


Remove the most recent mark and backtrack the cursor to the point given by that mark. If mark is zero, then backtracks the most recent mark. Returns the backtracked values of repetition count, cursor position, and mark (address).


Like !mark_fail above this backtracks the cursor to mark (releasing any intermediate marks), but preserves the current capture states.

!reduce(name [, key] [, match])

Perform any action associated with the current regex match.


Match the backreference given by name.

!INTERPOLATE(var [, convert])

Perform regex interpolation on var. If var is a regex (sub), it is used directly, otherwise it is used for a string literal match. If var is an array, then all of the elements of var are considered, and the longest match is returned.


Same as !INTERPOLATE above, except that any non-regex values are first compiled to regexes prior to being matched.

Vtable functions



Patrick Michaud <> is the author and maintainer.


Regex::Cursor-builtins - builtin regexes for Cursor objects


Patrick Michaud <> is the author and maintainer.


Regex::Cursor-protoregex-peek - simple protoregex implementation



Perform a match for protoregex name.


Reset the $!generation flag to indicate that protoregexes need to be recalculated (because new protoregexes have been added).


Return the token list for protoregex name. If the list doesn't already exist, or if the existing list is stale, create a new one and return it.


Generate a new protoregex table for parrotclass. This involves creating a hash keyed with method names containing ':sym<' from parrotclass and all of its superclasses. This new hash is then given the current $!generate property so we can avoid recreating it on future calls.


Return the set of initial tokens for protoregex name. These are conveniently available as the keys of the tokrx hash.


Regex::Match - Regex Match objects


This file implements Match objects for the regex engine.



Returns the Cursor associated with this match object.


Returns the offset in the target string of the beginning of the match.


Returns the offset in the target string of the end of the match.


Returns .to() - .from()


Return the original item that was matched against.


Returns the portion of the target corresponding to this match.


Returns the "abstract object" for the Match; if no abstract object has been set then returns Str above.

Vtable functions


Returns 1 (true) if this is the result of a successful match, otherwise returns 0 (false).


Returns the integer value of the matched text.


Returns the numeric value of this match


Returns the string value of the match


Set the "ast object" for the invocant.


Patrick Michaud <> is the author and maintainer.


Regex::Regex, Regex::Method - Regex subs


This file implements the Regex::Method and Regex::Regex types, used as containers for Regex subs that need .ACCEPTS and other regex attributes.



Create a new Regex::Regex object from sub.


Perform a match against target, return the result.


Patrick Michaud <> is the author and maintainer.


Regex::Dumper - various methods for displaying Match structures

Regex::Match Methods

__dump(PMC dumper, STR label)

This method enables Data::Dumper to work on Regex::Match objects.


An alternate dump output for a Match object and all of its subcaptures.


PAST::Regex - Regex nodes for PAST


This file implements the various abstract syntax tree nodes for regular expressions.


Returns the prefixes associated with the regex tree rooted at this node.


Patrick Michaud <> is the author and maintainer. Please send patches and suggestions to the Parrot porters or Perl 6 compilers mailing lists.


Copyright (C) 2009, The Perl Foundation.


PAST::Compiler-Regex - Compiler for PAST::Regex nodes


PAST::Compiler-Regex implements the transformations to convert PAST::Regex nodes into POST. It's still a part of PAST::Compiler; we've separated out the regex-specific transformations here for better code management and debugging.

Compiler methods


as_post(PAST::Regex node)

Return the POST representation of the regex AST rooted by node.

!cursorop(ops, func, retelems, arg :slurpy)

Helper function to push POST nodes onto ops that perform func on the regex's current cursor. By default this ends up being a method call on the cursor, but some values of func can result in inlined code to perform the equivalent operation without using the method call.

The retelems argument is the number of elements in arg that represent return values from the function; any remaining elements in arg are passed to the function as input arguments.


Helper function -- looks up the current regex register table in the dynamic scope and returns a slice based on the keys given in keystr.

post_regex(PAST::Regex node)

Return the POST representation of the regex component given by node. Normally this is handled by redispatching to a method corresponding to the node's "pasttype" and "backtrack" attributes. If no "pasttype" is given, then "concat" is assumed.

alt(PAST::Regex node)
alt_longest(PAST::Regex node)

Same as 'alt' above, but use declarative/LTM semantics. (Currently we cheat and just use 'alt' above.)

anchor(PAST::Regex node)

Match various anchor points, including ^, ^^, $, $$.

charclass(PAST::Regex node)

Match something in a character class, such as \w, \d, \s, dot, etc.

!charclass_init(PAST::Regex node)

Return the subtype, cclass value, and negation for a charclass node.

charclass_q(PAST::Regex node)

Optimize certain quantified character class shortcuts, if it makes sense to do so. If not, return a null PMC and the standard quantifier code will handle it.

concat(PAST::Regex node)

Handle a concatenation of regexes.

conj(PAST::Regex node)
cut(PAST::Regex node)

Generate POST for the cut-group and cut-rule operators.

enumcharlist(PAST::Regex node)

Generate POST for matching a character from an enumerated character list.

literal(PAST::Regex node)

Generate POST for matching a literal string provided as the second child of this node.

'pastnode'(PAST::Regex node)
pass(PAST::Regex node)
quant(PAST::Regex node)

Code for initial regex scan.

subcapture(PAST::Regex node)

Perform a subcapture (capture of a portion of a regex).

subrule(PAST::Regex node)

Perform a subrule call.

post_new(type, args :slurpy, options :slurpy :named)

Helper method to create a new POST node of type.

??!!(test, trueval, falseval)

Helper method to perform ternary operation -- returns trueval if test is true, falseval otherwise.


Patrick Michaud <> is the author and maintainer.


Copyright (C) 2009, The Perl Foundation.


Patrick Michaud <> is the author and maintainer.


Copyright (C) 2009, The Perl Foundation.

syntax highlighting: