This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix a problem with jump-tries, add (?FAIL) pattern.
[perl5.git] / regexp.h
index 09759fa..89fcea7 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -54,7 +54,8 @@ typedef struct regexp {
        U32 lastcloseparen;     /* last paren matched */
        U32 reganch;            /* Internal use only +
                                   Tainted information used by regexec? */
-        const struct regexp_engine* engine;
+       HV *paren_names;        /* Paren names */
+       const struct regexp_engine* engine;
        regnode program[1];     /* Unwarranted chumminess with compiler. */
 } regexp;
 
@@ -66,17 +67,17 @@ typedef struct re_scream_pos_data_s
 } re_scream_pos_data;
 
 typedef struct regexp_engine {
-    regexp*    (*regcomp) (pTHX_ char* exp, char* xend, PMOP* pm);
-    I32                (*regexec) (pTHX_ regexp* prog, char* stringarg, char* strend,
+    regexp* (*comp) (pTHX_ char* exp, char* xend, PMOP* pm);
+    I32            (*exec) (pTHX_ regexp* prog, char* stringarg, char* strend,
                            char* strbeg, I32 minend, SV* screamer,
                            void* data, U32 flags);
-    char*      (*re_intuit_start) (pTHX_ regexp *prog, SV *sv, char *strpos,
-                                   char *strend, U32 flags,
-                                   struct re_scream_pos_data_s *data);
-    SV*                (*re_intuit_string) (pTHX_ regexp *prog);
-    void       (*regfree) (pTHX_ struct regexp* r);
-#if defined(USE_ITHREADS)
-    regexp*    (*regdupe) (pTHX_ const regexp *r, CLONE_PARAMS *param);
+    char*   (*intuit) (pTHX_ regexp *prog, SV *sv, char *strpos,
+                           char *strend, U32 flags,
+                           struct re_scream_pos_data_s *data);
+    SV*            (*checkstr) (pTHX_ regexp *prog);
+    void    (*free) (pTHX_ struct regexp* r);
+#ifdef USE_ITHREADS
+    regexp* (*dupe) (pTHX_ const regexp *r, CLONE_PARAMS *param);
 #endif    
 } regexp_engine;
 
@@ -96,6 +97,7 @@ typedef struct regexp_engine {
 #define ROPT_CANY_SEEN         0x00000800
 #define ROPT_SANY_SEEN         ROPT_CANY_SEEN /* src bckwrd cmpt */
 #define ROPT_GPOS_CHECK         (ROPT_GPOS_SEEN|ROPT_ANCH_GPOS)
+#define ROPT_RECURSE_SEEN       0x00001000
 
 /* 0xf800 of reganch is used by PMf_COMPILETIME */
 
@@ -205,26 +207,13 @@ typedef struct {
 
 /* structures for holding and saving the state maintained by regmatch() */
 
+#define MAX_RECURSE_EVAL_NOCHANGE_DEPTH 50
+
 typedef I32 CHECKPOINT;
 
 typedef struct regmatch_state {
-
-    /* these vars contain state that needs to be maintained
-     * across the main while loop ... */
-
     int resume_state;          /* where to jump to on return */
-    regnode *scan;             /* Current node. */
-    regnode *next;             /* Next node. */
-    bool minmod;               /* the next "{n,m}" is a "{n,m}?" */
-    bool sw;                   /* the condition value in (?(cond)a|b) */
-    int logical;
-    I32 unwind;                        /* savestack index of current unwind block */
-    char *locinput;
-
-    /* ... while the rest of these are local to an individual branch */
-
-    I32 n;                     /* no or next */
-    I32 ln;                    /* len or last */
+    char *locinput;            /* where to backtrack in string on failure */
 
     union {
 
@@ -238,9 +227,9 @@ typedef struct regmatch_state {
        struct {
            reg_trie_accepted *accept_buff;
            U32         accepted; /* how many accepting states we have seen */
-           U16         *jump;  /* negative offsets from B */
+           U16         *jump;  /* positive offsets from me */
            regnode     *B;     /* node following the trie */
-           regnode     *me;    /* only needed for debugging */
+           regnode     *me;    /* Which node am I - needed for jump tries*/
        } trie;
 
        struct {
@@ -255,29 +244,34 @@ typedef struct regmatch_state {
            CHECKPOINT  cp;     /* remember current savestack indexes */
            CHECKPOINT  lastcp;
            regnode     *B;     /* the node following us  */
+           U32        close_paren; /* which close bracket is our end */
        } eval;
 
        struct {
-           CHECKPOINT cp;      /* remember current savestack indexes */
-           struct regmatch_state *outercc; /* outer CURLYX state if any */
-
-           /* these contain the current curly state, and are accessed
-            * by subsequent WHILEMs */
+           /* this first element must match u.yes */
+           struct regmatch_state *prev_yes_state;
+           struct regmatch_state *prev_curlyx; /* previous cur_curlyx */
+           CHECKPOINT  cp;     /* remember current savestack index */
+           bool        minmod;
            int         parenfloor;/* how far back to strip paren data */
-           int         cur;    /* how many instances of scan we've matched */
-           int         min;    /* the minimal number of scans to match */
-           int         max;    /* the maximal number of scans to match */
-           regnode *   scan;   /* the thing to match */
-           char *      lastloc;/* where we started matching this scan */
+           int         min;    /* the minimal number of A's to match */
+           int         max;    /* the maximal number of A's to match */
+           regnode     *A, *B; /* the nodes corresponding to /A*B/  */
+
+           /* these two are modified by WHILEM */
+           int         count;  /* how many instances of A we've matched */
+           char        *lastloc;/* where previous A matched (0-len detect) */
        } curlyx;
 
        struct {
-           CHECKPOINT cp;      /* remember current savestack indexes */
-           CHECKPOINT lastcp;
-           struct regmatch_state *savecc;
-           char *lastloc;      /* Detection of 0-len. */
-           I32 cache_offset;
-           I32 cache_bit;
+           /* this first element must match u.yes */
+           struct regmatch_state *prev_yes_state;
+           struct regmatch_state *save_curlyx;
+           CHECKPOINT  cp;     /* remember current savestack indexes */
+           CHECKPOINT  lastcp;
+           char        *save_lastloc;  /* previous curlyx.lastloc */
+           I32         cache_offset;
+           I32         cache_mask;
        } whilem;
 
        struct {
@@ -313,6 +307,7 @@ typedef struct regmatch_state {
            /* this first element must match u.yes */
            struct regmatch_state *prev_yes_state;
            I32 wanted;
+           I32 logical;        /* saved copy of 'logical' var */
            regnode  *me; /* the IFMATCH/SUSPEND/UNLESSM node  */
        } ifmatch; /* and SUSPEND/UNLESSM */
     } u;