parrotcode: implementation of character class vtables | |
Contents | Libraries |
PGE::Class - implementation of character class vtables
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.
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:
Returns 1 if char is in the character class, 0 if not. The behavior is undefined if char is more than one character long. This is just a named proxy to the get_integer_keyed vtable slot.
Finds the first character in source that matches the character class and returns its offset. The optional offset argument tells the method where to start looking.
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".
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)
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.
|