This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix a few perldelta nits
[perl5.git] / pod / perlreapi.pod
index 03996fd..1cef9c1 100644 (file)
@@ -34,6 +34,8 @@ following format:
     #ifdef USE_ITHREADS
         void*   (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
     #endif
+        REGEXP* (*op_comp) (...);
+
 
 When a regexp is compiled, its C<engine> field is then set to point at
 the appropriate structure, so that when it needs to be used Perl can find
@@ -120,29 +122,27 @@ TODO: Document those cases.
 
 =item C</p> - RXf_PMf_KEEPCOPY
 
-=back
+TODO: Document this
 
-Additional flags:
-
-=over 4
+=item Character set
 
-=item RXf_PMf_LOCALE
-
-Set if C<use locale> is in effect. If present in C<< rx->extflags >>
-C<split> 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<isSPACE|perlapi/ISSPACE>, and by the internal
-macros C<is_utf8_space> under UTF-8 and C<isSPACE_LC> under C<use
+The character set semantics are determined by an enum that is contained
+in this field.  This is still experimental and subject to change, but
+the current interface returns the rules by use of the in-line function
+C<get_regex_charset(const U32 flags)>.  The only currently documented
+value returned from it is REGEX_LOCALE_CHARSET, which is set if
+C<use locale> is in effect. If present in C<< rx->extflags >>,
+C<split> will use the locale dependent definition of whitespace
+when RXf_SKIPWHITE or RXf_WHITE is in effect. ASCII whitespace
+is defined as per L<isSPACE|perlapi/isSPACE>, and by the internal
+macros C<is_utf8_space> under UTF-8, and C<isSPACE_LC> under C<use
 locale>.
 
-=item RXf_UTF8
+=back
 
-Set if the pattern is L<SvUTF8()|perlapi/SvUTF8>, set by Perl_pmruntime.
+Additional flags:
 
-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.
+=over 4
 
 =item RXf_SPLIT
 
@@ -209,7 +209,49 @@ faster than C<unpack>.
              I32 minend, SV* screamer,
              void* data, U32 flags);
 
-Execute a regexp.
+Execute a regexp. The arguments are
+
+=over 4
+
+=item rx
+
+The regular expression to execute.
+
+=item screamer
+
+This strangely-named arg is the SV to be matched against. Note that the
+actual char array to be matched against is supplied by the arguments
+described below; the SV is just used to determine UTF8ness, C<pos()> etc.
+
+=item strbeg
+
+Pointer to the physical start of the string.
+
+=item strend
+
+Pointer to the character following the physical end of the string (i.e.
+the \0).
+
+=item stringarg
+
+Pointer to the position in the string where matching should start; it might
+not be equal to C<strbeg> (for example in a later iteration of C</.../g>).
+
+=item minend
+
+Minimum length of string (measured in bytes from C<stringarg>) that must
+match; if the engine reaches the end of the match but hasn't reached this
+position in the string, it should fail.
+
+=item data
+
+Optimisation data; subject to change.
+
+=item flags
+
+Optimisation flags; subject to change.
+
+=back
 
 =head2 intuit
 
@@ -243,10 +285,21 @@ perl will handle releasing anything else contained in the regexp structure.
 
 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>, ...).
+numbered capture groups (C<$1>, C<$2>, ...).
+
+The C<paren> parameter will be C<1> for C<$1>, C<2> for C<$2> and so
+forth, and have these symbolic values for the special variables:
+
+    ${^PREMATCH}  RX_BUFF_IDX_CARET_PREMATCH
+    ${^POSTMATCH} RX_BUFF_IDX_CARET_POSTMATCH
+    ${^MATCH}     RX_BUFF_IDX_CARET_FULLMATCH
+    $`            RX_BUFF_IDX_PREMATCH
+    $'            RX_BUFF_IDX_POSTMATCH
+    $&            RX_BUFF_IDX_FULLMATCH
+
+Note that in perl 5.17.3 and earlier, the last three constants were also
+used for the caret variants of the variables.
 
-The C<paren> 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<Tie::Scalar> methods
 names with an additional B<LENGTH> callback for efficiency. However
@@ -282,7 +335,7 @@ sure this is used as the new value (or reject it).
 Example:
 
     if ("ook" =~ /(o*)/) {
-        # `paren' will be `1' and `value' will be `ee'
+        # 'paren' will be '1' and 'value' will be 'ee'
         $1 =~ tr/o/e/;
     }
 
@@ -317,7 +370,7 @@ behave in the same situation:
 
     package main;
 
-    tie my $sv => "CatptureVar";
+    tie my $sv => "CaptureVar";
     $sv =~ y/a/b/;
 
 Because C<$sv> is C<undef> when the C<y///> operator is applied to it
@@ -410,7 +463,7 @@ name for identification regardless of whether they implement methods
 on the object.
 
 The package this method returns should also have the internal
-C<Regexp> package in its C<@ISA>. C<qr//->isa("Regexp")> should always
+C<Regexp> package in its C<@ISA>. C<< qr//->isa("Regexp") >> should always
 be true regardless of what engine is being used.
 
 Example implementation might be:
