parrotcode: MatchRange Numbers PMC Class | |
Contents | Dynamic PMCs |
src/dynpmc/matchrange.pmc - MatchRange Numbers PMC Class
MatchRange
provides a representation of regular expression matches,
by describing the starting and ending offsets within the input string.
This PMC only provides the start and end values; the Match PMC is responsible for interpreting these values appropriately (namely,
as a substring within the input string.)
This really probably shouldn't be a top-level class; it probably ought to inherit from "IntPair" or something like that. (But it can't just *be* "IntPair", because the Match PMC uses the type to figure out whether it has a regular variable or something that it needs to interpret as a string given its value and the input string.)
This PMC is used by the languages/regex rule compiler, together with the Match PMC.
static INTVAL *matchrange_locate_keyed_int(Interp *interp, PMC *self, STRING *key)
key
; valid keys are start
and end
,
representing the offsets of the first and last characters of the matching range.void class_init()
void class_init() {
/* class_init_code */
if (pass) {
MatchRange_type_id = entry;
}
}
void init()
void init_pmc(PMC *initializer)
void destroy()
PMC *clone()
INTVAL get_bool()
INTVAL get_integer_keyed(PMC *key)
INTVAL get_integer_keyed_str(STRING *key)
FLOATVAL get_number_keyed(PMC *key)
FLOATVAL get_number_keyed_str(STRING *key)
PMC *get_pmc_keyed(PMC *key)
PMC *get_pmc_keyed_str(STRING *key)
real
and imaginary for imag
).INTVAL get_integer_keyed_int(INTVAL key)
key = 0 ... get start offset
key = 1 ... get end offset
void set_integer_keyed_int(INTVAL key, INTVAL v)
INTVAL get_integer_keyed_int(INTVAL key) {
switch (key) {
case 0:
return RANGE_START(SELF);
case 1:
return RANGE_END(SELF);
default:
internal_exception(1, "MatchRange: key must be 0 or 1");
}
return -2;
}
void set_integer_keyed_int(INTVAL key, INTVAL v) {
switch (key) {
case 0:
RANGE_START(SELF) = v;
break;
case 1:
RANGE_END(SELF) = v;
break;
default:
internal_exception(1, "MatchRange: key must be 0 or 1");
}
}
/*
void set_pmc(PMC *value)
value
is a MatchRange PMC then the set the range indices to the same values; otherwise throw an exception. This really only makes sense if you're using a MatchRange from the same Match, or at least for the same input string, but I won't worry about that for now.void set_integer_keyed(PMC *key, INTVAL value)
void set_integer_keyed_str(STRING *key, INTVAL value)
void set_number_keyed(PMC *key, FLOATVAL value)
void set_number_keyed_str(STRING *key, FLOATVAL value)
void set_number_keyed_int(INTVAL key, FLOATVAL value)
void set_pmc_keyed(PMC *key, PMC *value)
void set_pmc_keyed_str(STRING *key, PMC *value)
start
and end offset for end
) to value
. For the keyed_int variants, 0 means RANGE_START, 1 means RANGE_END.PMC *add(PMC *value, PMC *dest)
PMC *add_int(INTVAL value, PMC *dest)
PMC *add_float(FLOATVAL value, PMC *dest)
value
to the ending offset of the match range, placing the result in dest
.PMC *subtract(PMC *value, PMC *dest)
PMC *subtract_int(INTVAL value, PMC *dest)
PMC *subtract_float(FLOATVAL value, PMC *dest)
value
from the ending offset of the match range, placing the result in dest
.INTVAL is_equal(PMC *value)
value
and returs true if they are equal.
|