This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [PATCH] Add support for /k modfier for matching along with ${^PREMATCH}, ${^MATCH...
authorYves Orton <demerphq@gmail.com>
Sat, 13 Jan 2007 17:18:01 +0000 (18:18 +0100)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Mon, 15 Jan 2007 16:37:21 +0000 (16:37 +0000)
Message-ID: <9b18b3110701130818h6badbd3o1b38f2660d258173@mail.gmail.com>

macroize regexp modifiers

p4raw-id: //depot/perl@29834

perl.h
regcomp.c
regexp.h
toke.c

diff --git a/perl.h b/perl.h
index 019335f..d8cdfeb 100644 (file)
--- a/perl.h
+++ b/perl.h
           : (REGEXP *)NULL) 
 #endif
 
           : (REGEXP *)NULL) 
 #endif
 
+
+/* chars and strings used as regex pattern modifiers 
+ * Singlular is a 'c'har, plural is a "string" 
+ */
+#define EXEC_PAT_MOD         'e'
+#define KEEPCOPY_PAT_MOD     'k'
+#define ONCE_PAT_MOD         'o'
+#define GLOBAL_PAT_MOD       'g'
+#define CONTINUE_PAT_MOD     'c'
+#define MULTILINE_PAT_MOD    'm'
+#define SINGLE_PAT_MOD       's'
+#define IGNORE_PAT_MOD       'i'
+#define XTENDED_PAT_MOD      'x'
+
+#define ONCE_PAT_MODS        "o"
+#define KEEPCOPY_PAT_MODS    "k"
+#define EXEC_PAT_MODS        "e"
+#define LOOP_PAT_MODS        "gc"
+
+#define STD_PAT_MODS        "msix"
+
+#define EXT_PAT_MODS    ONCE_PAT_MODS   KEEPCOPY_PAT_MODS
+#define QR_PAT_MODS     STD_PAT_MODS    EXT_PAT_MODS 
+#define M_PAT_MODS      QR_PAT_MODS     LOOP_PAT_MODS
+#define S_PAT_MODS      M_PAT_MODS      EXEC_PAT_MODS
+
+
 /*
  * Because of backward compatibility reasons the PERL_UNUSED_DECL
  * cannot be changed from postfix to PERL_UNUSED_DECL(x).  Sigh.
 /*
  * Because of backward compatibility reasons the PERL_UNUSED_DECL
  * cannot be changed from postfix to PERL_UNUSED_DECL(x).  Sigh.
index d07f177..b5faf28 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -8869,7 +8869,7 @@ Perl_reg_stringify(pTHX_ MAGIC *mg, STRLEN *lp, U32 *flags, I32 *haseval ) {
     const regexp * const re = (regexp *)mg->mg_obj;
 
     if (!mg->mg_ptr) {
     const regexp * const re = (regexp *)mg->mg_obj;
 
     if (!mg->mg_ptr) {
-       const char *fptr = "msix";
+       const char *fptr = STD_PAT_MODS;        /*"msix"*/
        char reflags[7];
        char ch;
        bool hask = ((re->extflags & RXf_PMf_KEEPCOPY) == RXf_PMf_KEEPCOPY);
        char reflags[7];
        char ch;
        bool hask = ((re->extflags & RXf_PMf_KEEPCOPY) == RXf_PMf_KEEPCOPY);