@@ -455,6 +508,11 @@ modify the final structure if it really must.
 
 On unthreaded builds this field doesn't exist.
 
+=head2 op_comp
+
+This is private to the perl core and subject to change. Should be left
+null.
+
 =head1 The REGEXP structure
 
 The REGEXP struct is defined in F<regexp.h>. All regex engines must be able to
@@ -492,7 +550,7 @@ values.
            in the final match, used for optimisations */
         struct reg_substr_data *substrs;
 
-        U32 nparens;  /* number of capture buffers */
+        U32 nparens;  /* number of capture groups */
 
         /* private engine specific data */
         U32 intflags;   /* Engine Specific Internal flags */
@@ -500,14 +558,16 @@ values.
                            created this object. */
 
         /* Data about the last/current match. These are modified during matching*/
-        U32 lastparen;            /* last open paren matched */
-        U32 lastcloseparen;       /* last close paren matched */
+        U32 lastparen;            /* highest close paren matched ($+) */
+        U32 lastcloseparen;       /* last close paren matched ($^N) */
         regexp_paren_pair *swap;  /* Swap copy of *offs */
         regexp_paren_pair *offs;  /* Array of offsets for (@-) and (@+) */
 
         char *subbeg;  /* saved or original string so \digit works forever. */
         SV_SAVED_COPY  /* If non-NULL, SV which is COW from original */
         I32 sublen;    /* Length of string pointed by subbeg */
+       I32 suboffset;  /* byte offset of subbeg from logical start of str */
+       I32 subcoffset; /* suboffset equiv, but in chars (for @-/@+) */
 
         /* Information about the match that isn't often used */
         I32 prelen;           /* length of precomp */
@@ -579,7 +639,7 @@ 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.
 
-=head2 C<nparens>, C<lasparen>, and C<lastcloseparen>
+=head2 C<nparens>, C<lastparen>, and C<lastcloseparen>
 
 These fields are used to keep track of how many paren groups could be matched
 in the pattern, which was the last open paren to be entered, and which was
@@ -612,8 +672,8 @@ C<regexp_paren_pair> struct is defined as follows:
     } regexp_paren_pair;
 
 If C<< ->offs[num].start >> or C<< ->offs[num].end >> is C<-1> then that
-capture buffer did not match. C<< ->offs[0].start/end >> represents C<$&> (or
-C<${^MATCH> under C<//p>) and C<< ->offs[paren].end >> matches C<$$paren> where
+capture group did not match. C<< ->offs[0].start/end >> represents C<$&> (or
+C<${^MATCH}> under C<//p>) and C<< ->offs[paren].end >> matches C<$$paren> where
 C<$paren >= 1>.
 
 =head2 C<precomp> C<prelen>
@@ -633,7 +693,7 @@ The relevant snippet from C<Perl_pp_regcomp>:
 
 =head2 C<paren_names>
 
-This is a hash used internally to track named capture buffers and their
+This is a hash used internally to track named capture groups and their
 offsets. The keys are the names of the buffers the values are dualvars,
 with the IV slot holding the number of buffers with the given name and the
 pv being an embedded array of I32.  The values may also be contained
@@ -648,14 +708,28 @@ occur at a floating offset from the start of the pattern. Used to do
 Fast-Boyer-Moore searches on the string to find out if its worth using
 the regex engine at all, and if so where in the string to search.
 
-=head2 C<subbeg> C<sublen> C<saved_copy>
+=head2 C<subbeg> C<sublen> C<saved_copy> C<suboffset> C<subcoffset>
+
+Used during the execution phase for managing search and replace patterns,
+and for providing the text for C<$&>, C<$1> etc. C<subbeg> points to a
+buffer (either the original string, or a copy in the case of
+C<RX_MATCH_COPIED(rx)>), and C<sublen> is the length of the buffer.  The
+C<RX_OFFS> start and end indices index into this buffer.
 
-Used during execution phase for managing search and replace patterns.
+In the presence of the C<REXEC_COPY_STR> flag, but with the addition of
+the C<REXEC_COPY_SKIP_PRE> or C<REXEC_COPY_SKIP_POST> flags, an engine
+can choose not to copy the full buffer (although it must still do so in
+the presence of C<RXf_PMf_KEEPCOPY> or the relevant bits being set in
+C<PL_sawampersand>). In this case, it may set C<suboffset> to indicate the
+number of bytes from the logical start of the buffer to the physical start
+(i.e. C<subbeg>). It should also set C<subcoffset>, the number of
+characters in the offset. The latter is needed to support C<@-> and C<@+>
+which work in characters, not bytes.
 
 =head2 C<wrapped> C<wraplen>
 
 Stores the string C<qr//> stringifies to. The perl engine for example
-stores C<(?-xism:eek)> in the case of C<qr/eek/>.
+stores C<(?^:eek)> in the case of C<qr/eek/>.
 
 When using a custom engine that doesn't support the C<(?:)> construct
 for inline modifiers, it's probably best to have C<qr//> stringify to