NAME
YAPE::Regex - Yet Another Parser/Extractor for Regular Expressions
SYNOPSIS
use YAPE::Regex;
use strict;
my $regex = qr/reg(ular\s+)?exp?(ression)?/i;
my $parser = YAPE::Regex->new($regex);
# here is the tokenizing part
while (my $chunk = $parser->next) {
# ...
}
`YAPE' MODULES
The `YAPE' hierarchy of modules is an attempt at a unified means of parsing and extracting content. It attempts to maintain a generic interface, to promote simplicity and reusability. The API is powerful, yet simple. The modules do tokenization (which can be intercepted) and build trees, so that extraction of specific nodes is doable.
DESCRIPTION
This module is yet another (?) parser and tree-builder for Perl regular expressions. It builds a tree out of a regex, but at the moment, the extent of the extraction tool for the tree is quite limited (see the section on "Extracting Sections"). However, the tree can be useful to extension modules.
USAGE
In addition to the base class, `YAPE::Regex', there is the auxiliary class `YAPE::Regex::Element' (common to all `YAPE' base classes) that holds the individual nodes' classes. There is documentation for the node classes in that module's documentation.
Methods for `YAPE::Regex'
package MyExt::Mod;
use YAPE::Regex 'MyExt::Mod';
# does the work of:
# @MyExt::Mod::ISA = 'YAPE::Regex'
# @MyExt::Mod::text::ISA = 'YAPE::Regex::text'
# ...
For `capture(N)', N will be the number the captured
pattern represents.
For `cond(TYPE)', TYPE will either be a number
representing the back-reference that the conditional depends
on, or the string `assert'.
For `lookahead' and `lookbehind', one of `neg' and `pos'
will be there, depending on the type of assertion.
Extracting Sections
While extraction of nodes is the goal of the `YAPE' modules, the author is at a loss for words as to what needs to be extracted from a regex. At the current time, all the `extract' method does is allow you access to the regex's set of back-references:
my $extor = $parser->extract;
while (my $backref = $extor->()) {
# ...
}
`japhy' is very open to suggestions as to the approach to node extraction (in how the API should look, in addition to what should be proffered). Preliminary ideas include extraction keywords like the output of -Dr (or the `re' module's `debug' option).
EXTENSIONS
TO DO
This is a listing of things to add to future versions of this module.
API
BUGS
Following is a list of known or reported bugs.
Pending
SUPPORT
Visit `YAPE''s web site at http://www.pobox.com/~japhy/YAPE/.
SEE ALSO
The `YAPE::Regex::Element' documentation, for information on the node classes. Also, `Text::Balanced', Damian Conway's excellent module, used for the matching of `(?{ ... })' and `(??{ ... })' blocks.
AUTHOR
Jeff "japhy" Pinyan
CPAN ID: PINYAN
japhy@pobox.com
http://www.pobox.com/~japhy/