This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
migrate CURLY/PLUS/STAR branch in regmatch() to new FSM-esque paradigm
[perl5.git] / regexp.h
index 777d82f..8d71752 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -14,7 +14,9 @@
  * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
  * not the System V one.
  */
-
+#ifndef PLUGGABLE_RE_EXTENSION
+/* we don't want to include this stuff if we are inside Nicholas'
+ * pluggable regex engine code */
 
 struct regnode {
     U8 flags;
@@ -80,22 +82,17 @@ typedef struct regexp {
 #define RE_USE_INTUIT_NOML     0x00100000 /* Best to intuit before matching */
 #define RE_USE_INTUIT_ML       0x00200000
 #define REINT_AUTORITATIVE_NOML        0x00400000 /* Can trust a positive answer */
-#define REINT_AUTORITATIVE_ML  0x00800000 
+#define REINT_AUTORITATIVE_ML  0x00800000
 #define REINT_ONCE_NOML                0x01000000 /* Intuit can succed once only. */
 #define REINT_ONCE_ML          0x02000000
 #define RE_INTUIT_ONECHAR      0x04000000
 #define RE_INTUIT_TAIL         0x08000000
 
-#define RE_DEBUG_BIT            0x20000000
 
 #define RE_USE_INTUIT          (RE_USE_INTUIT_NOML|RE_USE_INTUIT_ML)
 #define REINT_AUTORITATIVE     (REINT_AUTORITATIVE_NOML|REINT_AUTORITATIVE_ML)
 #define REINT_ONCE             (REINT_ONCE_NOML|REINT_ONCE_ML)
 
-#define RX_DEBUG(prog) ((prog)->reganch & RE_DEBUG_BIT)
-#define RX_DEBUG_on(prog) ((prog)->reganch |= RE_DEBUG_BIT)
-
-
 #define RX_MATCH_TAINTED(prog) ((prog)->reganch & ROPT_TAINTED_SEEN)
 #define RX_MATCH_TAINTED_on(prog) ((prog)->reganch |= ROPT_TAINTED_SEEN)
 #define RX_MATCH_TAINTED_off(prog) ((prog)->reganch &= ~ROPT_TAINTED_SEEN)
@@ -109,6 +106,13 @@ typedef struct regexp {
 #define RX_MATCH_COPIED_set(prog,t)    ((t) \
                                         ? RX_MATCH_COPIED_on(prog) \
                                         : RX_MATCH_COPIED_off(prog))
+#endif /* PLUGGABLE_RE_EXTENSION */
+
+/* Stuff that needs to be included in the plugable extension goes below here */
+
+#define RE_DEBUG_BIT            0x20000000
+#define RX_DEBUG(prog) ((prog)->reganch & RE_DEBUG_BIT)
+#define RX_DEBUG_on(prog) ((prog)->reganch |= RE_DEBUG_BIT)
 
 #ifdef PERL_OLD_COPY_ON_WRITE
 #define RX_MATCH_COPY_FREE(rx) \
@@ -176,34 +180,12 @@ typedef struct {
 
 typedef I32 CHECKPOINT;
 
-typedef enum {
-    resume_TRIE1,
-    resume_TRIE2,
-    resume_EVAL,
-    resume_CURLYX,
-    resume_WHILEM1,
-    resume_WHILEM2,
-    resume_WHILEM3,
-    resume_WHILEM4,
-    resume_WHILEM5,
-    resume_WHILEM6,
-    resume_CURLYM1,
-    resume_CURLYM2,
-    resume_CURLYM3,
-    resume_IFMATCH,
-    resume_PLUS1,
-    resume_PLUS2,
-    resume_PLUS3,
-    resume_PLUS4
-} regmatch_resume_states;
-
-
 typedef struct regmatch_state {
 
     /* these vars contain state that needs to be maintained
      * across the main while loop ... */
 
-    regmatch_resume_states resume_state; /* where to jump to on return */
+    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}?" */
@@ -229,7 +211,9 @@ typedef struct regmatch_state {
 
        struct {
            reg_trie_accepted *accept_buff;
-           U32 accepted;       /* how many accepting states we have seen */
+           U32         accepted; /* how many accepting states we have seen */
+           regnode     *B;     /* node following the trie */
+           regnode     *me;    /* only needed for debugging */
        } trie;
 
        struct {
@@ -239,6 +223,7 @@ typedef struct regmatch_state {
            int         toggleutf;
            CHECKPOINT  cp;     /* remember current savestack indexes */
            CHECKPOINT  lastcp;
+           regnode     *B;     /* the node following us  */
        } eval;
 
        struct {
@@ -265,30 +250,39 @@ typedef struct regmatch_state {
        } whilem;
 
        struct {
+           I32 lastparen;
+           regnode *next_branch; /* next branch node */
+           CHECKPOINT cp;
+       } branch;
+
+       struct {
            /* this first element must match u.yes */
            struct regmatch_state *prev_yes_state;
-           I32 paren;
            I32 c1, c2;         /* case fold search */
-           CHECKPOINT lastcp;
-           I32 l;
-           I32 matches;
-           I32 maxwanted;
+           CHECKPOINT cp;
+           I32 alen;           /* length of first-matched A string */
+           I32 count;
            bool minmod;
+           regnode *A, *B;     /* the nodes corresponding to /A*B/  */
+           regnode *me;        /* the curlym node */
        } curlym;
 
        struct {
            I32 paren;
-           CHECKPOINT lastcp;
+           CHECKPOINT cp;
            I32 c1, c2;         /* case fold search */
-           char *e;
-           char *old;
+           char *maxpos;       /* highest possible point in string to match */
+           char *oldloc;       /* the previous locinput */
            int count;
-       } plus; /* and CURLYN/CURLY/STAR */
+           int min, max;       /* {m,n} */
+           regnode *A, *B;     /* the nodes corresponding to /A*B/  */
+       } curly; /* and CURLYN/PLUS/STAR */
 
        struct {
            /* this first element must match u.yes */
            struct regmatch_state *prev_yes_state;
            I32 wanted;
+           regnode  *me; /* the IFMATCH/SUSPEND/UNLESSM node  */
        } ifmatch; /* and SUSPEND/UNLESSM */
     } u;
 } regmatch_state;