This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow (#...) anywhere white space is under qr//x
authorKarl Williamson <khw@cpan.org>
Wed, 23 Sep 2015 20:06:23 +0000 (14:06 -0600)
committerKarl Williamson <khw@cpan.org>
Sun, 11 Oct 2015 16:48:32 +0000 (10:48 -0600)
Wherever you can have white space under /x, you can also have a (#...)
comment (even without /x).  Prior to this commit, there were several
places that allowed the white space but not the comments.

This resolves [perl #116639].

pod/perldelta.pod
regcomp.c
t/re/re_tests
t/re/regex_sets.t

index 2bc85d6..91fbd1b 100644 (file)
@@ -354,7 +354,9 @@ files in F<ext/> and F<lib/> are best summarized in L</Modules and Pragmata>.
 
 =item *
 
-XXX
+There were places in regular expression patterns where comments
+(C<(?#...)>) weren't allowed, but should have been.  This is now fixed.
+[perl #116639]
 
 =back
 
index 5117e5c..8e3331a 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11178,7 +11178,7 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state,
     char * endbrace;    /* points to '}' following the name */
     char *endchar;     /* Points to '.' or '}' ending cur char in the input
                            stream */
-    char* p;            /* Temporary */
+    char* p = RExC_parse; /* Temporary */
 
     GET_RE_DEBUG_FLAGS_DECL;
 
@@ -11196,10 +11196,8 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state,
     /* The [^\n] meaning of \N ignores spaces and comments under the /x
      * modifier.  The other meanings do not, so use a temporary until we find
      * out which we are being called with */
-    p = (RExC_flags & RXf_PMf_EXTENDED)
-       ? regpatws(pRExC_state, RExC_parse,
-                                TRUE) /* means recognize comments */
-       : RExC_parse;
+    skip_to_be_ignored_text(pRExC_state, &p,
+                            FALSE /* Don't force to /x */ );
 
     /* Disambiguate between \N meaning a named character versus \N meaning
      * [^\n].  The latter is assumed when the {...} following the \N is a legal
@@ -12667,9 +12665,8 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                  * quantifier.  Move <p> to after anything that should be
                  * ignored, which, as a side effect, positions <p> for the next
                  * loop iteration */
-               if ( RExC_flags & RXf_PMf_EXTENDED)
-                    p = regpatws(pRExC_state, p,
-                                          TRUE); /* means recognize comments */
+                skip_to_be_ignored_text(pRExC_state, &p,
+                                        FALSE /* Don't force to /x */ );
 
                 /* If the next thing is a quantifier, it applies to this
                  * character only, which means that this character has to be in
@@ -13445,8 +13442,10 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist,
 
         while (RExC_parse < RExC_end) {
             SV* current = NULL;
-            RExC_parse = regpatws(pRExC_state, RExC_parse,
-                                          TRUE); /* means recognize comments */
+
+            skip_to_be_ignored_text(pRExC_state, &RExC_parse,
+                                    TRUE /* Force /x */ );
+
             switch (*RExC_parse) {
                 case '?':
                     if (RExC_parse[1] == '[') depth++, RExC_parse++;
@@ -13622,9 +13621,8 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist,
                                        operand */
         SV* only_to_avoid_leaks;
 
-        /* Skip white space */
-        RExC_parse = regpatws(pRExC_state, RExC_parse,
-                TRUE /* means recognize comments */ );
+        skip_to_be_ignored_text(pRExC_state, &RExC_parse,
+                                TRUE /* Force /x */ );
         if (RExC_parse >= RExC_end) {
             Perl_croak(aTHX_ "panic: Read past end of '(?[ ])'");
         }
index 4255fbc..d777992 100644 (file)
@@ -1936,5 +1936,9 @@ A+(*PRUNE)BC(?{}) AAABC   y       $&      AAABC
 foo(*ACCEPT:foo)       foo     y       $::REGMARK      foo
 (foo(*ACCEPT:foo))     foo     y       $::REGMARK      foo
 A(*FAIL:foo)[BC]       A       n       $::REGERROR     foo
+
+\N(?#comment){SPACE}   A       c       -       Missing braces on \N{}
+ab(?#Comment){2}c      abbc    y       $&      abbc
+
 # Keep these lines at the end of the file
 # vim: softtabstop=0 noexpandtab
index 0511117..5c683ba 100644 (file)
@@ -98,6 +98,8 @@ is($@, "", 'qr/(?[ [a] ])/ can be interpolated');
 
 like("B", qr/(?[ [B] | ! ( [^B] ) ])/, "[perl #125892]");
 
+like("a", qr/(?[ (?#comment) [a]])/, "Can have (?#comments)");
+
 if (! is_miniperl() && locales_enabled('LC_CTYPE')) {
     my $utf8_locale = find_utf8_ctype_locale;
     SKIP: {