5 * "A fair jaw-cracker dwarf-language must be." --Samwise Gamgee
8 /* NOTE: this is derived from Henry Spencer's regexp code, and should not
9 * confused with the original package (see point 3 below). Thanks, Henry!
12 /* Additional note: this code is very heavily munged from Henry's version
13 * in places. In some spots I've traded clarity for efficiency, so don't
14 * blame Henry for some of the lack of readability.
17 /* The names of the functions have been changed from regcomp and
18 * regexec to pregcomp and pregexec in order to avoid conflicts
19 * with the POSIX routines of the same names.
22 #ifdef PERL_EXT_RE_BUILD
23 /* need to replace pregcomp et al, so enable that */
24 # ifndef PERL_IN_XSUB_RE
25 # define PERL_IN_XSUB_RE
27 /* need access to debugger hooks */
28 # if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
33 #ifdef PERL_IN_XSUB_RE
34 /* We *really* need to overwrite these symbols: */
35 # define Perl_pregcomp my_regcomp
36 # define Perl_regdump my_regdump
37 # define Perl_regprop my_regprop
38 # define Perl_pregfree my_regfree
39 # define Perl_re_intuit_string my_re_intuit_string
40 /* *These* symbols are masked to allow static link. */
41 # define Perl_regnext my_regnext
42 # define Perl_save_re_context my_save_re_context
43 # define Perl_reginitcolors my_reginitcolors
45 # define PERL_NO_GET_CONTEXT
50 * pregcomp and pregexec -- regsub and regerror are not used in perl
52 * Copyright (c) 1986 by University of Toronto.
53 * Written by Henry Spencer. Not derived from licensed software.
55 * Permission is granted to anyone to use this software for any
56 * purpose on any computer system, and to redistribute it freely,
57 * subject to the following restrictions:
59 * 1. The author is not responsible for the consequences of use of
60 * this software, no matter how awful, even if they arise
63 * 2. The origin of this software must not be misrepresented, either
64 * by explicit claim or by omission.
66 * 3. Altered versions must be plainly marked as such, and must not
67 * be misrepresented as being the original software.
70 **** Alterations to Henry's code are...
72 **** Copyright (c) 1991-2000, Larry Wall
74 **** You may distribute under the terms of either the GNU General Public
75 **** License or the Artistic License, as specified in the README file.
78 * Beware that some of this code is subtly aware of the way operator
79 * precedence is structured in regular expressions. Serious changes in
80 * regular-expression syntax might require a total rethink.
83 #define PERL_IN_REGCOMP_C
86 #ifdef PERL_IN_XSUB_RE
87 # if defined(PERL_CAPI) || defined(PERL_OBJECT)
102 # if defined(BUGGY_MSC6)
103 /* MSC 6.00A breaks on op/regexp.t test 85 unless we turn this off */
104 # pragma optimize("a",off)
105 /* But MSC 6.00A is happy with 'w', for aliases only across function calls*/
106 # pragma optimize("w",on )
107 # endif /* BUGGY_MSC6 */
111 #define STATIC static
114 #define ISMULT1(c) ((c) == '*' || (c) == '+' || (c) == '?')
115 #define ISMULT2(s) ((*s) == '*' || (*s) == '+' || (*s) == '?' || \
116 ((*s) == '{' && regcurly(s)))
118 #define PERL_META "^$.[()|?+*\\"
120 #define META "^$.[()|?+*\\"
124 #undef SPSTART /* dratted cpp namespace... */
127 * Flags to be passed up and down.
129 #define WORST 0 /* Worst case. */
130 #define HASWIDTH 0x1 /* Known to match non-null strings. */
131 #define SIMPLE 0x2 /* Simple enough to be STAR/PLUS operand. */
132 #define SPSTART 0x4 /* Starts with * or +. */
133 #define TRYAGAIN 0x8 /* Weeded out a declaration. */
135 /* Length of a variant. */
137 typedef struct scan_data_t {
143 I32 last_end; /* min value, <0 unless valid. */
146 SV **longest; /* Either &l_fixed, or &l_float. */
150 I32 offset_float_min;
151 I32 offset_float_max;
154 struct regnode_charclass_class *start_class;
158 * Forward declarations for pregcomp()'s friends.
161 static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
164 #define SF_BEFORE_EOL (SF_BEFORE_SEOL|SF_BEFORE_MEOL)
165 #define SF_BEFORE_SEOL 0x1
166 #define SF_BEFORE_MEOL 0x2
167 #define SF_FIX_BEFORE_EOL (SF_FIX_BEFORE_SEOL|SF_FIX_BEFORE_MEOL)
168 #define SF_FL_BEFORE_EOL (SF_FL_BEFORE_SEOL|SF_FL_BEFORE_MEOL)
171 # define SF_FIX_SHIFT_EOL (0+2)
172 # define SF_FL_SHIFT_EOL (0+4)
174 # define SF_FIX_SHIFT_EOL (+2)
175 # define SF_FL_SHIFT_EOL (+4)
178 #define SF_FIX_BEFORE_SEOL (SF_BEFORE_SEOL << SF_FIX_SHIFT_EOL)
179 #define SF_FIX_BEFORE_MEOL (SF_BEFORE_MEOL << SF_FIX_SHIFT_EOL)
181 #define SF_FL_BEFORE_SEOL (SF_BEFORE_SEOL << SF_FL_SHIFT_EOL)
182 #define SF_FL_BEFORE_MEOL (SF_BEFORE_MEOL << SF_FL_SHIFT_EOL) /* 0x20 */
183 #define SF_IS_INF 0x40
184 #define SF_HAS_PAR 0x80
185 #define SF_IN_PAR 0x100
186 #define SF_HAS_EVAL 0x200
187 #define SCF_DO_SUBSTR 0x400
188 #define SCF_DO_STCLASS_AND 0x0800
189 #define SCF_DO_STCLASS_OR 0x1000
190 #define SCF_DO_STCLASS (SCF_DO_STCLASS_AND|SCF_DO_STCLASS_OR)
193 #define UTF (PL_reg_flags & RF_utf8)
194 #define LOC (PL_regflags & PMf_LOCALE)
195 #define FOLD (PL_regflags & PMf_FOLD)
197 #define OOB_CHAR8 1234
198 #define OOB_UTF8 123456
199 #define OOB_NAMEDCLASS -1
201 #define CHR_SVLEN(sv) (UTF ? sv_len_utf8(sv) : SvCUR(sv))
202 #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b)
204 /* Allow for side effects in s */
205 #define REGC(c,s) STMT_START { if (!SIZE_ONLY) *(s) = (c); else (s);} STMT_END
207 static void clear_re(pTHXo_ void *r);
209 /* Mark that we cannot extend a found fixed substring at this point.
210 Updata the longest found anchored substring and the longest found
211 floating substrings if needed. */
214 S_scan_commit(pTHX_ scan_data_t *data)
217 STRLEN l = CHR_SVLEN(data->last_found);
218 STRLEN old_l = CHR_SVLEN(*data->longest);
220 if ((l >= old_l) && ((l > old_l) || (data->flags & SF_BEFORE_EOL))) {
221 sv_setsv(*data->longest, data->last_found);
222 if (*data->longest == data->longest_fixed) {
223 data->offset_fixed = l ? data->last_start_min : data->pos_min;
224 if (data->flags & SF_BEFORE_EOL)
226 |= ((data->flags & SF_BEFORE_EOL) << SF_FIX_SHIFT_EOL);
228 data->flags &= ~SF_FIX_BEFORE_EOL;
231 data->offset_float_min = l ? data->last_start_min : data->pos_min;
232 data->offset_float_max = (l
233 ? data->last_start_max
234 : data->pos_min + data->pos_delta);
235 if (data->flags & SF_BEFORE_EOL)
237 |= ((data->flags & SF_BEFORE_EOL) << SF_FL_SHIFT_EOL);
239 data->flags &= ~SF_FL_BEFORE_EOL;
242 SvCUR_set(data->last_found, 0);
244 data->flags &= ~SF_BEFORE_EOL;
247 /* Can match anything (initialization) */
249 S_cl_anything(pTHX_ struct regnode_charclass_class *cl)
253 ANYOF_CLASS_ZERO(cl);
254 for (value = 0; value < 256; ++value)
255 ANYOF_BITMAP_SET(cl, value);
256 cl->flags = ANYOF_EOS;
258 cl->flags |= ANYOF_LOCALE;
261 /* Can match anything (initialization) */
263 S_cl_is_anything(pTHX_ struct regnode_charclass_class *cl)
267 for (value = 0; value < ANYOF_MAX; value += 2)
268 if (ANYOF_CLASS_TEST(cl, value) && ANYOF_CLASS_TEST(cl, value + 1))
270 for (value = 0; value < 256; ++value)
271 if (!ANYOF_BITMAP_TEST(cl, value))
276 /* Can match anything (initialization) */
278 S_cl_init(pTHX_ struct regnode_charclass_class *cl)
280 Zero(cl, 1, struct regnode_charclass_class);
286 S_cl_init_zero(pTHX_ struct regnode_charclass_class *cl)
288 Zero(cl, 1, struct regnode_charclass_class);
292 cl->flags |= ANYOF_LOCALE;
295 /* 'And' a given class with another one. Can create false positives */
296 /* We assume that cl is not inverted */
298 S_cl_and(pTHX_ struct regnode_charclass_class *cl,
299 struct regnode_charclass_class *and_with)
303 if (!(and_with->flags & ANYOF_CLASS)
304 && !(cl->flags & ANYOF_CLASS)
305 && (and_with->flags & ANYOF_LOCALE) == (cl->flags & ANYOF_LOCALE)
306 && !(and_with->flags & ANYOF_FOLD)
307 && !(cl->flags & ANYOF_FOLD)) {
310 if (and_with->flags & ANYOF_INVERT)
311 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
312 cl->bitmap[i] &= ~and_with->bitmap[i];
314 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
315 cl->bitmap[i] &= and_with->bitmap[i];
316 } /* XXXX: logic is complicated otherwise, leave it along for a moment. */
317 if (!(and_with->flags & ANYOF_EOS))
318 cl->flags &= ~ANYOF_EOS;
321 /* 'OR' a given class with another one. Can create false positives */
322 /* We assume that cl is not inverted */
324 S_cl_or(pTHX_ struct regnode_charclass_class *cl, struct regnode_charclass_class *or_with)
328 if (or_with->flags & ANYOF_INVERT) {
330 * (B1 | CL1) | (!B2 & !CL2) = (B1 | !B2 & !CL2) | (CL1 | (!B2 & !CL2))
331 * <= (B1 | !B2) | (CL1 | !CL2)
332 * which is wasteful if CL2 is small, but we ignore CL2:
333 * (B1 | CL1) | (!B2 & !CL2) <= (B1 | CL1) | !B2 = (B1 | !B2) | CL1
334 * XXXX Can we handle case-fold? Unclear:
335 * (OK1(i) | OK1(i')) | !(OK1(i) | OK1(i')) =
336 * (OK1(i) | OK1(i')) | (!OK1(i) & !OK1(i'))
338 if ( (or_with->flags & ANYOF_LOCALE) == (cl->flags & ANYOF_LOCALE)
339 && !(or_with->flags & ANYOF_FOLD)
340 && !(cl->flags & ANYOF_FOLD) ) {
343 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
344 cl->bitmap[i] |= ~or_with->bitmap[i];
345 } /* XXXX: logic is complicated otherwise */
350 /* (B1 | CL1) | (B2 | CL2) = (B1 | B2) | (CL1 | CL2)) */
351 if ( (or_with->flags & ANYOF_LOCALE) == (cl->flags & ANYOF_LOCALE)
352 && (!(or_with->flags & ANYOF_FOLD)
353 || (cl->flags & ANYOF_FOLD)) ) {
356 /* OR char bitmap and class bitmap separately */
357 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
358 cl->bitmap[i] |= or_with->bitmap[i];
359 if (or_with->flags & ANYOF_CLASS) {
360 for (i = 0; i < ANYOF_CLASSBITMAP_SIZE; i++)
361 cl->classflags[i] |= or_with->classflags[i];
362 cl->flags |= ANYOF_CLASS;
365 else { /* XXXX: logic is complicated, leave it along for a moment. */
369 if (or_with->flags & ANYOF_EOS)
370 cl->flags |= ANYOF_EOS;
373 /* REx optimizer. Converts nodes into quickier variants "in place".
374 Finds fixed substrings. */
376 /* Stops at toplevel WHILEM as well as at `last'. At end *scanp is set
377 to the position after last scanned or to NULL. */
380 S_study_chunk(pTHX_ regnode **scanp, I32 *deltap, regnode *last, scan_data_t *data, U32 flags)
381 /* scanp: Start here (read-write). */
382 /* deltap: Write maxlen-minlen here. */
383 /* last: Stop before this one. */
386 I32 min = 0, pars = 0, code;
387 regnode *scan = *scanp, *next;
389 int is_inf = (flags & SCF_DO_SUBSTR) && (data->flags & SF_IS_INF);
390 int is_inf_internal = 0; /* The studied chunk is infinite */
391 I32 is_par = OP(scan) == OPEN ? ARG(scan) : 0;
392 scan_data_t data_fake;
393 struct regnode_charclass_class and_with; /* Valid if flags & SCF_DO_STCLASS_OR */
395 while (scan && OP(scan) != END && scan < last) {
396 /* Peephole optimizer: */
398 if (PL_regkind[(U8)OP(scan)] == EXACT) {
399 /* Merge several consecutive EXACTish nodes into one. */
400 regnode *n = regnext(scan);
403 regnode *stop = scan;
406 next = scan + NODE_SZ_STR(scan);
407 /* Skip NOTHING, merge EXACT*. */
409 ( PL_regkind[(U8)OP(n)] == NOTHING ||
410 (stringok && (OP(n) == OP(scan))))
412 && NEXT_OFF(scan) + NEXT_OFF(n) < I16_MAX) {
413 if (OP(n) == TAIL || n > next)
415 if (PL_regkind[(U8)OP(n)] == NOTHING) {
416 NEXT_OFF(scan) += NEXT_OFF(n);
417 next = n + NODE_STEP_REGNODE;
425 int oldl = STR_LEN(scan);
426 regnode *nnext = regnext(n);
428 if (oldl + STR_LEN(n) > U8_MAX)
430 NEXT_OFF(scan) += NEXT_OFF(n);
431 STR_LEN(scan) += STR_LEN(n);
432 next = n + NODE_SZ_STR(n);
433 /* Now we can overwrite *n : */
434 Move(STRING(n), STRING(scan) + oldl,
445 n = scan + NODE_SZ_STR(scan);
447 if (PL_regkind[(U8)OP(n)] != NOTHING || OP(n) == NOTHING) {
455 /* Follow the next-chain of the current node and optimize
456 away all the NOTHINGs from it. */
457 if (OP(scan) != CURLYX) {
458 int max = (reg_off_by_arg[OP(scan)]
460 /* I32 may be smaller than U16 on CRAYs! */
461 : (I32_MAX < U16_MAX ? I32_MAX : U16_MAX));
462 int off = (reg_off_by_arg[OP(scan)] ? ARG(scan) : NEXT_OFF(scan));
466 /* Skip NOTHING and LONGJMP. */
467 while ((n = regnext(n))
468 && ((PL_regkind[(U8)OP(n)] == NOTHING && (noff = NEXT_OFF(n)))
469 || ((OP(n) == LONGJMP) && (noff = ARG(n))))
472 if (reg_off_by_arg[OP(scan)])
475 NEXT_OFF(scan) = off;
477 /* The principal pseudo-switch. Cannot be a switch, since we
478 look into several different things. */
479 if (OP(scan) == BRANCH || OP(scan) == BRANCHJ
480 || OP(scan) == IFTHEN || OP(scan) == SUSPEND) {
481 next = regnext(scan);
484 if (OP(next) == code || code == IFTHEN || code == SUSPEND) {
485 I32 max1 = 0, min1 = I32_MAX, num = 0;
486 struct regnode_charclass_class accum;
488 if (flags & SCF_DO_SUBSTR) /* XXXX Add !SUSPEND? */
489 scan_commit(data); /* Cannot merge strings after this. */
490 if (flags & SCF_DO_STCLASS)
491 cl_init_zero(&accum);
492 while (OP(scan) == code) {
493 I32 deltanext, minnext, f = 0;
494 struct regnode_charclass_class this_class;
499 data_fake.whilem_c = data->whilem_c;
500 next = regnext(scan);
501 scan = NEXTOPER(scan);
503 scan = NEXTOPER(scan);
504 if (flags & SCF_DO_STCLASS) {
505 cl_init(&this_class);
506 data_fake.start_class = &this_class;
507 f = SCF_DO_STCLASS_AND;
509 /* we suppose the run is continuous, last=next...*/
510 minnext = study_chunk(&scan, &deltanext, next,
514 if (max1 < minnext + deltanext)
515 max1 = minnext + deltanext;
516 if (deltanext == I32_MAX)
517 is_inf = is_inf_internal = 1;
519 if (data_fake.flags & (SF_HAS_PAR|SF_IN_PAR))
521 if (data && (data_fake.flags & SF_HAS_EVAL))
522 data->flags |= SF_HAS_EVAL;
524 data->whilem_c = data_fake.whilem_c;
525 if (flags & SCF_DO_STCLASS)
526 cl_or(&accum, &this_class);
530 if (code == IFTHEN && num < 2) /* Empty ELSE branch */
532 if (flags & SCF_DO_SUBSTR) {
533 data->pos_min += min1;
534 data->pos_delta += max1 - min1;
535 if (max1 != min1 || is_inf)
536 data->longest = &(data->longest_float);
539 delta += max1 - min1;
540 if (flags & SCF_DO_STCLASS_OR) {
541 cl_or(data->start_class, &accum);
543 cl_and(data->start_class, &and_with);
544 flags &= ~SCF_DO_STCLASS;
547 else if (flags & SCF_DO_STCLASS_AND) {
549 cl_and(data->start_class, &accum);
550 flags &= ~SCF_DO_STCLASS;
553 /* Switch to OR mode: cache the old value of
554 * data->start_class */
555 StructCopy(data->start_class, &and_with,
556 struct regnode_charclass_class);
557 flags &= ~SCF_DO_STCLASS_AND;
558 StructCopy(&accum, data->start_class,
559 struct regnode_charclass_class);
560 flags |= SCF_DO_STCLASS_OR;
561 data->start_class->flags |= ANYOF_EOS;
565 else if (code == BRANCHJ) /* single branch is optimized. */
566 scan = NEXTOPER(NEXTOPER(scan));
567 else /* single branch is optimized. */
568 scan = NEXTOPER(scan);
571 else if (OP(scan) == EXACT) {
572 I32 l = STR_LEN(scan);
574 unsigned char *s = (unsigned char *)STRING(scan);
575 unsigned char *e = s + l;
584 if (flags & SCF_DO_SUBSTR) { /* Update longest substr. */
585 /* The code below prefers earlier match for fixed
586 offset, later match for variable offset. */
587 if (data->last_end == -1) { /* Update the start info. */
588 data->last_start_min = data->pos_min;
589 data->last_start_max = is_inf
590 ? I32_MAX : data->pos_min + data->pos_delta;
592 sv_catpvn(data->last_found, STRING(scan), STR_LEN(scan));
593 data->last_end = data->pos_min + l;
594 data->pos_min += l; /* As in the first entry. */
595 data->flags &= ~SF_BEFORE_EOL;
597 if (flags & SCF_DO_STCLASS_AND) {
598 /* Check whether it is compatible with what we know already! */
601 if (!(data->start_class->flags & (ANYOF_CLASS | ANYOF_LOCALE))
602 && !ANYOF_BITMAP_TEST(data->start_class, *STRING(scan))
603 && (!(data->start_class->flags & ANYOF_FOLD)
604 || !ANYOF_BITMAP_TEST(data->start_class,
605 PL_fold[*STRING(scan)])))
607 ANYOF_CLASS_ZERO(data->start_class);
608 ANYOF_BITMAP_ZERO(data->start_class);
610 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
611 data->start_class->flags &= ~ANYOF_EOS;
613 else if (flags & SCF_DO_STCLASS_OR) {
614 /* false positive possible if the class is case-folded */
615 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
616 data->start_class->flags &= ~ANYOF_EOS;
617 cl_and(data->start_class, &and_with);
619 flags &= ~SCF_DO_STCLASS;
621 else if (PL_regkind[(U8)OP(scan)] == EXACT) { /* But OP != EXACT! */
622 I32 l = STR_LEN(scan);
624 /* Search for fixed substrings supports EXACT only. */
625 if (flags & SCF_DO_SUBSTR)
628 unsigned char *s = (unsigned char *)STRING(scan);
629 unsigned char *e = s + l;
638 if (data && (flags & SCF_DO_SUBSTR))
640 if (flags & SCF_DO_STCLASS_AND) {
641 /* Check whether it is compatible with what we know already! */
644 if (!(data->start_class->flags & (ANYOF_CLASS | ANYOF_LOCALE))
645 && !ANYOF_BITMAP_TEST(data->start_class, *STRING(scan))
646 && !ANYOF_BITMAP_TEST(data->start_class,
647 PL_fold[*STRING(scan)]))
649 ANYOF_CLASS_ZERO(data->start_class);
650 ANYOF_BITMAP_ZERO(data->start_class);
652 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
653 data->start_class->flags &= ~ANYOF_EOS;
654 data->start_class->flags |= ANYOF_FOLD;
655 if (OP(scan) == EXACTFL)
656 data->start_class->flags |= ANYOF_LOCALE;
659 else if (flags & SCF_DO_STCLASS_OR) {
660 if (data->start_class->flags & ANYOF_FOLD) {
661 /* false positive possible if the class is case-folded.
662 Assume that the locale settings are the same... */
663 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
664 data->start_class->flags &= ~ANYOF_EOS;
666 cl_and(data->start_class, &and_with);
668 flags &= ~SCF_DO_STCLASS;
670 else if (strchr((char*)PL_varies,OP(scan))) {
671 I32 mincount, maxcount, minnext, deltanext, pos_before, fl;
673 regnode *oscan = scan;
674 struct regnode_charclass_class this_class;
675 struct regnode_charclass_class *oclass = NULL;
677 switch (PL_regkind[(U8)OP(scan)]) {
678 case WHILEM: /* End of (?:...)* . */
679 scan = NEXTOPER(scan);
682 if (flags & (SCF_DO_SUBSTR | SCF_DO_STCLASS)) {
683 next = NEXTOPER(scan);
684 if (OP(next) == EXACT || (flags & SCF_DO_STCLASS)) {
686 maxcount = REG_INFTY;
687 next = regnext(scan);
688 scan = NEXTOPER(scan);
692 if (flags & SCF_DO_SUBSTR)
697 if (flags & SCF_DO_STCLASS) {
699 maxcount = REG_INFTY;
700 next = regnext(scan);
701 scan = NEXTOPER(scan);
704 is_inf = is_inf_internal = 1;
705 scan = regnext(scan);
706 if (flags & SCF_DO_SUBSTR) {
707 scan_commit(data); /* Cannot extend fixed substrings */
708 data->longest = &(data->longest_float);
710 goto optimize_curly_tail;
712 mincount = ARG1(scan);
713 maxcount = ARG2(scan);
714 next = regnext(scan);
715 scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
717 if (flags & SCF_DO_SUBSTR) {
718 if (mincount == 0) scan_commit(data); /* Cannot extend fixed substrings */
719 pos_before = data->pos_min;
723 data->flags &= ~(SF_HAS_PAR|SF_IN_PAR|SF_HAS_EVAL);
725 data->flags |= SF_IS_INF;
727 if (flags & SCF_DO_STCLASS) {
728 cl_init(&this_class);
729 oclass = data->start_class;
730 data->start_class = &this_class;
731 f |= SCF_DO_STCLASS_AND;
732 f &= ~SCF_DO_STCLASS_OR;
735 /* This will finish on WHILEM, setting scan, or on NULL: */
736 minnext = study_chunk(&scan, &deltanext, last, data,
738 ? (f & ~SCF_DO_SUBSTR) : f);
740 if (flags & SCF_DO_STCLASS)
741 data->start_class = oclass;
742 if (mincount == 0 || minnext == 0) {
743 if (flags & SCF_DO_STCLASS_OR) {
744 cl_or(data->start_class, &this_class);
746 else if (flags & SCF_DO_STCLASS_AND) {
747 /* Switch to OR mode: cache the old value of
748 * data->start_class */
749 StructCopy(data->start_class, &and_with,
750 struct regnode_charclass_class);
751 flags &= ~SCF_DO_STCLASS_AND;
752 StructCopy(&this_class, data->start_class,
753 struct regnode_charclass_class);
754 flags |= SCF_DO_STCLASS_OR;
755 data->start_class->flags |= ANYOF_EOS;
757 } else { /* Non-zero len */
758 if (flags & SCF_DO_STCLASS_OR) {
759 cl_or(data->start_class, &this_class);
760 cl_and(data->start_class, &and_with);
762 else if (flags & SCF_DO_STCLASS_AND)
763 cl_and(data->start_class, &this_class);
764 flags &= ~SCF_DO_STCLASS;
766 if (!scan) /* It was not CURLYX, but CURLY. */
768 if (ckWARN(WARN_REGEXP) && (minnext + deltanext == 0)
769 && !(data->flags & (SF_HAS_PAR|SF_IN_PAR))
770 && maxcount <= REG_INFTY/3) /* Complement check for big count */
771 Perl_warner(aTHX_ WARN_REGEXP,
772 "Strange *+?{} on zero-length expression");
773 min += minnext * mincount;
774 is_inf_internal |= (maxcount == REG_INFTY
775 && (minnext + deltanext) > 0
776 || deltanext == I32_MAX);
777 is_inf |= is_inf_internal;
778 delta += (minnext + deltanext) * maxcount - minnext * mincount;
780 /* Try powerful optimization CURLYX => CURLYN. */
781 if ( OP(oscan) == CURLYX && data
782 && data->flags & SF_IN_PAR
783 && !(data->flags & SF_HAS_EVAL)
784 && !deltanext && minnext == 1 ) {
785 /* Try to optimize to CURLYN. */
786 regnode *nxt = NEXTOPER(oscan) + EXTRA_STEP_2ARGS;
787 regnode *nxt1 = nxt, *nxt2;
791 if (!strchr((char*)PL_simple,OP(nxt))
792 && !(PL_regkind[(U8)OP(nxt)] == EXACT
793 && STR_LEN(nxt) == 1))
797 if (OP(nxt) != CLOSE)
799 /* Now we know that nxt2 is the only contents: */
800 oscan->flags = ARG(nxt);
802 OP(nxt1) = NOTHING; /* was OPEN. */
804 OP(nxt1 + 1) = OPTIMIZED; /* was count. */
805 NEXT_OFF(nxt1+ 1) = 0; /* just for consistancy. */
806 NEXT_OFF(nxt2) = 0; /* just for consistancy with CURLY. */
807 OP(nxt) = OPTIMIZED; /* was CLOSE. */
808 OP(nxt + 1) = OPTIMIZED; /* was count. */
809 NEXT_OFF(nxt+ 1) = 0; /* just for consistancy. */
814 /* Try optimization CURLYX => CURLYM. */
815 if ( OP(oscan) == CURLYX && data
816 && !(data->flags & SF_HAS_PAR)
817 && !(data->flags & SF_HAS_EVAL)
819 /* XXXX How to optimize if data == 0? */
820 /* Optimize to a simpler form. */
821 regnode *nxt = NEXTOPER(oscan) + EXTRA_STEP_2ARGS; /* OPEN */
825 while ( (nxt2 = regnext(nxt)) /* skip over embedded stuff*/
826 && (OP(nxt2) != WHILEM))
828 OP(nxt2) = SUCCEED; /* Whas WHILEM */
829 /* Need to optimize away parenths. */
830 if (data->flags & SF_IN_PAR) {
831 /* Set the parenth number. */
832 regnode *nxt1 = NEXTOPER(oscan) + EXTRA_STEP_2ARGS; /* OPEN*/
834 if (OP(nxt) != CLOSE)
835 FAIL("panic opt close");
836 oscan->flags = ARG(nxt);
837 OP(nxt1) = OPTIMIZED; /* was OPEN. */
838 OP(nxt) = OPTIMIZED; /* was CLOSE. */
840 OP(nxt1 + 1) = OPTIMIZED; /* was count. */
841 OP(nxt + 1) = OPTIMIZED; /* was count. */
842 NEXT_OFF(nxt1 + 1) = 0; /* just for consistancy. */
843 NEXT_OFF(nxt + 1) = 0; /* just for consistancy. */
846 while ( nxt1 && (OP(nxt1) != WHILEM)) {
847 regnode *nnxt = regnext(nxt1);
850 if (reg_off_by_arg[OP(nxt1)])
851 ARG_SET(nxt1, nxt2 - nxt1);
852 else if (nxt2 - nxt1 < U16_MAX)
853 NEXT_OFF(nxt1) = nxt2 - nxt1;
855 OP(nxt) = NOTHING; /* Cannot beautify */
860 /* Optimize again: */
861 study_chunk(&nxt1, &deltanext, nxt, NULL, 0);
866 else if (OP(oscan) == CURLYX && data && ++data->whilem_c < 16) {
867 /* This stays as CURLYX, and can put the count/of pair. */
868 /* Find WHILEM (as in regexec.c) */
869 regnode *nxt = oscan + NEXT_OFF(oscan);
871 if (OP(PREVOPER(nxt)) == NOTHING) /* LONGJMP */
873 PREVOPER(nxt)->flags = data->whilem_c
874 | (PL_reg_whilem_seen << 4); /* On WHILEM */
876 if (data && fl & (SF_HAS_PAR|SF_IN_PAR))
878 if (flags & SCF_DO_SUBSTR) {
879 SV *last_str = Nullsv;
880 int counted = mincount != 0;
882 if (data->last_end > 0 && mincount != 0) { /* Ends with a string. */
883 I32 b = pos_before >= data->last_start_min
884 ? pos_before : data->last_start_min;
886 char *s = SvPV(data->last_found, l);
887 I32 old = b - data->last_start_min;
890 old = utf8_hop((U8*)s, old) - (U8*)s;
893 /* Get the added string: */
894 last_str = newSVpvn(s + old, l);
895 if (deltanext == 0 && pos_before == b) {
896 /* What was added is a constant string */
898 SvGROW(last_str, (mincount * l) + 1);
899 repeatcpy(SvPVX(last_str) + l,
900 SvPVX(last_str), l, mincount - 1);
901 SvCUR(last_str) *= mincount;
902 /* Add additional parts. */
903 SvCUR_set(data->last_found,
904 SvCUR(data->last_found) - l);
905 sv_catsv(data->last_found, last_str);
906 data->last_end += l * (mincount - 1);
910 /* It is counted once already... */
911 data->pos_min += minnext * (mincount - counted);
912 data->pos_delta += - counted * deltanext +
913 (minnext + deltanext) * maxcount - minnext * mincount;
914 if (mincount != maxcount) {
915 /* Cannot extend fixed substrings found inside
918 if (mincount && last_str) {
919 sv_setsv(data->last_found, last_str);
920 data->last_end = data->pos_min;
921 data->last_start_min =
922 data->pos_min - CHR_SVLEN(last_str);
923 data->last_start_max = is_inf
925 : data->pos_min + data->pos_delta
926 - CHR_SVLEN(last_str);
928 data->longest = &(data->longest_float);
930 SvREFCNT_dec(last_str);
932 if (data && (fl & SF_HAS_EVAL))
933 data->flags |= SF_HAS_EVAL;
935 if (OP(oscan) != CURLYX) {
936 while (PL_regkind[(U8)OP(next = regnext(oscan))] == NOTHING
938 NEXT_OFF(oscan) += NEXT_OFF(next);
941 default: /* REF and CLUMP only? */
942 if (flags & SCF_DO_SUBSTR) {
943 scan_commit(data); /* Cannot expect anything... */
944 data->longest = &(data->longest_float);
946 is_inf = is_inf_internal = 1;
947 if (flags & SCF_DO_STCLASS_OR)
948 cl_anything(data->start_class);
949 flags &= ~SCF_DO_STCLASS;
953 else if (strchr((char*)PL_simple,OP(scan)) || PL_regkind[(U8)OP(scan)] == ANYUTF8) {
956 if (flags & SCF_DO_SUBSTR) {
961 if (flags & SCF_DO_STCLASS) {
962 data->start_class->flags &= ~ANYOF_EOS; /* No match on empty */
964 /* Some of the logic below assumes that switching
965 locale on will only add false positives. */
966 switch (PL_regkind[(U8)OP(scan)]) {
983 /* Perl_croak(aTHX_ "panic: unexpected simple REx opcode %d", OP(scan)); */
984 if (flags & SCF_DO_STCLASS_OR) /* Allow everything */
985 cl_anything(data->start_class);
988 if (OP(scan) == SANY)
990 if (flags & SCF_DO_STCLASS_OR) { /* Everything but \n */
991 value = (ANYOF_BITMAP_TEST(data->start_class,'\n')
992 || (data->start_class->flags & ANYOF_CLASS));
993 cl_anything(data->start_class);
995 if (flags & SCF_DO_STCLASS_AND || !value)
996 ANYOF_BITMAP_CLEAR(data->start_class,'\n');
999 if (flags & SCF_DO_STCLASS_AND)
1000 cl_and(data->start_class,
1001 (struct regnode_charclass_class*)scan);
1003 cl_or(data->start_class,
1004 (struct regnode_charclass_class*)scan);
1007 if (flags & SCF_DO_STCLASS_AND) {
1008 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1009 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NALNUM);
1010 for (value = 0; value < 256; value++)
1011 if (!isALNUM(value))
1012 ANYOF_BITMAP_CLEAR(data->start_class, value);
1016 if (data->start_class->flags & ANYOF_LOCALE)
1017 ANYOF_CLASS_SET(data->start_class,ANYOF_ALNUM);
1019 for (value = 0; value < 256; value++)
1021 ANYOF_BITMAP_SET(data->start_class, value);
1026 if (flags & SCF_DO_STCLASS_AND) {
1027 if (data->start_class->flags & ANYOF_LOCALE)
1028 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NALNUM);
1031 ANYOF_CLASS_SET(data->start_class,ANYOF_ALNUM);
1032 data->start_class->flags |= ANYOF_LOCALE;
1036 if (flags & SCF_DO_STCLASS_AND) {
1037 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1038 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_ALNUM);
1039 for (value = 0; value < 256; value++)
1041 ANYOF_BITMAP_CLEAR(data->start_class, value);
1045 if (data->start_class->flags & ANYOF_LOCALE)
1046 ANYOF_CLASS_SET(data->start_class,ANYOF_NALNUM);
1048 for (value = 0; value < 256; value++)
1049 if (!isALNUM(value))
1050 ANYOF_BITMAP_SET(data->start_class, value);
1055 if (flags & SCF_DO_STCLASS_AND) {
1056 if (data->start_class->flags & ANYOF_LOCALE)
1057 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_ALNUM);
1060 data->start_class->flags |= ANYOF_LOCALE;
1061 ANYOF_CLASS_SET(data->start_class,ANYOF_NALNUM);
1065 if (flags & SCF_DO_STCLASS_AND) {
1066 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1067 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NSPACE);
1068 for (value = 0; value < 256; value++)
1069 if (!isSPACE(value))
1070 ANYOF_BITMAP_CLEAR(data->start_class, value);
1074 if (data->start_class->flags & ANYOF_LOCALE)
1075 ANYOF_CLASS_SET(data->start_class,ANYOF_SPACE);
1077 for (value = 0; value < 256; value++)
1079 ANYOF_BITMAP_SET(data->start_class, value);
1084 if (flags & SCF_DO_STCLASS_AND) {
1085 if (data->start_class->flags & ANYOF_LOCALE)
1086 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NSPACE);
1089 data->start_class->flags |= ANYOF_LOCALE;
1090 ANYOF_CLASS_SET(data->start_class,ANYOF_SPACE);
1094 if (flags & SCF_DO_STCLASS_AND) {
1095 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1096 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_SPACE);
1097 for (value = 0; value < 256; value++)
1099 ANYOF_BITMAP_CLEAR(data->start_class, value);
1103 if (data->start_class->flags & ANYOF_LOCALE)
1104 ANYOF_CLASS_SET(data->start_class,ANYOF_NSPACE);
1106 for (value = 0; value < 256; value++)
1107 if (!isSPACE(value))
1108 ANYOF_BITMAP_SET(data->start_class, value);
1113 if (flags & SCF_DO_STCLASS_AND) {
1114 if (data->start_class->flags & ANYOF_LOCALE) {
1115 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_SPACE);
1116 for (value = 0; value < 256; value++)
1117 if (!isSPACE(value))
1118 ANYOF_BITMAP_CLEAR(data->start_class, value);
1122 data->start_class->flags |= ANYOF_LOCALE;
1123 ANYOF_CLASS_SET(data->start_class,ANYOF_NSPACE);
1127 if (flags & SCF_DO_STCLASS_AND) {
1128 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NDIGIT);
1129 for (value = 0; value < 256; value++)
1130 if (!isDIGIT(value))
1131 ANYOF_BITMAP_CLEAR(data->start_class, value);
1134 if (data->start_class->flags & ANYOF_LOCALE)
1135 ANYOF_CLASS_SET(data->start_class,ANYOF_DIGIT);
1137 for (value = 0; value < 256; value++)
1139 ANYOF_BITMAP_SET(data->start_class, value);
1144 if (flags & SCF_DO_STCLASS_AND) {
1145 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_DIGIT);
1146 for (value = 0; value < 256; value++)
1148 ANYOF_BITMAP_CLEAR(data->start_class, value);
1151 if (data->start_class->flags & ANYOF_LOCALE)
1152 ANYOF_CLASS_SET(data->start_class,ANYOF_NDIGIT);
1154 for (value = 0; value < 256; value++)
1155 if (!isDIGIT(value))
1156 ANYOF_BITMAP_SET(data->start_class, value);
1161 if (flags & SCF_DO_STCLASS_OR)
1162 cl_and(data->start_class, &and_with);
1163 flags &= ~SCF_DO_STCLASS;
1166 else if (PL_regkind[(U8)OP(scan)] == EOL && flags & SCF_DO_SUBSTR) {
1167 data->flags |= (OP(scan) == MEOL
1171 else if ( PL_regkind[(U8)OP(scan)] == BRANCHJ
1172 /* Lookbehind, or need to calculate parens/evals/stclass: */
1173 && (scan->flags || data || (flags & SCF_DO_STCLASS))
1174 && (OP(scan) == IFMATCH || OP(scan) == UNLESSM)) {
1175 /* Lookahead/lookbehind */
1176 I32 deltanext, minnext;
1178 struct regnode_charclass_class intrnl;
1181 data_fake.flags = 0;
1183 data_fake.whilem_c = data->whilem_c;
1184 if ( flags & SCF_DO_STCLASS && !scan->flags
1185 && OP(scan) == IFMATCH ) { /* Lookahead */
1187 data_fake.start_class = &intrnl;
1188 f = SCF_DO_STCLASS_AND;
1190 next = regnext(scan);
1191 nscan = NEXTOPER(NEXTOPER(scan));
1192 minnext = study_chunk(&nscan, &deltanext, last, &data_fake, f);
1195 FAIL("variable length lookbehind not implemented");
1197 else if (minnext > U8_MAX) {
1198 FAIL2("lookbehind longer than %"UVuf" not implemented", (UV)U8_MAX);
1200 scan->flags = minnext;
1202 if (data && data_fake.flags & (SF_HAS_PAR|SF_IN_PAR))
1204 if (data && (data_fake.flags & SF_HAS_EVAL))
1205 data->flags |= SF_HAS_EVAL;
1207 data->whilem_c = data_fake.whilem_c;
1209 int was = (data->start_class->flags & ANYOF_EOS);
1211 cl_and(data->start_class, &intrnl);
1213 data->start_class->flags |= ANYOF_EOS;
1216 else if (OP(scan) == OPEN) {
1219 else if (OP(scan) == CLOSE && ARG(scan) == is_par) {
1220 next = regnext(scan);
1222 if ( next && (OP(next) != WHILEM) && next < last)
1223 is_par = 0; /* Disable optimization */
1225 else if (OP(scan) == EVAL) {
1227 data->flags |= SF_HAS_EVAL;
1229 else if (OP(scan) == LOGICAL && scan->flags == 2) { /* Embedded */
1230 if (flags & SCF_DO_SUBSTR) {
1232 data->longest = &(data->longest_float);
1234 is_inf = is_inf_internal = 1;
1235 if (flags & SCF_DO_STCLASS_OR) /* Allow everything */
1236 cl_anything(data->start_class);
1238 /* Else: zero-length, ignore. */
1239 scan = regnext(scan);
1244 *deltap = is_inf_internal ? I32_MAX : delta;
1245 if (flags & SCF_DO_SUBSTR && is_inf)
1246 data->pos_delta = I32_MAX - data->pos_min;
1247 if (is_par > U8_MAX)
1249 if (is_par && pars==1 && data) {
1250 data->flags |= SF_IN_PAR;
1251 data->flags &= ~SF_HAS_PAR;
1253 else if (pars && data) {
1254 data->flags |= SF_HAS_PAR;
1255 data->flags &= ~SF_IN_PAR;
1257 if (flags & SCF_DO_STCLASS_OR)
1258 cl_and(data->start_class, &and_with);
1263 S_add_data(pTHX_ I32 n, char *s)
1266 if (PL_regcomp_rx->data) {
1267 Renewc(PL_regcomp_rx->data,
1268 sizeof(*PL_regcomp_rx->data) + sizeof(void*) * (PL_regcomp_rx->data->count + n - 1),
1269 char, struct reg_data);
1270 Renew(PL_regcomp_rx->data->what, PL_regcomp_rx->data->count + n, U8);
1271 PL_regcomp_rx->data->count += n;
1274 Newc(1207, PL_regcomp_rx->data, sizeof(*PL_regcomp_rx->data) + sizeof(void*) * (n - 1),
1275 char, struct reg_data);
1276 New(1208, PL_regcomp_rx->data->what, n, U8);
1277 PL_regcomp_rx->data->count = n;
1279 Copy(s, PL_regcomp_rx->data->what + PL_regcomp_rx->data->count - n, n, U8);
1280 return PL_regcomp_rx->data->count - n;
1284 Perl_reginitcolors(pTHX)
1288 char *s = PerlEnv_getenv("PERL_RE_COLORS");
1291 PL_colors[0] = s = savepv(s);
1293 s = strchr(s, '\t');
1299 PL_colors[i] = s = "";
1303 PL_colors[i++] = "";
1309 - pregcomp - compile a regular expression into internal code
1311 * We can't allocate space until we know how big the compiled form will be,
1312 * but we can't compile it (and thus know how big it is) until we've got a
1313 * place to put the code. So we cheat: we compile it twice, once with code
1314 * generation turned off and size counting turned on, and once "for real".
1315 * This also means that we don't allocate space until we are sure that the
1316 * thing really will compile successfully, and we never have to move the
1317 * code and thus invalidate pointers into it. (Note that it has to be in
1318 * one piece because free() must be able to free it all.) [NB: not true in perl]
1320 * Beware that the optimization-preparation code in here knows about some
1321 * of the structure of the compiled regexp. [I'll say.]
1324 Perl_pregcomp(pTHX_ char *exp, char *xend, PMOP *pm)
1340 FAIL("NULL regexp argument");
1342 if (pm->op_pmdynflags & PMdf_UTF8) {
1343 PL_reg_flags |= RF_utf8;
1348 PL_regprecomp = savepvn(exp, xend - exp);
1349 DEBUG_r(if (!PL_colorset) reginitcolors());
1350 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sCompiling REx%s `%s%*s%s'\n",
1351 PL_colors[4],PL_colors[5],PL_colors[0],
1352 (int)(xend - exp), PL_regprecomp, PL_colors[1]));
1353 PL_regflags = pm->op_pmflags;
1357 PL_seen_zerolen = *exp == '^' ? -1 : 0;
1361 /* First pass: determine size, legality. */
1362 PL_regcomp_parse = exp;
1367 PL_regcode = &PL_regdummy;
1368 PL_reg_whilem_seen = 0;
1369 REGC((U8)REG_MAGIC, (char*)PL_regcode);
1370 if (reg(0, &flags) == NULL) {
1371 Safefree(PL_regprecomp);
1372 PL_regprecomp = Nullch;
1375 DEBUG_r(PerlIO_printf(Perl_debug_log, "size %"IVdf" ", (IV)PL_regsize));
1377 /* Small enough for pointer-storage convention?
1378 If extralen==0, this means that we will not need long jumps. */
1379 if (PL_regsize >= 0x10000L && PL_extralen)
1380 PL_regsize += PL_extralen;
1383 if (PL_reg_whilem_seen > 15)
1384 PL_reg_whilem_seen = 15;
1386 /* Allocate space and initialize. */
1387 Newc(1001, r, sizeof(regexp) + (unsigned)PL_regsize * sizeof(regnode),
1390 FAIL("regexp out of space");
1392 /* avoid reading uninitialized memory in DEBUGGING code in study_chunk() */
1393 Zero(r, sizeof(regexp) + (unsigned)PL_regsize * sizeof(regnode), char);
1396 r->prelen = xend - exp;
1397 r->precomp = PL_regprecomp;
1399 r->reganch = pm->op_pmflags & PMf_COMPILETIME;
1400 r->nparens = PL_regnpar - 1; /* set early to validate backrefs */
1402 r->substrs = 0; /* Useful during FAIL. */
1403 r->startp = 0; /* Useful during FAIL. */
1404 r->endp = 0; /* Useful during FAIL. */
1408 /* Second pass: emit code. */
1409 PL_regcomp_parse = exp;
1413 PL_regcode = r->program;
1414 /* Store the count of eval-groups for security checks: */
1415 PL_regcode->next_off = ((PL_seen_evals > U16_MAX) ? U16_MAX : PL_seen_evals);
1416 REGC((U8)REG_MAGIC, (char*) PL_regcode++);
1418 if (reg(0, &flags) == NULL)
1421 /* Dig out information for optimizations. */
1422 r->reganch = pm->op_pmflags & PMf_COMPILETIME; /* Again? */
1423 pm->op_pmflags = PL_regflags;
1425 r->reganch |= ROPT_UTF8;
1426 r->regstclass = NULL;
1427 if (PL_regnaughty >= 10) /* Probably an expensive pattern. */
1428 r->reganch |= ROPT_NAUGHTY;
1429 scan = r->program + 1; /* First BRANCH. */
1431 /* XXXX To minimize changes to RE engine we always allocate
1432 3-units-long substrs field. */
1433 Newz(1004, r->substrs, 1, struct reg_substr_data);
1435 StructCopy(&zero_scan_data, &data, scan_data_t);
1436 /* XXXX Should not we check for something else? Usually it is OPEN1... */
1437 if (OP(scan) != BRANCH) { /* Only one top-level choice. */
1439 STRLEN longest_float_length, longest_fixed_length;
1440 struct regnode_charclass_class ch_class;
1444 /* Skip introductions and multiplicators >= 1. */
1445 while ((OP(first) == OPEN && (sawopen = 1)) ||
1446 /* An OR of *one* alternative - should not happen now. */
1447 (OP(first) == BRANCH && OP(regnext(first)) != BRANCH) ||
1448 (OP(first) == PLUS) ||
1449 (OP(first) == MINMOD) ||
1450 /* An {n,m} with n>0 */
1451 (PL_regkind[(U8)OP(first)] == CURLY && ARG1(first) > 0) ) {
1452 if (OP(first) == PLUS)
1455 first += regarglen[(U8)OP(first)];
1456 first = NEXTOPER(first);
1459 /* Starting-point info. */
1461 if (PL_regkind[(U8)OP(first)] == EXACT) {
1462 if (OP(first) == EXACT); /* Empty, get anchored substr later. */
1463 else if ((OP(first) == EXACTF || OP(first) == EXACTFL)
1465 r->regstclass = first;
1467 else if (strchr((char*)PL_simple,OP(first)))
1468 r->regstclass = first;
1469 else if (PL_regkind[(U8)OP(first)] == BOUND ||
1470 PL_regkind[(U8)OP(first)] == NBOUND)
1471 r->regstclass = first;
1472 else if (PL_regkind[(U8)OP(first)] == BOL) {
1473 r->reganch |= (OP(first) == MBOL
1475 : (OP(first) == SBOL
1478 first = NEXTOPER(first);
1481 else if (OP(first) == GPOS) {
1482 r->reganch |= ROPT_ANCH_GPOS;
1483 first = NEXTOPER(first);
1486 else if ((OP(first) == STAR &&
1487 PL_regkind[(U8)OP(NEXTOPER(first))] == REG_ANY) &&
1488 !(r->reganch & ROPT_ANCH) )
1490 /* turn .* into ^.* with an implied $*=1 */
1491 int type = OP(NEXTOPER(first));
1493 if (type == REG_ANY || type == ANYUTF8)
1494 type = ROPT_ANCH_MBOL;
1496 type = ROPT_ANCH_SBOL;
1498 r->reganch |= type | ROPT_IMPLICIT;
1499 first = NEXTOPER(first);
1502 if (sawplus && (!sawopen || !PL_regsawback)
1503 && !(PL_regseen & REG_SEEN_EVAL)) /* May examine pos and $& */
1504 /* x+ must match at the 1st pos of run of x's */
1505 r->reganch |= ROPT_SKIP;
1507 /* Scan is after the zeroth branch, first is atomic matcher. */
1508 DEBUG_r(PerlIO_printf(Perl_debug_log, "first at %"IVdf"\n",
1509 (IV)(first - scan + 1)));
1511 * If there's something expensive in the r.e., find the
1512 * longest literal string that must appear and make it the
1513 * regmust. Resolve ties in favor of later strings, since
1514 * the regstart check works with the beginning of the r.e.
1515 * and avoiding duplication strengthens checking. Not a
1516 * strong reason, but sufficient in the absence of others.
1517 * [Now we resolve ties in favor of the earlier string if
1518 * it happens that c_offset_min has been invalidated, since the
1519 * earlier string may buy us something the later one won't.]
1523 data.longest_fixed = newSVpvn("",0);
1524 data.longest_float = newSVpvn("",0);
1525 data.last_found = newSVpvn("",0);
1526 data.longest = &(data.longest_fixed);
1528 if (!r->regstclass) {
1530 data.start_class = &ch_class;
1531 stclass_flag = SCF_DO_STCLASS_AND;
1532 } else /* XXXX Check for BOUND? */
1535 minlen = study_chunk(&first, &fake, scan + PL_regsize, /* Up to end */
1536 &data, SCF_DO_SUBSTR | stclass_flag);
1537 if ( PL_regnpar == 1 && data.longest == &(data.longest_fixed)
1538 && data.last_start_min == 0 && data.last_end > 0
1540 && (!(PL_regseen & REG_SEEN_GPOS) || (r->reganch & ROPT_ANCH_GPOS)))
1541 r->reganch |= ROPT_CHECK_ALL;
1543 SvREFCNT_dec(data.last_found);
1545 longest_float_length = CHR_SVLEN(data.longest_float);
1546 if (longest_float_length
1547 || (data.flags & SF_FL_BEFORE_EOL
1548 && (!(data.flags & SF_FL_BEFORE_MEOL)
1549 || (PL_regflags & PMf_MULTILINE)))) {
1552 if (SvCUR(data.longest_fixed) /* ok to leave SvCUR */
1553 && data.offset_fixed == data.offset_float_min
1554 && SvCUR(data.longest_fixed) == SvCUR(data.longest_float))
1555 goto remove_float; /* As in (a)+. */
1557 r->float_substr = data.longest_float;
1558 r->float_min_offset = data.offset_float_min;
1559 r->float_max_offset = data.offset_float_max;
1560 t = (data.flags & SF_FL_BEFORE_EOL /* Can't have SEOL and MULTI */
1561 && (!(data.flags & SF_FL_BEFORE_MEOL)
1562 || (PL_regflags & PMf_MULTILINE)));
1563 fbm_compile(r->float_substr, t ? FBMcf_TAIL : 0);
1567 r->float_substr = Nullsv;
1568 SvREFCNT_dec(data.longest_float);
1569 longest_float_length = 0;
1572 longest_fixed_length = CHR_SVLEN(data.longest_fixed);
1573 if (longest_fixed_length
1574 || (data.flags & SF_FIX_BEFORE_EOL /* Cannot have SEOL and MULTI */
1575 && (!(data.flags & SF_FIX_BEFORE_MEOL)
1576 || (PL_regflags & PMf_MULTILINE)))) {
1579 r->anchored_substr = data.longest_fixed;
1580 r->anchored_offset = data.offset_fixed;
1581 t = (data.flags & SF_FIX_BEFORE_EOL /* Can't have SEOL and MULTI */
1582 && (!(data.flags & SF_FIX_BEFORE_MEOL)
1583 || (PL_regflags & PMf_MULTILINE)));
1584 fbm_compile(r->anchored_substr, t ? FBMcf_TAIL : 0);
1587 r->anchored_substr = Nullsv;
1588 SvREFCNT_dec(data.longest_fixed);
1589 longest_fixed_length = 0;
1592 && (OP(r->regstclass) == REG_ANY || OP(r->regstclass) == ANYUTF8
1593 || OP(r->regstclass) == SANYUTF8 || OP(r->regstclass) == SANY))
1594 r->regstclass = NULL;
1595 if ((!r->anchored_substr || r->anchored_offset) && stclass_flag
1596 && !(data.start_class->flags & ANYOF_EOS)
1597 && !cl_is_anything(data.start_class)) {
1599 I32 n = add_data(1, "f");
1601 New(1006, PL_regcomp_rx->data->data[n], 1,
1602 struct regnode_charclass_class);
1603 StructCopy(data.start_class,
1604 (struct regnode_charclass_class*)PL_regcomp_rx->data->data[n],
1605 struct regnode_charclass_class);
1606 r->regstclass = (regnode*)PL_regcomp_rx->data->data[n];
1607 r->reganch &= ~ROPT_SKIP; /* Used in find_byclass(). */
1608 DEBUG_r((sv = sv_newmortal(),
1609 regprop(sv, (regnode*)data.start_class),
1610 PerlIO_printf(Perl_debug_log, "synthetic stclass `%s'.\n",
1614 /* A temporary algorithm prefers floated substr to fixed one to dig more info. */
1615 if (longest_fixed_length > longest_float_length) {
1616 r->check_substr = r->anchored_substr;
1617 r->check_offset_min = r->check_offset_max = r->anchored_offset;
1618 if (r->reganch & ROPT_ANCH_SINGLE)
1619 r->reganch |= ROPT_NOSCAN;
1622 r->check_substr = r->float_substr;
1623 r->check_offset_min = data.offset_float_min;
1624 r->check_offset_max = data.offset_float_max;
1626 /* XXXX Currently intuiting is not compatible with ANCH_GPOS.
1627 This should be changed ASAP! */
1628 if (r->check_substr && !(r->reganch & ROPT_ANCH_GPOS)) {
1629 r->reganch |= RE_USE_INTUIT;
1630 if (SvTAIL(r->check_substr))
1631 r->reganch |= RE_INTUIT_TAIL;
1635 /* Several toplevels. Best we can is to set minlen. */
1637 struct regnode_charclass_class ch_class;
1639 DEBUG_r(PerlIO_printf(Perl_debug_log, "\n"));
1640 scan = r->program + 1;
1642 data.start_class = &ch_class;
1643 minlen = study_chunk(&scan, &fake, scan + PL_regsize, &data, SCF_DO_STCLASS_AND);
1644 r->check_substr = r->anchored_substr = r->float_substr = Nullsv;
1645 if (!(data.start_class->flags & ANYOF_EOS)
1646 && !cl_is_anything(data.start_class)) {
1648 I32 n = add_data(1, "f");
1650 New(1006, PL_regcomp_rx->data->data[n], 1,
1651 struct regnode_charclass_class);
1652 StructCopy(data.start_class,
1653 (struct regnode_charclass_class*)PL_regcomp_rx->data->data[n],
1654 struct regnode_charclass_class);
1655 r->regstclass = (regnode*)PL_regcomp_rx->data->data[n];
1656 r->reganch &= ~ROPT_SKIP; /* Used in find_byclass(). */
1657 DEBUG_r((sv = sv_newmortal(),
1658 regprop(sv, (regnode*)data.start_class),
1659 PerlIO_printf(Perl_debug_log, "synthetic stclass `%s'.\n",
1665 if (PL_regseen & REG_SEEN_GPOS)
1666 r->reganch |= ROPT_GPOS_SEEN;
1667 if (PL_regseen & REG_SEEN_LOOKBEHIND)
1668 r->reganch |= ROPT_LOOKBEHIND_SEEN;
1669 if (PL_regseen & REG_SEEN_EVAL)
1670 r->reganch |= ROPT_EVAL_SEEN;
1671 Newz(1002, r->startp, PL_regnpar, I32);
1672 Newz(1002, r->endp, PL_regnpar, I32);
1673 DEBUG_r(regdump(r));
1678 - reg - regular expression, i.e. main body or parenthesized thing
1680 * Caller must absorb opening parenthesis.
1682 * Combining parenthesis handling with the base level of regular expression
1683 * is a trifle forced, but the need to tie the tails of the branches to what
1684 * follows makes it hard to avoid.
1687 S_reg(pTHX_ I32 paren, I32 *flagp)
1688 /* paren: Parenthesized? 0=top, 1=(, inside: changed to letter. */
1691 register regnode *ret; /* Will be the head of the group. */
1692 register regnode *br;
1693 register regnode *lastbr;
1694 register regnode *ender = 0;
1695 register I32 parno = 0;
1696 I32 flags, oregflags = PL_regflags, have_branch = 0, open = 0;
1699 *flagp = 0; /* Tentatively. */
1701 /* Make an OPEN node, if parenthesized. */
1703 if (*PL_regcomp_parse == '?') {
1704 U16 posflags = 0, negflags = 0;
1705 U16 *flagsp = &posflags;
1709 paren = *PL_regcomp_parse++;
1710 ret = NULL; /* For look-ahead/behind. */
1713 PL_regseen |= REG_SEEN_LOOKBEHIND;
1714 if (*PL_regcomp_parse == '!')
1716 if (*PL_regcomp_parse != '=' && *PL_regcomp_parse != '!')
1727 FAIL2("Sequence (?%c...) not implemented", (int)paren);
1730 while (*PL_regcomp_parse && *PL_regcomp_parse != ')')
1732 if (*PL_regcomp_parse != ')')
1733 FAIL("Sequence (?#... not terminated");
1739 paren = *PL_regcomp_parse++;
1744 I32 count = 1, n = 0;
1746 char *s = PL_regcomp_parse;
1748 OP_4tree *sop, *rop;
1751 PL_regseen |= REG_SEEN_EVAL;
1752 while (count && (c = *PL_regcomp_parse)) {
1753 if (c == '\\' && PL_regcomp_parse[1])
1761 if (*PL_regcomp_parse != ')')
1762 FAIL("Sequence (?{...}) not terminated or not {}-balanced");
1766 if (PL_regcomp_parse - 1 - s)
1767 sv = newSVpvn(s, PL_regcomp_parse - 1 - s);
1769 sv = newSVpvn("", 0);
1771 rop = sv_compile_2op(sv, &sop, "re", &av);
1773 n = add_data(3, "nop");
1774 PL_regcomp_rx->data->data[n] = (void*)rop;
1775 PL_regcomp_rx->data->data[n+1] = (void*)sop;
1776 PL_regcomp_rx->data->data[n+2] = (void*)av;
1779 else { /* First pass */
1780 if (PL_reginterp_cnt < ++PL_seen_evals
1781 && PL_curcop != &PL_compiling)
1782 /* No compiled RE interpolated, has runtime
1783 components ===> unsafe. */
1784 FAIL("Eval-group not allowed at runtime, use re 'eval'");
1786 FAIL("Eval-group in insecure regular expression");
1791 ret = reg_node(LOGICAL);
1794 regtail(ret, reganode(EVAL, n));
1797 return reganode(EVAL, n);
1801 if (PL_regcomp_parse[0] == '?') {
1802 if (PL_regcomp_parse[1] == '=' || PL_regcomp_parse[1] == '!'
1803 || PL_regcomp_parse[1] == '<'
1804 || PL_regcomp_parse[1] == '{') { /* Lookahead or eval. */
1807 ret = reg_node(LOGICAL);
1810 regtail(ret, reg(1, &flag));
1814 else if (PL_regcomp_parse[0] >= '1' && PL_regcomp_parse[0] <= '9' ) {
1815 parno = atoi(PL_regcomp_parse++);
1817 while (isDIGIT(*PL_regcomp_parse))
1819 ret = reganode(GROUPP, parno);
1820 if ((c = *nextchar()) != ')')
1821 FAIL2("Switch (?(number%c not recognized", c);
1823 regtail(ret, reganode(IFTHEN, 0));
1824 br = regbranch(&flags, 1);
1826 br = reganode(LONGJMP, 0);
1828 regtail(br, reganode(LONGJMP, 0));
1833 lastbr = reganode(IFTHEN, 0); /* Fake one for optimizer. */
1834 regbranch(&flags, 1);
1835 regtail(ret, lastbr);
1843 FAIL("Switch (?(condition)... contains too many branches");
1844 ender = reg_node(TAIL);
1847 regtail(lastbr, ender);
1848 regtail(NEXTOPER(NEXTOPER(lastbr)), ender);
1851 regtail(ret, ender);
1855 FAIL2("Unknown condition for (?(%.2s", PL_regcomp_parse);
1859 FAIL("Sequence (? incomplete");
1864 while (*PL_regcomp_parse && strchr("iogcmsx", *PL_regcomp_parse)) {
1865 if (*PL_regcomp_parse != 'o')
1866 pmflag(flagsp, *PL_regcomp_parse);
1869 if (*PL_regcomp_parse == '-') {
1874 PL_regflags |= posflags;
1875 PL_regflags &= ~negflags;
1876 if (*PL_regcomp_parse == ':') {
1882 if (*PL_regcomp_parse != ')')
1883 FAIL2("Sequence (?%c...) not recognized", *PL_regcomp_parse);
1892 ret = reganode(OPEN, parno);
1899 /* Pick up the branches, linking them together. */
1900 br = regbranch(&flags, 1);
1903 if (*PL_regcomp_parse == '|') {
1904 if (!SIZE_ONLY && PL_extralen) {
1905 reginsert(BRANCHJ, br);
1908 reginsert(BRANCH, br);
1911 PL_extralen += 1; /* For BRANCHJ-BRANCH. */
1913 else if (paren == ':') {
1914 *flagp |= flags&SIMPLE;
1916 if (open) { /* Starts with OPEN. */
1917 regtail(ret, br); /* OPEN -> first. */
1919 else if (paren != '?') /* Not Conditional */
1923 *flagp |= flags&SPSTART;
1925 while (*PL_regcomp_parse == '|') {
1926 if (!SIZE_ONLY && PL_extralen) {
1927 ender = reganode(LONGJMP,0);
1928 regtail(NEXTOPER(NEXTOPER(lastbr)), ender); /* Append to the previous. */
1931 PL_extralen += 2; /* Account for LONGJMP. */
1933 br = regbranch(&flags, 0);
1936 regtail(lastbr, br); /* BRANCH -> BRANCH. */
1940 *flagp |= flags&SPSTART;
1943 if (have_branch || paren != ':') {
1944 /* Make a closing node, and hook it on the end. */
1947 ender = reg_node(TAIL);
1950 ender = reganode(CLOSE, parno);
1956 *flagp &= ~HASWIDTH;
1959 ender = reg_node(SUCCEED);
1962 ender = reg_node(END);
1965 regtail(lastbr, ender);
1968 /* Hook the tails of the branches to the closing node. */
1969 for (br = ret; br != NULL; br = regnext(br)) {
1970 regoptail(br, ender);
1977 static char parens[] = "=!<,>";
1979 if (paren && (p = strchr(parens, paren))) {
1980 int node = ((p - parens) % 2) ? UNLESSM : IFMATCH;
1981 int flag = (p - parens) > 1;
1984 node = SUSPEND, flag = 0;
1985 reginsert(node,ret);
1987 regtail(ret, reg_node(TAIL));
1991 /* Check for proper termination. */
1993 PL_regflags = oregflags;
1994 if (PL_regcomp_parse >= PL_regxend || *nextchar() != ')') {
1995 FAIL("unmatched () in regexp");
1998 else if (!paren && PL_regcomp_parse < PL_regxend) {
1999 if (*PL_regcomp_parse == ')') {
2000 FAIL("unmatched () in regexp");
2003 FAIL("junk on end of regexp"); /* "Can't happen". */
2011 - regbranch - one alternative of an | operator
2013 * Implements the concatenation operator.
2016 S_regbranch(pTHX_ I32 *flagp, I32 first)
2019 register regnode *ret;
2020 register regnode *chain = NULL;
2021 register regnode *latest;
2022 I32 flags = 0, c = 0;
2027 if (!SIZE_ONLY && PL_extralen)
2028 ret = reganode(BRANCHJ,0);
2030 ret = reg_node(BRANCH);
2033 if (!first && SIZE_ONLY)
2034 PL_extralen += 1; /* BRANCHJ */
2036 *flagp = WORST; /* Tentatively. */
2040 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != '|' && *PL_regcomp_parse != ')') {
2042 latest = regpiece(&flags);
2043 if (latest == NULL) {
2044 if (flags & TRYAGAIN)
2048 else if (ret == NULL)
2050 *flagp |= flags&HASWIDTH;
2051 if (chain == NULL) /* First piece. */
2052 *flagp |= flags&SPSTART;
2055 regtail(chain, latest);
2060 if (chain == NULL) { /* Loop ran zero times. */
2061 chain = reg_node(NOTHING);
2066 *flagp |= flags&SIMPLE;
2073 - regpiece - something followed by possible [*+?]
2075 * Note that the branching code sequences used for ? and the general cases
2076 * of * and + are somewhat optimized: they use the same NOTHING node as
2077 * both the endmarker for their branch list and the body of the last branch.
2078 * It might seem that this node could be dispensed with entirely, but the
2079 * endmarker role is not redundant.
2082 S_regpiece(pTHX_ I32 *flagp)
2085 register regnode *ret;
2087 register char *next;
2089 char *origparse = PL_regcomp_parse;
2092 I32 max = REG_INFTY;
2094 ret = regatom(&flags);
2096 if (flags & TRYAGAIN)
2101 op = *PL_regcomp_parse;
2103 if (op == '{' && regcurly(PL_regcomp_parse)) {
2104 next = PL_regcomp_parse + 1;
2106 while (isDIGIT(*next) || *next == ',') {
2115 if (*next == '}') { /* got one */
2119 min = atoi(PL_regcomp_parse);
2123 maxpos = PL_regcomp_parse;
2125 if (!max && *maxpos != '0')
2126 max = REG_INFTY; /* meaning "infinity" */
2127 else if (max >= REG_INFTY)
2128 FAIL2("Quantifier in {,} bigger than %d", REG_INFTY - 1);
2129 PL_regcomp_parse = next;
2133 if ((flags&SIMPLE)) {
2134 PL_regnaughty += 2 + PL_regnaughty / 2;
2135 reginsert(CURLY, ret);
2138 regnode *w = reg_node(WHILEM);
2142 if (!SIZE_ONLY && PL_extralen) {
2143 reginsert(LONGJMP,ret);
2144 reginsert(NOTHING,ret);
2145 NEXT_OFF(ret) = 3; /* Go over LONGJMP. */
2147 reginsert(CURLYX,ret);
2148 if (!SIZE_ONLY && PL_extralen)
2149 NEXT_OFF(ret) = 3; /* Go over NOTHING to LONGJMP. */
2150 regtail(ret, reg_node(NOTHING));
2152 PL_reg_whilem_seen++, PL_extralen += 3;
2153 PL_regnaughty += 4 + PL_regnaughty; /* compound interest */
2161 if (max && max < min)
2162 FAIL("Can't do {n,m} with n > m");
2177 #if 0 /* Now runtime fix should be reliable. */
2178 if (!(flags&HASWIDTH) && op != '?')
2179 FAIL("regexp *+ operand could be empty");
2184 *flagp = (op != '+') ? (WORST|SPSTART|HASWIDTH) : (WORST|HASWIDTH);
2186 if (op == '*' && (flags&SIMPLE)) {
2187 reginsert(STAR, ret);
2191 else if (op == '*') {
2195 else if (op == '+' && (flags&SIMPLE)) {
2196 reginsert(PLUS, ret);
2200 else if (op == '+') {
2204 else if (op == '?') {
2209 if (ckWARN(WARN_REGEXP) && !SIZE_ONLY && !(flags&HASWIDTH) && max > REG_INFTY/3) {
2210 Perl_warner(aTHX_ WARN_REGEXP, "%.*s matches null string many times",
2211 PL_regcomp_parse - origparse, origparse);
2214 if (*PL_regcomp_parse == '?') {
2216 reginsert(MINMOD, ret);
2217 regtail(ret, ret + NODE_STEP_REGNODE);
2219 if (ISMULT2(PL_regcomp_parse))
2220 FAIL("nested *?+ in regexp");
2226 - regatom - the lowest level
2228 * Optimization: gobbles an entire sequence of ordinary characters so that
2229 * it can turn them into a single node, which is smaller to store and
2230 * faster to run. Backslashed characters are exceptions, each becoming a
2231 * separate node; the code is simpler that way and it's not worth fixing.
2233 * [Yes, it is worth fixing, some scripts can run twice the speed.]
2236 S_regatom(pTHX_ I32 *flagp)
2239 register regnode *ret = 0;
2242 *flagp = WORST; /* Tentatively. */
2245 switch (*PL_regcomp_parse) {
2249 if (PL_regflags & PMf_MULTILINE)
2250 ret = reg_node(MBOL);
2251 else if (PL_regflags & PMf_SINGLELINE)
2252 ret = reg_node(SBOL);
2254 ret = reg_node(BOL);
2257 if (PL_regcomp_parse[1])
2260 if (PL_regflags & PMf_MULTILINE)
2261 ret = reg_node(MEOL);
2262 else if (PL_regflags & PMf_SINGLELINE)
2263 ret = reg_node(SEOL);
2265 ret = reg_node(EOL);
2270 if (PL_regflags & PMf_SINGLELINE)
2271 ret = reg_node(SANYUTF8);
2273 ret = reg_node(ANYUTF8);
2277 if (PL_regflags & PMf_SINGLELINE)
2278 ret = reg_node(SANY);
2280 ret = reg_node(REG_ANY);
2281 *flagp |= HASWIDTH|SIMPLE;
2287 ret = (UTF ? regclassutf8() : regclass());
2288 if (*PL_regcomp_parse != ']')
2289 FAIL("unmatched [] in regexp");
2291 *flagp |= HASWIDTH|SIMPLE;
2295 ret = reg(1, &flags);
2297 if (flags & TRYAGAIN)
2301 *flagp |= flags&(HASWIDTH|SPSTART|SIMPLE);
2305 if (flags & TRYAGAIN) {
2309 FAIL2("internal urp in regexp at /%s/", PL_regcomp_parse);
2310 /* Supposed to be caught earlier. */
2313 if (!regcurly(PL_regcomp_parse)) {
2321 FAIL("?+*{} follows nothing in regexp");
2324 switch (*++PL_regcomp_parse) {
2327 ret = reg_node(SBOL);
2332 ret = reg_node(GPOS);
2333 PL_regseen |= REG_SEEN_GPOS;
2338 ret = reg_node(SEOL);
2343 ret = reg_node(EOS);
2345 PL_seen_zerolen++; /* Do not optimize RE away */
2349 ret = reg_node(SANY);
2350 *flagp |= HASWIDTH|SIMPLE;
2354 ret = reg_node(CLUMP);
2357 if (UTF && !PL_utf8_mark)
2358 is_utf8_mark((U8*)"~"); /* preload table */
2363 ? (LOC ? ALNUMLUTF8 : ALNUMUTF8)
2364 : (LOC ? ALNUML : ALNUM));
2365 *flagp |= HASWIDTH|SIMPLE;
2367 if (UTF && !PL_utf8_alnum)
2368 is_utf8_alnum((U8*)"a"); /* preload table */
2373 ? (LOC ? NALNUMLUTF8 : NALNUMUTF8)
2374 : (LOC ? NALNUML : NALNUM));
2375 *flagp |= HASWIDTH|SIMPLE;
2377 if (UTF && !PL_utf8_alnum)
2378 is_utf8_alnum((U8*)"a"); /* preload table */
2382 PL_regseen |= REG_SEEN_LOOKBEHIND;
2385 ? (LOC ? BOUNDLUTF8 : BOUNDUTF8)
2386 : (LOC ? BOUNDL : BOUND));
2389 if (UTF && !PL_utf8_alnum)
2390 is_utf8_alnum((U8*)"a"); /* preload table */
2394 PL_regseen |= REG_SEEN_LOOKBEHIND;
2397 ? (LOC ? NBOUNDLUTF8 : NBOUNDUTF8)
2398 : (LOC ? NBOUNDL : NBOUND));
2401 if (UTF && !PL_utf8_alnum)
2402 is_utf8_alnum((U8*)"a"); /* preload table */
2407 ? (LOC ? SPACELUTF8 : SPACEUTF8)
2408 : (LOC ? SPACEL : SPACE));
2409 *flagp |= HASWIDTH|SIMPLE;
2411 if (UTF && !PL_utf8_space)
2412 is_utf8_space((U8*)" "); /* preload table */
2417 ? (LOC ? NSPACELUTF8 : NSPACEUTF8)
2418 : (LOC ? NSPACEL : NSPACE));
2419 *flagp |= HASWIDTH|SIMPLE;
2421 if (UTF && !PL_utf8_space)
2422 is_utf8_space((U8*)" "); /* preload table */
2425 ret = reg_node(UTF ? DIGITUTF8 : DIGIT);
2426 *flagp |= HASWIDTH|SIMPLE;
2428 if (UTF && !PL_utf8_digit)
2429 is_utf8_digit((U8*)"1"); /* preload table */
2432 ret = reg_node(UTF ? NDIGITUTF8 : NDIGIT);
2433 *flagp |= HASWIDTH|SIMPLE;
2435 if (UTF && !PL_utf8_digit)
2436 is_utf8_digit((U8*)"1"); /* preload table */
2440 { /* a lovely hack--pretend we saw [\pX] instead */
2441 char* oldregxend = PL_regxend;
2443 if (PL_regcomp_parse[1] == '{') {
2444 PL_regxend = strchr(PL_regcomp_parse, '}');
2446 FAIL("Missing right brace on \\p{}");
2450 PL_regxend = PL_regcomp_parse + 2;
2453 ret = regclassutf8();
2455 PL_regxend = oldregxend;
2458 *flagp |= HASWIDTH|SIMPLE;
2471 case '1': case '2': case '3': case '4':
2472 case '5': case '6': case '7': case '8': case '9':
2474 I32 num = atoi(PL_regcomp_parse);
2476 if (num > 9 && num >= PL_regnpar)
2479 if (!SIZE_ONLY && num > PL_regcomp_rx->nparens)
2480 FAIL("reference to nonexistent group");
2483 ? (LOC ? REFFL : REFF)
2486 while (isDIGIT(*PL_regcomp_parse))
2494 if (PL_regcomp_parse >= PL_regxend)
2495 FAIL("trailing \\ in regexp");
2498 /* Do not generate `unrecognized' warnings here, we fall
2499 back into the quick-grab loop below */
2505 if (PL_regflags & PMf_EXTENDED) {
2506 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != '\n') PL_regcomp_parse++;
2507 if (PL_regcomp_parse < PL_regxend)
2523 ? (LOC ? EXACTFL : EXACTF)
2526 for (len = 0, p = PL_regcomp_parse - 1;
2527 len < 127 && p < PL_regxend;
2532 if (PL_regflags & PMf_EXTENDED)
2533 p = regwhite(p, PL_regxend);
2595 char* e = strchr(p, '}');
2598 FAIL("Missing right brace on \\x{}");
2600 ender = (UV)scan_hex(p + 1, e - p, &numlen);
2601 if (numlen + len >= 127) { /* numlen is generous */
2608 FAIL("Can't use \\x{} without 'use utf8' declaration");
2611 ender = (UV)scan_hex(p, 2, &numlen);
2617 ender = UCHARAT(p++);
2618 ender = toCTRL(ender);
2620 case '0': case '1': case '2': case '3':case '4':
2621 case '5': case '6': case '7': case '8':case '9':
2623 (isDIGIT(p[1]) && atoi(p) >= PL_regnpar) ) {
2624 ender = (UV)scan_oct(p, 3, &numlen);
2633 if (p >= PL_regxend)
2634 FAIL("trailing \\ in regexp");
2637 if (!SIZE_ONLY && ckWARN(WARN_REGEXP) && isALPHA(*p))
2638 Perl_warner(aTHX_ WARN_REGEXP,
2639 "/%.127s/: Unrecognized escape \\%c passed through",
2642 goto normal_default;
2647 if ((*p & 0xc0) == 0xc0 && UTF) {
2648 ender = utf8_to_uv((U8*)p, &numlen);
2655 if (PL_regflags & PMf_EXTENDED)
2656 p = regwhite(p, PL_regxend);
2659 ender = toLOWER_LC_uni(ender);
2661 ender = toLOWER_uni(ender);
2663 if (ISMULT2(p)) { /* Back off on ?+*. */
2666 else if (ender >= 0x80 && UTF) {
2667 reguni(ender, s, &numlen);
2677 if (ender >= 0x80 && UTF) {
2678 reguni(ender, s, &numlen);
2686 PL_regcomp_parse = p - 1;
2689 FAIL("internal disaster in regexp");
2697 PL_regsize += STR_SZ(len);
2699 PL_regcode += STR_SZ(len);
2708 S_regwhite(pTHX_ char *p, char *e)
2713 else if (*p == '#') {
2716 } while (p < e && *p != '\n');
2724 /* Parse POSIX character classes: [[:foo:]], [[=foo=]], [[.foo.]].
2725 Character classes ([:foo:]) can also be negated ([:^foo:]).
2726 Returns a named class id (ANYOF_XXX) if successful, -1 otherwise.
2727 Equivalence classes ([=foo=]) and composites ([.foo.]) are parsed,
2728 but trigger warnings because they are currently unimplemented. */
2730 S_regpposixcc(pTHX_ I32 value)
2734 I32 namedclass = OOB_NAMEDCLASS;
2736 if (value == '[' && PL_regcomp_parse + 1 < PL_regxend &&
2737 /* I smell either [: or [= or [. -- POSIX has been here, right? */
2738 (*PL_regcomp_parse == ':' ||
2739 *PL_regcomp_parse == '=' ||
2740 *PL_regcomp_parse == '.')) {
2741 char c = *PL_regcomp_parse;
2742 char* s = PL_regcomp_parse++;
2744 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != c)
2746 if (PL_regcomp_parse == PL_regxend)
2747 /* Grandfather lone [:, [=, [. */
2748 PL_regcomp_parse = s;
2750 char* t = PL_regcomp_parse++; /* skip over the c */
2752 if (*PL_regcomp_parse == ']') {
2753 PL_regcomp_parse++; /* skip over the ending ] */
2756 I32 complement = *posixcc == '^' ? *posixcc++ : 0;
2757 I32 skip = 5; /* the most common skip */
2761 if (strnEQ(posixcc, "alnum", 5))
2763 complement ? ANYOF_NALNUMC : ANYOF_ALNUMC;
2764 else if (strnEQ(posixcc, "alpha", 5))
2766 complement ? ANYOF_NALPHA : ANYOF_ALPHA;
2767 else if (strnEQ(posixcc, "ascii", 5))
2769 complement ? ANYOF_NASCII : ANYOF_ASCII;
2772 if (strnEQ(posixcc, "cntrl", 5))
2774 complement ? ANYOF_NCNTRL : ANYOF_CNTRL;
2777 if (strnEQ(posixcc, "digit", 5))
2779 complement ? ANYOF_NDIGIT : ANYOF_DIGIT;
2782 if (strnEQ(posixcc, "graph", 5))
2784 complement ? ANYOF_NGRAPH : ANYOF_GRAPH;
2787 if (strnEQ(posixcc, "lower", 5))
2789 complement ? ANYOF_NLOWER : ANYOF_LOWER;
2792 if (strnEQ(posixcc, "print", 5))
2794 complement ? ANYOF_NPRINT : ANYOF_PRINT;
2795 else if (strnEQ(posixcc, "punct", 5))
2797 complement ? ANYOF_NPUNCT : ANYOF_PUNCT;
2800 if (strnEQ(posixcc, "space", 5))
2802 complement ? ANYOF_NSPACE : ANYOF_SPACE;
2804 if (strnEQ(posixcc, "upper", 5))
2806 complement ? ANYOF_NUPPER : ANYOF_UPPER;
2808 case 'w': /* this is not POSIX, this is the Perl \w */
2809 if (strnEQ(posixcc, "word", 4)) {
2811 complement ? ANYOF_NALNUM : ANYOF_ALNUM;
2816 if (strnEQ(posixcc, "xdigit", 6)) {
2818 complement ? ANYOF_NXDIGIT : ANYOF_XDIGIT;
2823 if (namedclass == OOB_NAMEDCLASS ||
2824 posixcc[skip] != ':' ||
2825 posixcc[skip+1] != ']')
2827 "Character class [:%.*s:] unknown",
2829 } else if (ckWARN(WARN_REGEXP) && !SIZE_ONLY)
2830 /* [[=foo=]] and [[.foo.]] are still future. */
2831 Perl_warner(aTHX_ WARN_REGEXP,
2832 "Character class syntax [%c %c] is reserved for future extensions", c, c);
2834 /* Maternal grandfather:
2835 * "[:" ending in ":" but not in ":]" */
2836 PL_regcomp_parse = s;
2845 S_checkposixcc(pTHX)
2847 if (!SIZE_ONLY && ckWARN(WARN_REGEXP) &&
2848 (*PL_regcomp_parse == ':' ||
2849 *PL_regcomp_parse == '=' ||
2850 *PL_regcomp_parse == '.')) {
2851 char *s = PL_regcomp_parse;
2854 while(*s && isALNUM(*s))
2856 if (*s && c == *s && s[1] == ']') {
2857 Perl_warner(aTHX_ WARN_REGEXP,
2858 "Character class syntax [%c %c] belongs inside character classes", c, c);
2859 if (c == '=' || c == '.')
2860 Perl_warner(aTHX_ WARN_REGEXP,
2861 "Character class syntax [%c %c] is reserved for future extensions", c, c);
2871 register I32 lastvalue = OOB_CHAR8;
2872 register I32 range = 0;
2873 register regnode *ret;
2878 bool need_class = 0;
2880 ret = reg_node(ANYOF);
2882 PL_regsize += ANYOF_SKIP;
2885 ANYOF_BITMAP_ZERO(ret);
2886 PL_regcode += ANYOF_SKIP;
2888 ANYOF_FLAGS(ret) |= ANYOF_FOLD;
2890 ANYOF_FLAGS(ret) |= ANYOF_LOCALE;
2892 if (*PL_regcomp_parse == '^') { /* Complement of range. */
2896 ANYOF_FLAGS(ret) |= ANYOF_INVERT;
2899 if (!SIZE_ONLY && ckWARN(WARN_REGEXP))
2902 if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
2903 goto skipcond; /* allow 1st char to be ] or - */
2904 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != ']') {
2906 namedclass = OOB_NAMEDCLASS;
2908 rangebegin = PL_regcomp_parse;
2909 value = UCHARAT(PL_regcomp_parse++);
2911 namedclass = regpposixcc(value);
2912 else if (value == '\\') {
2913 value = UCHARAT(PL_regcomp_parse++);
2914 /* Some compilers cannot handle switching on 64-bit integer
2915 * values, therefore value cannot be an UV. --jhi */
2917 case 'w': namedclass = ANYOF_ALNUM; break;
2918 case 'W': namedclass = ANYOF_NALNUM; break;
2919 case 's': namedclass = ANYOF_SPACE; break;
2920 case 'S': namedclass = ANYOF_NSPACE; break;
2921 case 'd': namedclass = ANYOF_DIGIT; break;
2922 case 'D': namedclass = ANYOF_NDIGIT; break;
2923 case 'n': value = '\n'; break;
2924 case 'r': value = '\r'; break;
2925 case 't': value = '\t'; break;
2926 case 'f': value = '\f'; break;
2927 case 'b': value = '\b'; break;
2929 case 'e': value = '\033'; break;
2930 case 'a': value = '\007'; break;
2932 case 'e': value = '\047'; break;
2933 case 'a': value = '\057'; break;
2936 value = (UV)scan_hex(PL_regcomp_parse, 2, &numlen);
2937 PL_regcomp_parse += numlen;
2940 value = UCHARAT(PL_regcomp_parse++);
2941 value = toCTRL(value);
2943 case '0': case '1': case '2': case '3': case '4':
2944 case '5': case '6': case '7': case '8': case '9':
2945 value = (UV)scan_oct(--PL_regcomp_parse, 3, &numlen);
2946 PL_regcomp_parse += numlen;
2949 if (!SIZE_ONLY && ckWARN(WARN_REGEXP) && isALPHA(value))
2950 Perl_warner(aTHX_ WARN_REGEXP,
2951 "/%.127s/: Unrecognized escape \\%c in character class passed through",
2957 if (namedclass > OOB_NAMEDCLASS) {
2958 if (!need_class && !SIZE_ONLY)
2959 ANYOF_CLASS_ZERO(ret);
2961 if (range) { /* a-\d, a-[:digit:] */
2963 if (ckWARN(WARN_REGEXP))
2964 Perl_warner(aTHX_ WARN_REGEXP,
2965 "/%.127s/: false [] range \"%*.*s\" in regexp",
2967 PL_regcomp_parse - rangebegin,
2968 PL_regcomp_parse - rangebegin,
2970 ANYOF_BITMAP_SET(ret, lastvalue);
2971 ANYOF_BITMAP_SET(ret, '-');
2973 range = 0; /* this is not a true range */
2976 switch (namedclass) {
2979 ANYOF_CLASS_SET(ret, ANYOF_ALNUM);
2981 for (value = 0; value < 256; value++)
2983 ANYOF_BITMAP_SET(ret, value);
2988 ANYOF_CLASS_SET(ret, ANYOF_NALNUM);
2990 for (value = 0; value < 256; value++)
2991 if (!isALNUM(value))
2992 ANYOF_BITMAP_SET(ret, value);
2997 ANYOF_CLASS_SET(ret, ANYOF_SPACE);
2999 for (value = 0; value < 256; value++)
3001 ANYOF_BITMAP_SET(ret, value);
3006 ANYOF_CLASS_SET(ret, ANYOF_NSPACE);
3008 for (value = 0; value < 256; value++)
3009 if (!isSPACE(value))
3010 ANYOF_BITMAP_SET(ret, value);
3015 ANYOF_CLASS_SET(ret, ANYOF_DIGIT);
3017 for (value = '0'; value <= '9'; value++)
3018 ANYOF_BITMAP_SET(ret, value);
3023 ANYOF_CLASS_SET(ret, ANYOF_NDIGIT);
3025 for (value = 0; value < '0'; value++)
3026 ANYOF_BITMAP_SET(ret, value);
3027 for (value = '9' + 1; value < 256; value++)
3028 ANYOF_BITMAP_SET(ret, value);
3033 ANYOF_CLASS_SET(ret, ANYOF_NALNUMC);
3035 for (value = 0; value < 256; value++)
3036 if (!isALNUMC(value))
3037 ANYOF_BITMAP_SET(ret, value);
3042 ANYOF_CLASS_SET(ret, ANYOF_ALNUMC);
3044 for (value = 0; value < 256; value++)
3045 if (isALNUMC(value))
3046 ANYOF_BITMAP_SET(ret, value);
3051 ANYOF_CLASS_SET(ret, ANYOF_ALPHA);
3053 for (value = 0; value < 256; value++)
3055 ANYOF_BITMAP_SET(ret, value);
3060 ANYOF_CLASS_SET(ret, ANYOF_NALPHA);
3062 for (value = 0; value < 256; value++)
3063 if (!isALPHA(value))
3064 ANYOF_BITMAP_SET(ret, value);
3069 ANYOF_CLASS_SET(ret, ANYOF_ASCII);
3072 for (value = 0; value < 128; value++)
3073 ANYOF_BITMAP_SET(ret, value);
3075 for (value = 0; value < 256; value++)
3077 ANYOF_BITMAP_SET(ret, value);
3083 ANYOF_CLASS_SET(ret, ANYOF_NASCII);
3086 for (value = 128; value < 256; value++)
3087 ANYOF_BITMAP_SET(ret, value);
3089 for (value = 0; value < 256; value++)
3090 if (!isASCII(value))
3091 ANYOF_BITMAP_SET(ret, value);
3097 ANYOF_CLASS_SET(ret, ANYOF_CNTRL);
3099 for (value = 0; value < 256; value++)
3101 ANYOF_BITMAP_SET(ret, value);
3103 lastvalue = OOB_CHAR8;
3107 ANYOF_CLASS_SET(ret, ANYOF_NCNTRL);
3109 for (value = 0; value < 256; value++)
3110 if (!isCNTRL(value))
3111 ANYOF_BITMAP_SET(ret, value);
3116 ANYOF_CLASS_SET(ret, ANYOF_GRAPH);
3118 for (value = 0; value < 256; value++)
3120 ANYOF_BITMAP_SET(ret, value);
3125 ANYOF_CLASS_SET(ret, ANYOF_NGRAPH);
3127 for (value = 0; value < 256; value++)
3128 if (!isGRAPH(value))
3129 ANYOF_BITMAP_SET(ret, value);
3134 ANYOF_CLASS_SET(ret, ANYOF_LOWER);
3136 for (value = 0; value < 256; value++)
3138 ANYOF_BITMAP_SET(ret, value);
3143 ANYOF_CLASS_SET(ret, ANYOF_NLOWER);
3145 for (value = 0; value < 256; value++)
3146 if (!isLOWER(value))
3147 ANYOF_BITMAP_SET(ret, value);
3152 ANYOF_CLASS_SET(ret, ANYOF_PRINT);
3154 for (value = 0; value < 256; value++)
3156 ANYOF_BITMAP_SET(ret, value);
3161 ANYOF_CLASS_SET(ret, ANYOF_NPRINT);
3163 for (value = 0; value < 256; value++)
3164 if (!isPRINT(value))
3165 ANYOF_BITMAP_SET(ret, value);
3170 ANYOF_CLASS_SET(ret, ANYOF_PUNCT);
3172 for (value = 0; value < 256; value++)
3174 ANYOF_BITMAP_SET(ret, value);
3179 ANYOF_CLASS_SET(ret, ANYOF_NPUNCT);
3181 for (value = 0; value < 256; value++)
3182 if (!isPUNCT(value))
3183 ANYOF_BITMAP_SET(ret, value);
3188 ANYOF_CLASS_SET(ret, ANYOF_UPPER);
3190 for (value = 0; value < 256; value++)
3192 ANYOF_BITMAP_SET(ret, value);
3197 ANYOF_CLASS_SET(ret, ANYOF_NUPPER);
3199 for (value = 0; value < 256; value++)
3200 if (!isUPPER(value))
3201 ANYOF_BITMAP_SET(ret, value);
3206 ANYOF_CLASS_SET(ret, ANYOF_XDIGIT);
3208 for (value = 0; value < 256; value++)
3209 if (isXDIGIT(value))
3210 ANYOF_BITMAP_SET(ret, value);
3215 ANYOF_CLASS_SET(ret, ANYOF_NXDIGIT);
3217 for (value = 0; value < 256; value++)
3218 if (!isXDIGIT(value))
3219 ANYOF_BITMAP_SET(ret, value);
3223 FAIL("invalid [::] class in regexp");
3227 ANYOF_FLAGS(ret) |= ANYOF_CLASS;
3232 if (lastvalue > value) /* b-a */ {
3234 "/%.127s/: invalid [] range \"%*.*s\" in regexp",
3236 PL_regcomp_parse - rangebegin,
3237 PL_regcomp_parse - rangebegin,
3244 if (*PL_regcomp_parse == '-' && PL_regcomp_parse+1 < PL_regxend &&
3245 PL_regcomp_parse[1] != ']') {
3247 if (namedclass > OOB_NAMEDCLASS) { /* \w-, [:word:]- */
3248 if (ckWARN(WARN_REGEXP))
3249 Perl_warner(aTHX_ WARN_REGEXP,
3250 "/%.127s/: false [] range \"%*.*s\" in regexp",
3252 PL_regcomp_parse - rangebegin,
3253 PL_regcomp_parse - rangebegin,
3256 ANYOF_BITMAP_SET(ret, '-');
3259 continue; /* do it next time */
3262 /* now is the next time */
3264 #ifndef ASCIIish /* EBCDIC, for example. */
3265 if ((isLOWER(lastvalue) && isLOWER(value)) ||
3266 (isUPPER(lastvalue) && isUPPER(value)))
3269 if (isLOWER(lastvalue)) {
3270 for (i = lastvalue; i <= value; i++)
3272 ANYOF_BITMAP_SET(ret, i);
3274 for (i = lastvalue; i <= value; i++)
3276 ANYOF_BITMAP_SET(ret, i);
3281 for ( ; lastvalue <= value; lastvalue++)
3282 ANYOF_BITMAP_SET(ret, lastvalue);
3288 PL_regsize += ANYOF_CLASS_ADD_SKIP;
3290 PL_regcode += ANYOF_CLASS_ADD_SKIP;
3292 /* optimize case-insensitive simple patterns (e.g. /[a-z]/i) */
3294 (ANYOF_FLAGS(ret) & (ANYOF_FLAGS_ALL ^ ANYOF_INVERT)) == ANYOF_FOLD) {
3295 for (value = 0; value < 256; ++value) {
3296 if (ANYOF_BITMAP_TEST(ret, value)) {
3297 I32 cf = PL_fold[value];
3298 ANYOF_BITMAP_SET(ret, cf);
3301 ANYOF_FLAGS(ret) &= ~ANYOF_FOLD;
3303 /* optimize inverted simple patterns (e.g. [^a-z]) */
3304 if (!SIZE_ONLY && (ANYOF_FLAGS(ret) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
3305 for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
3306 ANYOF_BITMAP(ret)[value] ^= ANYOF_FLAGS_ALL;
3307 ANYOF_FLAGS(ret) = 0;
3313 S_regclassutf8(pTHX)
3318 register U32 lastvalue = OOB_UTF8;
3319 register I32 range = 0;
3320 register regnode *ret;
3328 if (*PL_regcomp_parse == '^') { /* Complement of range. */
3332 flags |= ANYOF_INVERT;
3336 flags |= ANYOF_FOLD;
3338 flags |= ANYOF_LOCALE;
3339 listsv = newSVpvn("# comment\n",10);
3342 if (!SIZE_ONLY && ckWARN(WARN_REGEXP))
3345 if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
3346 goto skipcond; /* allow 1st char to be ] or - */
3348 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != ']') {
3350 namedclass = OOB_NAMEDCLASS;
3352 rangebegin = PL_regcomp_parse;
3353 value = utf8_to_uv((U8*)PL_regcomp_parse, &numlen);
3354 PL_regcomp_parse += numlen;
3356 namedclass = regpposixcc(value);
3357 else if (value == '\\') {
3358 value = (U32)utf8_to_uv((U8*)PL_regcomp_parse, &numlen);
3359 PL_regcomp_parse += numlen;
3360 /* Some compilers cannot handle switching on 64-bit integer
3361 * values, therefore value cannot be an UV. Yes, this will
3362 * be a problem later if we want switch on Unicode. --jhi */
3364 case 'w': namedclass = ANYOF_ALNUM; break;
3365 case 'W': namedclass = ANYOF_NALNUM; break;
3366 case 's': namedclass = ANYOF_SPACE; break;
3367 case 'S': namedclass = ANYOF_NSPACE; break;
3368 case 'd': namedclass = ANYOF_DIGIT; break;
3369 case 'D': namedclass = ANYOF_NDIGIT; break;
3372 if (*PL_regcomp_parse == '{') {
3373 e = strchr(PL_regcomp_parse++, '}');
3375 FAIL("Missing right brace on \\p{}");
3376 n = e - PL_regcomp_parse;
3379 e = PL_regcomp_parse;
3384 Perl_sv_catpvf(aTHX_ listsv,
3385 "+utf8::%.*s\n", (int)n, PL_regcomp_parse);
3387 Perl_sv_catpvf(aTHX_ listsv,
3388 "!utf8::%.*s\n", (int)n, PL_regcomp_parse);
3390 PL_regcomp_parse = e + 1;
3391 lastvalue = OOB_UTF8;
3393 case 'n': value = '\n'; break;
3394 case 'r': value = '\r'; break;
3395 case 't': value = '\t'; break;
3396 case 'f': value = '\f'; break;
3397 case 'b': value = '\b'; break;
3399 case 'e': value = '\033'; break;
3400 case 'a': value = '\007'; break;
3402 case 'e': value = '\047'; break;
3403 case 'a': value = '\057'; break;
3406 if (*PL_regcomp_parse == '{') {
3407 e = strchr(PL_regcomp_parse++, '}');
3409 FAIL("Missing right brace on \\x{}");
3410 value = (UV)scan_hex(PL_regcomp_parse,
3411 e - PL_regcomp_parse,
3413 PL_regcomp_parse = e + 1;
3416 value = (UV)scan_hex(PL_regcomp_parse, 2, &numlen);
3417 PL_regcomp_parse += numlen;
3421 value = UCHARAT(PL_regcomp_parse++);
3422 value = toCTRL(value);
3424 case '0': case '1': case '2': case '3': case '4':
3425 case '5': case '6': case '7': case '8': case '9':
3426 value = (UV)scan_oct(--PL_regcomp_parse, 3, &numlen);
3427 PL_regcomp_parse += numlen;
3430 if (!SIZE_ONLY && ckWARN(WARN_REGEXP) && isALPHA(value))
3431 Perl_warner(aTHX_ WARN_REGEXP,
3432 "/%.127s/: Unrecognized escape \\%c in character class passed through",
3438 if (namedclass > OOB_NAMEDCLASS) {
3439 if (range) { /* a-\d, a-[:digit:] */
3441 if (ckWARN(WARN_REGEXP))
3442 Perl_warner(aTHX_ WARN_REGEXP,
3443 "/%.127s/: false [] range \"%*.*s\" in regexp",
3445 PL_regcomp_parse - rangebegin,
3446 PL_regcomp_parse - rangebegin,
3448 Perl_sv_catpvf(aTHX_ listsv,
3449 /* 0x002D is Unicode for '-' */
3450 "%04"UVxf"\n002D\n", (UV)lastvalue);
3455 switch (namedclass) {
3457 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsWord\n"); break;
3459 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsWord\n"); break;
3461 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsAlnum\n"); break;
3463 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsAlnum\n"); break;
3465 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsAlpha\n"); break;
3467 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsAlpha\n"); break;
3469 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsASCII\n"); break;
3471 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsASCII\n"); break;
3473 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsCntrl\n"); break;
3475 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsCntrl\n"); break;
3477 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsGraph\n"); break;
3479 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsGraph\n"); break;
3481 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsDigit\n"); break;
3483 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsDigit\n"); break;
3485 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsLower\n"); break;
3487 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsLower\n"); break;
3489 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsPrint\n"); break;
3491 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsPrint\n"); break;
3493 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsPunct\n"); break;
3495 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsPunct\n"); break;
3497 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsSpace\n"); break;
3499 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsSpace\n"); break;
3501 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsUpper\n"); break;
3503 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsUpper\n"); break;
3505 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsXDigit\n"); break;
3507 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsXDigit\n"); break;
3513 if (lastvalue > value) { /* b-a */
3515 "/%.127s/: invalid [] range \"%*.*s\" in regexp",
3517 PL_regcomp_parse - rangebegin,
3518 PL_regcomp_parse - rangebegin,
3525 if (*PL_regcomp_parse == '-' && PL_regcomp_parse+1 < PL_regxend &&
3526 PL_regcomp_parse[1] != ']') {
3528 if (namedclass > OOB_NAMEDCLASS) { /* \w-, [:word:]- */
3529 if (ckWARN(WARN_REGEXP))
3530 Perl_warner(aTHX_ WARN_REGEXP,
3531 "/%.127s/: false [] range \"%*.*s\" in regexp",
3533 PL_regcomp_parse - rangebegin,
3534 PL_regcomp_parse - rangebegin,
3537 Perl_sv_catpvf(aTHX_ listsv,
3538 /* 0x002D is Unicode for '-' */
3542 continue; /* do it next time */
3545 /* now is the next time */
3547 Perl_sv_catpvf(aTHX_ listsv, "%04"UVxf"\t%04"UVxf"\n",
3548 (UV)lastvalue, (UV)value);
3552 ret = reganode(ANYOFUTF8, 0);
3555 SV *rv = swash_init("utf8", "", listsv, 1, 0);
3556 SvREFCNT_dec(listsv);
3557 n = add_data(1,"s");
3558 PL_regcomp_rx->data->data[n] = (void*)rv;
3559 ARG1_SET(ret, flags);
3570 char* retval = PL_regcomp_parse++;
3573 if (*PL_regcomp_parse == '(' && PL_regcomp_parse[1] == '?' &&
3574 PL_regcomp_parse[2] == '#') {
3575 while (*PL_regcomp_parse && *PL_regcomp_parse != ')')
3580 if (PL_regflags & PMf_EXTENDED) {
3581 if (isSPACE(*PL_regcomp_parse)) {
3585 else if (*PL_regcomp_parse == '#') {
3586 while (*PL_regcomp_parse && *PL_regcomp_parse != '\n')
3597 - reg_node - emit a node
3599 STATIC regnode * /* Location. */
3600 S_reg_node(pTHX_ U8 op)
3603 register regnode *ret;
3604 register regnode *ptr;
3608 SIZE_ALIGN(PL_regsize);
3613 NODE_ALIGN_FILL(ret);
3615 FILL_ADVANCE_NODE(ptr, op);
3622 - reganode - emit a node with an argument
3624 STATIC regnode * /* Location. */
3625 S_reganode(pTHX_ U8 op, U32 arg)
3628 register regnode *ret;
3629 register regnode *ptr;
3633 SIZE_ALIGN(PL_regsize);
3638 NODE_ALIGN_FILL(ret);
3640 FILL_ADVANCE_NODE_ARG(ptr, op, arg);
3647 - reguni - emit (if appropriate) a Unicode character
3650 S_reguni(pTHX_ UV uv, char* s, I32* lenp)
3654 U8 tmpbuf[UTF8_MAXLEN];
3655 *lenp = uv_to_utf8(tmpbuf, uv) - tmpbuf;
3658 *lenp = uv_to_utf8((U8*)s, uv) - (U8*)s;
3663 - reginsert - insert an operator in front of already-emitted operand
3665 * Means relocating the operand.
3668 S_reginsert(pTHX_ U8 op, regnode *opnd)
3671 register regnode *src;
3672 register regnode *dst;
3673 register regnode *place;
3674 register int offset = regarglen[(U8)op];
3676 /* (PL_regkind[(U8)op] == CURLY ? EXTRA_STEP_2ARGS : 0); */
3679 PL_regsize += NODE_STEP_REGNODE + offset;
3684 PL_regcode += NODE_STEP_REGNODE + offset;
3687 StructCopy(--src, --dst, regnode);
3689 place = opnd; /* Op node, where operand used to be. */
3690 src = NEXTOPER(place);
3691 FILL_ADVANCE_NODE(place, op);
3692 Zero(src, offset, regnode);
3696 - regtail - set the next-pointer at the end of a node chain of p to val.
3699 S_regtail(pTHX_ regnode *p, regnode *val)
3702 register regnode *scan;
3703 register regnode *temp;
3704 register I32 offset;
3709 /* Find last node. */
3712 temp = regnext(scan);
3718 if (reg_off_by_arg[OP(scan)]) {
3719 ARG_SET(scan, val - scan);
3722 NEXT_OFF(scan) = val - scan;
3727 - regoptail - regtail on operand of first argument; nop if operandless
3730 S_regoptail(pTHX_ regnode *p, regnode *val)
3733 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
3734 if (p == NULL || SIZE_ONLY)
3736 if (PL_regkind[(U8)OP(p)] == BRANCH) {
3737 regtail(NEXTOPER(p), val);
3739 else if ( PL_regkind[(U8)OP(p)] == BRANCHJ) {
3740 regtail(NEXTOPER(NEXTOPER(p)), val);
3747 - regcurly - a little FSA that accepts {\d+,?\d*}
3750 S_regcurly(pTHX_ register char *s)
3769 S_dumpuntil(pTHX_ regnode *start, regnode *node, regnode *last, SV* sv, I32 l)
3772 register U8 op = EXACT; /* Arbitrary non-END op. */
3773 register regnode *next, *onode;
3775 while (op != END && (!last || node < last)) {
3776 /* While that wasn't END last time... */
3782 next = regnext(node);
3784 if (OP(node) == OPTIMIZED)
3787 PerlIO_printf(Perl_debug_log, "%4"IVdf":%*s%s", (IV)(node - start),
3788 (int)(2*l + 1), "", SvPVX(sv));
3789 if (next == NULL) /* Next ptr. */
3790 PerlIO_printf(Perl_debug_log, "(0)");
3792 PerlIO_printf(Perl_debug_log, "(%"IVdf")", (IV)(next - start));
3793 (void)PerlIO_putc(Perl_debug_log, '\n');
3795 if (PL_regkind[(U8)op] == BRANCHJ) {
3796 register regnode *nnode = (OP(next) == LONGJMP
3799 if (last && nnode > last)
3801 node = dumpuntil(start, NEXTOPER(NEXTOPER(node)), nnode, sv, l + 1);
3803 else if (PL_regkind[(U8)op] == BRANCH) {
3804 node = dumpuntil(start, NEXTOPER(node), next, sv, l + 1);
3806 else if ( op == CURLY) { /* `next' might be very big: optimizer */
3807 node = dumpuntil(start, NEXTOPER(node) + EXTRA_STEP_2ARGS,
3808 NEXTOPER(node) + EXTRA_STEP_2ARGS + 1, sv, l + 1);
3810 else if (PL_regkind[(U8)op] == CURLY && op != CURLYX) {
3811 node = dumpuntil(start, NEXTOPER(node) + EXTRA_STEP_2ARGS,
3814 else if ( op == PLUS || op == STAR) {
3815 node = dumpuntil(start, NEXTOPER(node), NEXTOPER(node) + 1, sv, l + 1);
3817 else if (op == ANYOF) {
3818 node = NEXTOPER(node);
3821 else if (PL_regkind[(U8)op] == EXACT) {
3822 /* Literal string, where present. */
3823 node += NODE_SZ_STR(node) - 1;
3824 node = NEXTOPER(node);
3827 node = NEXTOPER(node);
3828 node += regarglen[(U8)op];
3830 if (op == CURLYX || op == OPEN)
3832 else if (op == WHILEM)
3835 #endif /* DEBUGGING */
3840 - regdump - dump a regexp onto Perl_debug_log in vaguely comprehensible form
3843 Perl_regdump(pTHX_ regexp *r)
3847 SV *sv = sv_newmortal();
3849 (void)dumpuntil(r->program, r->program + 1, NULL, sv, 0);
3851 /* Header fields of interest. */
3852 if (r->anchored_substr)
3853 PerlIO_printf(Perl_debug_log,
3854 "anchored `%s%.*s%s'%s at %"IVdf" ",
3856 (int)(SvCUR(r->anchored_substr) - (SvTAIL(r->anchored_substr)!=0)),
3857 SvPVX(r->anchored_substr),
3859 SvTAIL(r->anchored_substr) ? "$" : "",
3860 (IV)r->anchored_offset);
3861 if (r->float_substr)
3862 PerlIO_printf(Perl_debug_log,
3863 "floating `%s%.*s%s'%s at %"IVdf"..%"UVuf" ",
3865 (int)(SvCUR(r->float_substr) - (SvTAIL(r->float_substr)!=0)),
3866 SvPVX(r->float_substr),
3868 SvTAIL(r->float_substr) ? "$" : "",
3869 (IV)r->float_min_offset, (UV)r->float_max_offset);
3870 if (r->check_substr)
3871 PerlIO_printf(Perl_debug_log,
3872 r->check_substr == r->float_substr
3873 ? "(checking floating" : "(checking anchored");
3874 if (r->reganch & ROPT_NOSCAN)
3875 PerlIO_printf(Perl_debug_log, " noscan");
3876 if (r->reganch & ROPT_CHECK_ALL)
3877 PerlIO_printf(Perl_debug_log, " isall");
3878 if (r->check_substr)
3879 PerlIO_printf(Perl_debug_log, ") ");
3881 if (r->regstclass) {
3882 regprop(sv, r->regstclass);
3883 PerlIO_printf(Perl_debug_log, "stclass `%s' ", SvPVX(sv));
3885 if (r->reganch & ROPT_ANCH) {
3886 PerlIO_printf(Perl_debug_log, "anchored");
3887 if (r->reganch & ROPT_ANCH_BOL)
3888 PerlIO_printf(Perl_debug_log, "(BOL)");
3889 if (r->reganch & ROPT_ANCH_MBOL)
3890 PerlIO_printf(Perl_debug_log, "(MBOL)");
3891 if (r->reganch & ROPT_ANCH_SBOL)
3892 PerlIO_printf(Perl_debug_log, "(SBOL)");
3893 if (r->reganch & ROPT_ANCH_GPOS)
3894 PerlIO_printf(Perl_debug_log, "(GPOS)");
3895 PerlIO_putc(Perl_debug_log, ' ');
3897 if (r->reganch & ROPT_GPOS_SEEN)
3898 PerlIO_printf(Perl_debug_log, "GPOS ");
3899 if (r->reganch & ROPT_SKIP)
3900 PerlIO_printf(Perl_debug_log, "plus ");
3901 if (r->reganch & ROPT_IMPLICIT)
3902 PerlIO_printf(Perl_debug_log, "implicit ");
3903 PerlIO_printf(Perl_debug_log, "minlen %ld ", (long) r->minlen);
3904 if (r->reganch & ROPT_EVAL_SEEN)
3905 PerlIO_printf(Perl_debug_log, "with eval ");
3906 PerlIO_printf(Perl_debug_log, "\n");
3907 #endif /* DEBUGGING */
3911 S_put_byte(pTHX_ SV *sv, int c)
3913 if (c <= ' ' || c == 127 || c == 255)
3914 Perl_sv_catpvf(aTHX_ sv, "\\%o", c);
3915 else if (c == '-' || c == ']' || c == '\\' || c == '^')
3916 Perl_sv_catpvf(aTHX_ sv, "\\%c", c);
3918 Perl_sv_catpvf(aTHX_ sv, "%c", c);
3922 - regprop - printable representation of opcode
3925 Perl_regprop(pTHX_ SV *sv, regnode *o)
3931 sv_setpvn(sv, "", 0);
3932 if (OP(o) >= reg_num) /* regnode.type is unsigned */
3933 FAIL("corrupted regexp opcode");
3934 sv_catpv(sv, (char*)reg_name[OP(o)]); /* Take off const! */
3936 k = PL_regkind[(U8)OP(o)];
3939 Perl_sv_catpvf(aTHX_ sv, " <%s%.*s%s>", PL_colors[0],
3940 STR_LEN(o), STRING(o), PL_colors[1]);
3941 else if (k == CURLY) {
3942 if (OP(o) == CURLYM || OP(o) == CURLYN)
3943 Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* Parenth number */
3944 Perl_sv_catpvf(aTHX_ sv, " {%d,%d}", ARG1(o), ARG2(o));
3946 else if (k == WHILEM && o->flags) /* Ordinal/of */
3947 Perl_sv_catpvf(aTHX_ sv, "[%d/%d]", o->flags & 0xf, o->flags>>4);
3948 else if (k == REF || k == OPEN || k == CLOSE || k == GROUPP )
3949 Perl_sv_catpvf(aTHX_ sv, "%d", (int)ARG(o)); /* Parenth number */
3950 else if (k == LOGICAL)
3951 Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* 2: embedded, otherwise 1 */
3952 else if (k == ANYOF) {
3953 int i, rangestart = -1;
3954 const char * const out[] = { /* Should be syncronized with
3955 a table in regcomp.h */
3984 if (o->flags & ANYOF_LOCALE)
3985 sv_catpv(sv, "{loc}");
3986 if (o->flags & ANYOF_FOLD)
3987 sv_catpv(sv, "{i}");
3988 Perl_sv_catpvf(aTHX_ sv, "[%s", PL_colors[0]);
3989 if (o->flags & ANYOF_INVERT)
3991 for (i = 0; i <= 256; i++) {
3992 if (i < 256 && ANYOF_BITMAP_TEST(o,i)) {
3993 if (rangestart == -1)
3995 } else if (rangestart != -1) {
3996 if (i <= rangestart + 3)
3997 for (; rangestart < i; rangestart++)
3998 put_byte(sv, rangestart);
4000 put_byte(sv, rangestart);
4002 put_byte(sv, i - 1);
4007 if (o->flags & ANYOF_CLASS)
4008 for (i = 0; i < sizeof(out)/sizeof(char*); i++)
4009 if (ANYOF_CLASS_TEST(o,i))
4010 sv_catpv(sv, out[i]);
4011 Perl_sv_catpvf(aTHX_ sv, "%s]", PL_colors[1]);
4013 else if (k == BRANCHJ && (OP(o) == UNLESSM || OP(o) == IFMATCH))
4014 Perl_sv_catpvf(aTHX_ sv, "[-%d]", o->flags);
4015 #endif /* DEBUGGING */
4019 Perl_re_intuit_string(pTHX_ regexp *prog)
4020 { /* Assume that RE_INTUIT is set */
4023 char *s = SvPV(prog->check_substr,n_a);
4025 if (!PL_colorset) reginitcolors();
4026 PerlIO_printf(Perl_debug_log,
4027 "%sUsing REx substr:%s `%s%.60s%s%s'\n",
4028 PL_colors[4],PL_colors[5],PL_colors[0],
4031 (strlen(s) > 60 ? "..." : ""));
4034 return prog->check_substr;
4038 Perl_pregfree(pTHX_ struct regexp *r)
4041 DEBUG_r(if (!PL_colorset) reginitcolors());
4043 if (!r || (--r->refcnt > 0))
4045 DEBUG_r(PerlIO_printf(Perl_debug_log,
4046 "%sFreeing REx:%s `%s%.60s%s%s'\n",
4047 PL_colors[4],PL_colors[5],PL_colors[0],
4050 (strlen(r->precomp) > 60 ? "..." : "")));
4053 Safefree(r->precomp);
4054 if (RX_MATCH_COPIED(r))
4055 Safefree(r->subbeg);
4057 if (r->anchored_substr)
4058 SvREFCNT_dec(r->anchored_substr);
4059 if (r->float_substr)
4060 SvREFCNT_dec(r->float_substr);
4061 Safefree(r->substrs);
4064 int n = r->data->count;
4065 AV* new_comppad = NULL;
4070 switch (r->data->what[n]) {
4072 SvREFCNT_dec((SV*)r->data->data[n]);
4075 Safefree(r->data->data[n]);
4078 new_comppad = (AV*)r->data->data[n];
4081 if (new_comppad == NULL)
4082 Perl_croak(aTHX_ "panic: pregfree comppad");
4083 old_comppad = PL_comppad;
4084 old_curpad = PL_curpad;
4085 PL_comppad = new_comppad;
4086 PL_curpad = AvARRAY(new_comppad);
4087 op_free((OP_4tree*)r->data->data[n]);
4088 PL_comppad = old_comppad;
4089 PL_curpad = old_curpad;
4090 SvREFCNT_dec((SV*)new_comppad);
4096 FAIL2("panic: regfree data code '%c'", r->data->what[n]);
4099 Safefree(r->data->what);
4102 Safefree(r->startp);
4108 - regnext - dig the "next" pointer out of a node
4110 * [Note, when REGALIGN is defined there are two places in regmatch()
4111 * that bypass this code for speed.]
4114 Perl_regnext(pTHX_ register regnode *p)
4117 register I32 offset;
4119 if (p == &PL_regdummy)
4122 offset = (reg_off_by_arg[OP(p)] ? ARG(p) : NEXT_OFF(p));
4130 S_re_croak2(pTHX_ const char* pat1,const char* pat2,...)
4133 STRLEN l1 = strlen(pat1);
4134 STRLEN l2 = strlen(pat2);
4143 Copy(pat1, buf, l1 , char);
4144 Copy(pat2, buf + l1, l2 , char);
4145 buf[l1 + l2] = '\n';
4146 buf[l1 + l2 + 1] = '\0';
4148 /* ANSI variant takes additional second argument */
4149 va_start(args, pat2);
4153 msv = vmess(buf, &args);
4155 message = SvPV(msv,l1);
4158 Copy(message, buf, l1 , char);
4159 buf[l1] = '\0'; /* Overwrite \n */
4160 Perl_croak(aTHX_ "%s", buf);
4163 /* XXX Here's a total kludge. But we need to re-enter for swash routines. */
4166 Perl_save_re_context(pTHX)
4170 SAVEPPTR(PL_regprecomp); /* uncompiled string. */
4171 SAVEI32(PL_regnpar); /* () count. */
4172 SAVEI32(PL_regsize); /* Code size. */
4173 SAVEI16(PL_regflags); /* are we folding, multilining? */
4174 SAVEPPTR(PL_reginput); /* String-input pointer. */
4175 SAVEPPTR(PL_regbol); /* Beginning of input, for ^ check. */
4176 SAVEPPTR(PL_regeol); /* End of input, for $ check. */
4177 SAVEVPTR(PL_regstartp); /* Pointer to startp array. */
4178 SAVEVPTR(PL_regendp); /* Ditto for endp. */
4179 SAVEVPTR(PL_reglastparen); /* Similarly for lastparen. */
4180 SAVEPPTR(PL_regtill); /* How far we are required to go. */
4181 SAVEI8(PL_regprev); /* char before regbol, \n if none */
4182 SAVEVPTR(PL_reg_start_tmp); /* from regexec.c */
4183 PL_reg_start_tmp = 0;
4184 SAVEFREEPV(PL_reg_start_tmp);
4185 SAVEI32(PL_reg_start_tmpl); /* from regexec.c */
4186 PL_reg_start_tmpl = 0;
4187 SAVEVPTR(PL_regdata);
4188 SAVEI32(PL_reg_flags); /* from regexec.c */
4189 SAVEI32(PL_reg_eval_set); /* from regexec.c */
4190 SAVEI32(PL_regnarrate); /* from regexec.c */
4191 SAVEVPTR(PL_regprogram); /* from regexec.c */
4192 SAVEINT(PL_regindent); /* from regexec.c */
4193 SAVEVPTR(PL_regcc); /* from regexec.c */
4194 SAVEVPTR(PL_curcop);
4195 SAVEVPTR(PL_regcomp_rx); /* from regcomp.c */
4196 SAVEI32(PL_regseen); /* from regcomp.c */
4197 SAVEI32(PL_regsawback); /* Did we see \1, ...? */
4198 SAVEI32(PL_regnaughty); /* How bad is this pattern? */
4199 SAVEVPTR(PL_regcode); /* Code-emit pointer; ®dummy = don't */
4200 SAVEPPTR(PL_regxend); /* End of input for compile */
4201 SAVEPPTR(PL_regcomp_parse); /* Input-scan pointer. */
4202 SAVEVPTR(PL_reg_call_cc); /* from regexec.c */
4203 SAVEVPTR(PL_reg_re); /* from regexec.c */
4204 SAVEPPTR(PL_reg_ganch); /* from regexec.c */
4205 SAVESPTR(PL_reg_sv); /* from regexec.c */
4206 SAVEVPTR(PL_reg_magic); /* from regexec.c */
4207 SAVEI32(PL_reg_oldpos); /* from regexec.c */
4208 SAVEVPTR(PL_reg_oldcurpm); /* from regexec.c */
4209 SAVEVPTR(PL_reg_curpm); /* from regexec.c */
4211 SAVEPPTR(PL_reg_starttry); /* from regexec.c */
4222 clear_re(pTHXo_ void *r)
4224 ReREFCNT_dec((regexp *)r);