X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlreapi.pod;h=03996fd51edc9d863548ad968a638f992f921828;hb=6d1e6673d7386f4f9139111a6e44d555b8252741;hp=2ac4c164b54997de54796bed6d2b3d88b81c95d8;hpb=192b9cd13b3ba000f1d0a2d32c141b9513be7936;p=p5sagit%2Fp5-mst-13.2.git
diff --git a/pod/perlreapi.pod b/pod/perlreapi.pod
index 2ac4c16..03996fd 100644
--- a/pod/perlreapi.pod
+++ b/pod/perlreapi.pod
@@ -4,9 +4,11 @@ perlreapi - perl regular expression plugin interface
=head1 DESCRIPTION
-As of Perl 5.9.5 there is a new interface for using other regexp engines than
-the default one. Each engine is supposed to provide access to a constant
-structure of the following format:
+As of Perl 5.9.5 there is a new interface for plugging and using other
+regular expression engines than the default one.
+
+Each engine is supposed to provide access to a constant structure of the
+following format:
typedef struct regexp_engine {
REGEXP* (*comp) (pTHX_ const SV * const pattern, const U32 flags);
@@ -34,7 +36,7 @@ structure of the following format:
#endif
When a regexp is compiled, its C field is then set to point at
-the appropriate structure so that when it needs to be used Perl can find
+the appropriate structure, so that when it needs to be used Perl can find
the right routines to do so.
In order to install a new regexp handler, C<$^H{regcomp}> is set
@@ -61,7 +63,7 @@ the individual fields in the REGEXP struct.
The C parameter is the scalar that was used as the
pattern. previous versions of perl would pass two C indicating
-the start and end of the stringifed pattern, the following snippet can
+the start and end of the stringified pattern, the following snippet can
be used to get the old parameters:
STRLEN plen;
@@ -75,81 +77,130 @@ expression (C<< "ook" =~ qr/eek/ >>). perl's own engine will always
stringify everything using the snippet above but that doesn't mean
other engines have to.
-The C paramater is a bitfield which indicates which of the
-C flags the regex was compiled with. In addition it contains
-info about whether C
- RXf_PMf_KEEPCOPY
+
+=back
+
+Additional flags:
+
+=over 4
=item RXf_PMf_LOCALE
-Makes C use the locale dependant definition of whitespace under C when RXf_SKIPWHITE or RXf_WHITE is in effect. Under ASCII whitespace is
-defined as per L, and by the internal macros
-C under UTF-8 and C under C.
+Set if C is in effect. If present in C<< rx->extflags >>
+C will use the locale dependent definition of whitespace under
+when RXf_SKIPWHITE or RXf_WHITE are in effect. Under ASCII whitespace
+is defined as per L, and by the internal
+macros C under UTF-8 and C under C.
-=item RXf_PMf_MULTILINE
+=item RXf_UTF8
-The C flag, this ends up being passed to C by
-C regardless of the engine.
+Set if the pattern is L, set by Perl_pmruntime.
-=item RXf_PMf_SINGLELINE
+A regex engine may want to set or disable this flag during
+compilation. The perl engine for instance may upgrade non-UTF-8
+strings to UTF-8 if the pattern includes constructs such as C<\x{...}>
+that can only match Unicode values.
-The C flag. Guaranteed not to be used outside the regex engine.
+=item RXf_SPLIT
-=item RXf_PMf_FOLD
+If C is invoked as C or with no arguments (which
+really means C, see L), perl will
+set this flag. The regex engine can then check for it and set the
+SKIPWHITE and WHITE extflags. To do this the perl engine does:
-The C flag. Guaranteed not to be used outside the regex engine.
+ if (flags & RXf_SPLIT && r->prelen == 1 && r->precomp[0] == ' ')
+ r->extflags |= (RXf_SKIPWHITE|RXf_WHITE);
-=item RXf_PMf_EXTENDED
+=back
-The C flag. Guaranteed not to be used outside the regex
-engine. However if present on a regex C<#> comments will be stripped
-by the tokenizer regardless of the engine currently in use.
+These flags can be set during compilation to enable optimizations in
+the C operator.
-=item RXf_PMf_KEEPCOPY
+=over 4
-The C flag.
+=item RXf_SKIPWHITE
-=item RXf_UTF8
+If the flag is present in C<< rx->extflags >> C will delete
+whitespace from the start of the subject string before it's operated
+on. What is considered whitespace depends on whether the subject is a
+UTF-8 string and whether the C flag is set.
-Set if the pattern is L, set by Perl_pmruntime.
+If RXf_WHITE is set in addition to this flag C will behave like
+C under the perl engine.
-=back
+=item RXf_START_ONLY
+
+Tells the split operator to split the target string on newlines
+(C<\n>) without invoking the regex engine.
+
+Perl's engine sets this if the pattern is C^/> (C), even under C^/s>, see L. Of course a
+different regex engine might want to use the same optimizations
+with a different syntax.
+
+=item RXf_WHITE
+
+Tells the split operator to split the target string on whitespace
+without invoking the regex engine. The definition of whitespace varies
+depending on whether the target string is a UTF-8 string and on
+whether RXf_PMf_LOCALE is set.
-In general these flags should be preserved in C<< rx->extflags >>
-after compilation, although it is possible the regex includes
-constructs that changes them. The perl engine for instance may upgrade
-non-utf8 strings to utf8 if the pattern includes constructs such as
-C<\x{...}> that can only match unicode values. RXf_SKIPWHITE should
-always be preserved verbatim in C<< regex->extflags >>.
+Perl's engine sets this flag if the pattern is C<\s+>.
+
+=item RXf_NULL
+
+Tells the split operator to split the target string on
+characters. The definition of character varies depending on whether
+the target string is a UTF-8 string.
+
+Perl's engine sets this flag on empty patterns, this optimization
+makes C much faster than it would otherwise be. It's even
+faster than C.
+
+=back
=head2 exec
@@ -194,7 +245,7 @@ Called to get/set the value of C<$`>, C<$'>, C<$&> and their named
equivalents, ${^PREMATCH}, ${^POSTMATCH} and $^{MATCH}, as well as the
numbered capture buffers (C<$1>, C<$2>, ...).
-The C paramater will be C<-2> for C<$`>, C<-1> for C<$'>, C<0>
+The C parameter will be C<-2> for C<$`>, C<-1> for C<$'>, C<0>
for C<$&>, C<1> for C<$1> and so forth.
The names have been chosen by analogy with L methods
@@ -215,7 +266,7 @@ redundant. The scalar can be set with C, C and
friends, see L.
This callback is where perl untaints its own capture variables under
-taint mode (see L). See the C
+taint mode (see L). See the C
function in F for how to untaint capture variables if
that's something you'd like your engine to do as well.
@@ -236,7 +287,7 @@ Example:
}
Perl's own engine will croak on any attempt to modify the capture
-variables, to do this in another engine use the following callack
+variables, to do this in another engine use the following callback
(copied from C):
void
@@ -251,7 +302,7 @@ variables, to do this in another engine use the following callack
Perl_croak(aTHX_ PL_no_modify);
}
-Actually perl 5.10 will not I croak in a statement that looks
+Actually perl will not I croak in a statement that looks
like it would modify a numbered capture variable. This is because the
STORE callback will not be called if perl can determine that it
doesn't have to modify the value. This is exactly how tied variables
@@ -283,7 +334,7 @@ just die when assigned to in the default engine.
Get the C of a capture variable. There's a special callback
for this so that perl doesn't have to do a FETCH and run C on
the result, since the length is (in perl's case) known from an offset
-stored in C<offs> this is much more efficient:
+stored in C<< rx->offs >> this is much more efficient:
I32 s1 = rx->offs[paren].start;
I32 s2 = rx->offs[paren].end;
@@ -310,27 +361,27 @@ currently defined:
Which L operation is being performed from the Perl level on
C<%+> or C<%+>, if any:
- RXf_HASH_FETCH
- RXf_HASH_STORE
- RXf_HASH_DELETE
- RXf_HASH_CLEAR
- RXf_HASH_EXISTS
- RXf_HASH_SCALAR
- RXf_HASH_FIRSTKEY
- RXf_HASH_NEXTKEY
+ RXapif_FETCH
+ RXapif_STORE
+ RXapif_DELETE
+ RXapif_CLEAR
+ RXapif_EXISTS
+ RXapif_SCALAR
+ RXapif_FIRSTKEY
+ RXapif_NEXTKEY
Whether C<%+> or C<%-> is being operated on, if any.
- RXf_HASH_ONE /* %+ */
- RXf_HASH_ALL /* %- */
+ RXapif_ONE /* %+ */
+ RXapif_ALL /* %- */
Whether this is being called as C, C or
-C, if any. The first two will be combined with
-C or C.
+C, if any. The first two will be combined with
+C or C.
- RXf_HASH_REGNAME
- RXf_HASH_REGNAMES
- RXf_HASH_REGNAMES_COUNT
+ RXapif_REGNAME
+ RXapif_REGNAMES
+ RXapif_REGNAMES_COUNT
Internally C<%+> and C<%-> are implemented with a real tied interface
via L. The methods in that package will call
@@ -378,34 +429,24 @@ package as a normal object.
my $re = qr//;
$re->meth; # dispatched to re::engine::Example::meth()
-To retrieve the C object from the scalar in an XS function use the
-following snippet:
+To retrieve the C object from the scalar in an XS function use
+the C macro, see L<"REGEXP Functions" in perlapi|perlapi/REGEXP
+Functions>.
void meth(SV * rv)
PPCODE:
- MAGIC * mg;
- REGEXP * re;
-
- if (SvMAGICAL(sv))
- mg_get(sv);
- if (SvROK(sv) &&
- (sv = (SV*)SvRV(sv)) && /* assignment deliberate */
- SvTYPE(sv) == SVt_PVMG &&
- (mg = mg_find(sv, PERL_MAGIC_qr))) /* assignment deliberate */
- {
- re = (REGEXP *)mg->mg_obj;
- }
+ REGEXP * re = SvRX(sv);
=head2 dupe
void* dupe(pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
On threaded builds a regexp may need to be duplicated so that the pattern
-can be used by mutiple threads. This routine is expected to handle the
+can be used by multiple threads. This routine is expected to handle the
duplication of any private data pointed to by the C member of
the regexp structure. It will be called with the preconstructed new
regexp structure as an argument, the C member will point at
-the B private structue, and it is this routine's responsibility to
+the B private structure, and it is this routine's responsibility to
construct a copy and return a pointer to it (which perl will then use to
overwrite the field as passed to this routine.)
@@ -472,7 +513,6 @@ values.
I32 prelen; /* length of precomp */
const char *precomp; /* pre-compilation regular expression */
- /* wrapped can't be const char*, as it is returned by sv_2pv_flags */
char *wrapped; /* wrapped version of the pattern */
I32 wraplen; /* length of wrapped */
@@ -504,7 +544,8 @@ TODO, see L
This will be used by perl to see what flags the regexp was compiled
with, this will normally be set to the value of the flags parameter by
-the L callback.
+the L callback. See the L documentation for
+valid flags.
=head2 C C
@@ -525,7 +566,7 @@ following pattern:
where the C would be 3 but C would only be 2 as the \d is
required to match but is not actually included in the matched content. This
distinction is particularly important as the substitution logic uses the
-C to tell whether it can do in-place substition which can result in
+C to tell whether it can do in-place substitution which can result in
considerable speedup.
=head2 C
@@ -536,7 +577,7 @@ Left offset from pos() to start match at.
Substring data about strings that must appear in the final match. This
is currently only used internally by perl's engine for but might be
-used in the future for all engines for optimisations like C.
+used in the future for all engines for optimisations.
=head2 C, C, and C
@@ -557,7 +598,7 @@ engine should use something else.
=head2 C
-TODO: document
+Unused. Left in for compatibility with perl 5.10.0.
=head2 C
@@ -599,7 +640,7 @@ pv being an embedded array of I32. The values may also be contained
independently in the data array in cases where named backreferences are
used.
-=head2 C
+=head2 C
Holds information on the longest string that must occur at a fixed
offset from the start of the pattern, and the longest string that must
@@ -609,25 +650,17 @@ the regex engine at all, and if so where in the string to search.
=head2 C C C
- #define SAVEPVN(p,n) ((p) ? savepvn(p,n) : NULL)
- if (RX_MATCH_COPIED(ret))
- ret->subbeg = SAVEPVN(ret->subbeg, ret->sublen);
- else
- ret->subbeg = NULL;
-
-Cextflags & RXf_PMf_KEEPCOPY>
-
-These are used during execution phase for managing search and replace
-patterns.
+Used during execution phase for managing search and replace patterns.
=head2 C C
-Stores the string C stringifies to, for example C<(?-xism:eek)>
-in the case of C.
+Stores the string C stringifies to. The perl engine for example
+stores C<(?-xism:eek)> in the case of C.
-When using a custom engine that doesn't support the C<(?:)> construct for
-inline modifiers it's best to have C stringify to the supplied pattern,
-note that this will create invalid patterns in cases such as:
+When using a custom engine that doesn't support the C<(?:)> construct
+for inline modifiers, it's probably best to have C stringify to
+the supplied pattern, note that this will create undesired patterns in
+cases such as:
my $x = qr/a|b/; # "a|b"
my $y = qr/c/i; # "c"
@@ -636,8 +669,6 @@ note that this will create invalid patterns in cases such as:
There's no solution for this problem other than making the custom
engine understand a construct like C<(?:)>.
-The C in F does the stringification work.
-
=head2 C
This stores the number of eval groups in the pattern. This is used for security