summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2011-04-12 11:50:06 -0600
committerKarl Williamson <public@khwilliamson.com>2011-04-12 12:34:50 -0600
commit9442e3b8d7c9c3e8121cad5682064cfc3e185f32 (patch)
tree84f2c601cea8ab521cde26e9e8d06affd5553cc4
parent0c96c706fef52effd833861ae408c0cedef51125 (diff)
downloadperl-9442e3b8d7c9c3e8121cad5682064cfc3e185f32.tar.gz
regcomp: Improve error message for (?-d:...)
As agreed, this improvement is going into 5.14. A customized message is output, instead of a generic one.
-rw-r--r--pod/perldiag.pod10
-rw-r--r--regcomp.c17
-rw-r--r--t/re/reg_mesg.t1
3 files changed, 20 insertions, 8 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index e9c5543871..88c55a8e68 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -4021,6 +4021,13 @@ expression compiler gave it.
(F syntax, regexp) The regular expression pattern had too many occurrences
of the specified modifier. Remove the extraneous ones.
+=item Regexp modifier "%c" may not appear after the "-"
+
+(F regexp) Turning off the given modifier has the side effect of turning
+on another one. Perl currently doesn't allow this. Reword the regular
+expression to use the modifier you want to turn on (and place it before
+the minus), instead of the one you want to turn off.
+
=item Regexp modifiers "/%c" and "/%c" are mutually exclusive
(F syntax, regexp) The regular expression pattern had more than one of these
@@ -4168,8 +4175,7 @@ where the problem was discovered. See L<perlre>.
<-- HERE shows in the regular expression about where the problem was
discovered. This happens when using the C<(?^...)> construct to tell
Perl to use the default regular expression modifiers, and you
-redundantly specify a default modifier; or having a modifier that can't
-be turned off (such as C<"p"> or C<"l">) after a minus. For other
+redundantly specify a default modifier. For other
causes, see L<perlre>.
=item Sequence \%s... not terminated in regex; marked by <-- HERE in m/%s/
diff --git a/regcomp.c b/regcomp.c
index e37bc46c2a..085884174a 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -7086,7 +7086,7 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
goto excess_modifier;
}
else if (flagsp == &negflags) {
- goto fail_modifiers;
+ goto neg_modifier;
}
cs = REGEX_LOCALE_CHARSET;
has_charset_modifier = LOCALE_PAT_MOD;
@@ -7097,14 +7097,14 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
goto excess_modifier;
}
else if (flagsp == &negflags) {
- goto fail_modifiers;
+ goto neg_modifier;
}
cs = REGEX_UNICODE_CHARSET;
has_charset_modifier = UNICODE_PAT_MOD;
break;
case ASCII_RESTRICT_PAT_MOD:
if (flagsp == &negflags) {
- goto fail_modifiers;
+ goto neg_modifier;
}
if (has_charset_modifier) {
if (cs != REGEX_ASCII_RESTRICTED_CHARSET) {
@@ -7119,11 +7119,12 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
has_charset_modifier = ASCII_RESTRICT_PAT_MOD;
break;
case DEPENDS_PAT_MOD:
- if (has_use_defaults
- || flagsp == &negflags)
- {
+ if (has_use_defaults) {
goto fail_modifiers;
}
+ else if (flagsp == &negflags) {
+ goto neg_modifier;
+ }
else if (has_charset_modifier) {
goto excess_modifier;
}
@@ -7149,6 +7150,10 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
vFAIL3("Regexp modifiers \"%c\" and \"%c\" are mutually exclusive", has_charset_modifier, *(RExC_parse - 1));
}
/*NOTREACHED*/
+ neg_modifier:
+ RExC_parse++;
+ vFAIL2("Regexp modifier \"%c\" may not appear after the \"-\"", *(RExC_parse - 1));
+ /*NOTREACHED*/
case ONCE_PAT_MOD: /* 'o' */
case GLOBAL_PAT_MOD: /* 'g' */
if (SIZE_ONLY && ckWARN(WARN_REGEXP)) {
diff --git a/t/re/reg_mesg.t b/t/re/reg_mesg.t
index 976798c132..d6b343b1c3 100644
--- a/t/re/reg_mesg.t
+++ b/t/re/reg_mesg.t
@@ -69,6 +69,7 @@ my @death =
'/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive in regex; marked by {#} in m/(?da{#}:foo)/',
'/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice in regex; marked by {#} in m/(?lil{#}:foo)/',
'/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice in regex; marked by {#} in m/(?aaia{#}:foo)/',
+'/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" in regex; marked by {#} in m/(?i-l{#}:foo)/',
'/((x)/' => 'Unmatched ( in regex; marked by {#} in m/({#}(x)/',