@@ -8879,7 +8879,7 @@ Perl_reg_stringify(pTHX_ MAGIC *mg, STRLEN *lp, U32 *flags, I32 *haseval ) {
         int left = 0;
        int right = 4 + hask;
         if (hask) 
         int left = 0;
        int right = 4 + hask;
         if (hask) 
-            reflags[left++]='k';
+            reflags[left++] = KEEPCOPY_PAT_MOD; /*'k'*/
        while((ch = *fptr++)) {
            if(reganch & 1) {
                reflags[left++] = ch;
        while((ch = *fptr++)) {
            if(reganch & 1) {
                reflags[left++] = ch;
index 4045fbd..a2e0fc1 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -149,11 +149,11 @@ typedef struct regexp_engine {
 #define RXf_PMf_STD_PMMOD      (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_FOLD|RXf_PMf_EXTENDED)
 #define RXf_PMf_COMPILETIME    (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_LOCALE|RXf_PMf_FOLD|RXf_PMf_EXTENDED|RXf_PMf_KEEPCOPY)
 
 #define RXf_PMf_STD_PMMOD      (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_FOLD|RXf_PMf_EXTENDED)
 #define RXf_PMf_COMPILETIME    (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_LOCALE|RXf_PMf_FOLD|RXf_PMf_EXTENDED|RXf_PMf_KEEPCOPY)
 
-#define CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl)              \
-        case 'i': *(pmfl) |= RXf_PMf_FOLD;       break;   \
-        case 'm': *(pmfl) |= RXf_PMf_MULTILINE;  break;   \
-        case 's': *(pmfl) |= RXf_PMf_SINGLELINE; break;   \
-        case 'x': *(pmfl) |= RXf_PMf_EXTENDED;   break
+#define CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl)                        \
+    case IGNORE_PAT_MOD:    *(pmfl) |= RXf_PMf_FOLD;       break;   \
+    case MULTILINE_PAT_MOD: *(pmfl) |= RXf_PMf_MULTILINE;  break;   \
+    case SINGLE_PAT_MOD:    *(pmfl) |= RXf_PMf_SINGLELINE; break;   \
+    case XTENDED_PAT_MOD:   *(pmfl) |= RXf_PMf_EXTENDED;   break
 
 /* What we have seen */
 #define RXf_LOOKBEHIND_SEEN    0x00020000
 
 /* What we have seen */
 #define RXf_LOOKBEHIND_SEEN    0x00020000
diff --git a/toke.c b/toke.c
index dcbf3d6..c22d508 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -10767,10 +10767,10 @@ Perl_pmflag(pTHX_ U32* pmfl, int ch)
         char c = (char)ch;
         switch (c) {
             CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
         char c = (char)ch;
         switch (c) {
             CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
-            case 'g': *pmfl |= PMf_GLOBAL; break;
-            case 'c': *pmfl |= PMf_CONTINUE; break;
-            case 'o': *pmfl |= PMf_KEEP; break;
-            case 'k': *pmfl |= PMf_KEEPCOPY; break;
+            case GLOBAL_PAT_MOD:    *pmfl |= PMf_GLOBAL; break;
+            case CONTINUE_PAT_MOD:  *pmfl |= PMf_CONTINUE; break;
+            case ONCE_PAT_MOD:      *pmfl |= PMf_KEEP; break;
+            case KEEPCOPY_PAT_MOD:  *pmfl |= PMf_KEEPCOPY; break;
         }
     }
 }
         }
     }
 }
@@ -10782,7 +10782,7 @@ S_scan_pat(pTHX_ char *start, I32 type)
     PMOP *pm;
     char *s = scan_str(start,!!PL_madskills,FALSE);
     const char * const valid_flags =
     PMOP *pm;
     char *s = scan_str(start,!!PL_madskills,FALSE);
     const char * const valid_flags =
-       (const char *)((type == OP_QR) ? "iomsxk" : "iogcmsxk");
+       (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
 #ifdef PERL_MAD
     char *modstart;
 #endif
 #ifdef PERL_MAD
     char *modstart;
 #endif
@@ -10815,7 +10815,8 @@ S_scan_pat(pTHX_ char *start, I32 type)
     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
            && ckWARN(WARN_REGEXP))
     {
     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
            && ckWARN(WARN_REGEXP))
     {
-        Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
+        Perl_warner(aTHX_ packWARN(WARN_REGEXP), 
+            "Use of /c modifier is meaningless without /g" );
     }
 
     pm->op_pmpermflags = pm->op_pmflags;
     }
 
     pm->op_pmpermflags = pm->op_pmflags;
@@ -10879,11 +10880,11 @@ S_scan_subst(pTHX_ char *start)
 #endif
 
     while (*s) {
 #endif
 
     while (*s) {
-       if (*s == 'e') {
+       if (*s == EXEC_PAT_MOD) {
            s++;
            es++;
        }
            s++;
            es++;
        }
-       else if (strchr("iogcmsxk", *s))
+       else if (strchr(S_PAT_MODS, *s))
            pmflag(&pm->op_pmflags,*s++);
        else
            break;
            pmflag(&pm->op_pmflags,*s++);
        else
            break;