From 9442e3b8d7c9c3e8121cad5682064cfc3e185f32 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 12 Apr 2011 11:50:06 -0600 Subject: [PATCH] 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. --- pod/perldiag.pod | 10 ++++++++-- regcomp.c | 17 +++++++++++------ t/re/reg_mesg.t | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index e9c5543..88c55a8 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. <-- 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. =item Sequence \%s... not terminated in regex; marked by <-- HERE in m/%s/ diff --git a/regcomp.c b/regcomp.c index e37bc46..0858841 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 976798c..d6b343b 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)/', -- 2.7.4