NAME ^

PGE::Class - implementation of character class vtables

DESCRIPTION ^

This file implements objects that represent character class atoms. The design is a simple vtable design, so that we can add unicode trait classes and such when we find out how.

Yes, it is all in PIR. And yes, this is a speed-critical part of PGE. Don't complain; it's designed so that you can drop in a faster implementation any time. Just replace these classes with PMCs.

There's also something to be said for adding an optimizer at some point. The number of tests could get expensive for complex classes, so an optimizer would walk the logic tree and replace it with a direct lookup or something.

PGE::Class ^

This is an abstract base class for the atomic classes defined later in the file. It provides the following methods to all other classes defined here:

PGE::Class::Discrete ^

This class represents a discrete set of characters, such as [aeiou] (or <[aeiou]> in Perl 6-land). To use this class:

    # create the character class
    .local pmc new_sub
    .local pmc class
    find_global new_sub, "PGE::Class::Discrete", "new"
    class = new_sub("aeiou")

    # decide whether it matches a character
    .local int matches
    matches = class["x"]
    # or
    matches = class.matches("x")

Ranges ("a-m") are not supported. That means the three characters "a", "-", and "m".

PGE::Class::Invert ^

This class represents the logical inversion of another class. That is, it matches exactly when its child doesn't. To create this class:

    # create the character class
    .local pmc class
    .local pmc new_sub
    find_global new_sub, "PGE::Class::Invert", "new"
    class = new_sub(some_other_pge_class)

AUTHORS ^

Luke Palmer (luke@luqui.org) wrote this module. Patrick Michaud (pmichaud@pobox.com) engineered PGE as a whole. Questions about PGE should be directed to perl6-compiler@perl.org.


parrot