From: Yves Orton Date: Sat, 13 Jan 2007 17:18:01 +0000 (+0100) Subject: Re: [PATCH] Add support for /k modfier for matching along with ${^PREMATCH}, ${^MATCH... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a20207d7c00bd54d6d2718961a96cd5c7ed1e37b;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH] Add support for /k modfier for matching along with ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} Message-ID: <9b18b3110701130818h6badbd3o1b38f2660d258173@mail.gmail.com> macroize regexp modifiers p4raw-id: //depot/perl@29834 --- diff --git a/perl.h b/perl.h index 019335f..d8cdfeb 100644 --- a/perl.h +++ b/perl.h @@ -228,6 +228,33 @@ : (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. diff --git a/regcomp.c b/regcomp.c index d07f177..b5faf28 100644 --- 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 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); @@ -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) - reflags[left++]='k'; + reflags[left++] = KEEPCOPY_PAT_MOD; /*'k'*/ while((ch = *fptr++)) { if(reganch & 1) { reflags[left++] = ch; diff --git a/regexp.h b/regexp.h index 4045fbd..a2e0fc1 100644 --- 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 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 diff --git a/toke.c b/toke.c index dcbf3d6..c22d508 100644 --- 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); - 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 = - (const char *)((type == OP_QR) ? "iomsxk" : "iogcmsxk"); + (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS); #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)) { - 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; @@ -10879,11 +10880,11 @@ S_scan_subst(pTHX_ char *start) #endif while (*s) { - if (*s == 'e') { + if (*s == EXEC_PAT_MOD) { s++; es++; } - else if (strchr("iogcmsxk", *s)) + else if (strchr(S_PAT_MODS, *s)) pmflag(&pm->op_pmflags,*s++); else break;