Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s/// substitutions allow the null pattern in Rakudo (but not in STD) #2326

Closed
p6rt opened this issue Jan 12, 2011 · 11 comments
Closed

s/// substitutions allow the null pattern in Rakudo (but not in STD) #2326

p6rt opened this issue Jan 12, 2011 · 11 comments

Comments

@p6rt
Copy link

p6rt commented Jan 12, 2011

Migrated from rt.perl.org#82142 (status was 'resolved')

Searchable as RT82142$

@p6rt
Copy link
Author

p6rt commented Jan 12, 2011

From @masak

<masak> rakudo​: $_ = 'foo'; s​:g/ /a/; say 'alive'
<p6eval> rakudo 8681da​: OUTPUT«alive␤»
<masak> std​: $_ = 'foo'; s​:g/ /a/
<p6eval> std 625303c​: OUTPUT«�[31m===�[0mSORRY!�[31m===�[0m␤Null
pattern not allowed [...] FAILED 00​:01 122m␤»
* masak submits rakudobug

@p6rt
Copy link
Author

p6rt commented Feb 6, 2011

From anteusz@freemail.hu

Hi,

Here is the patch..

Jaffa4

@p6rt
Copy link
Author

p6rt commented Feb 6, 2011

From anteusz@freemail.hu

Grammar.pm

@p6rt
Copy link
Author

p6rt commented Feb 7, 2011

From @moritz

And as an actual patch​:

--- a/src/Perl6/Grammar.pm
+++ b/src/Perl6/Grammar.pm
@​@​ -1477,6 +1477,7 @​@​ token quote​:sym<s> {
  }
  <.setup_quotepairs>
  [
+ | '/' \s* '/' <.panic​: "Null regex in substitution not allowed">
  | '/' <p6regex=.LANG('Regex','nibbler')> <?[/]> <quote_EXPR​:
'​:qq'> <.old_rx_mods>?
  | '[' <p6regex=.LANG('Regex','nibbler')> ']'
  <.ws> [ '=' || <.panic​: "Missing assignment operator"> ]

But I fear this is the wrong approach. Instead of doing a separate null
pattern check in every quoting construct, the check should be done in
the regex parsing code once, as STD.pm6 does it.

But I'll leave the final say to pmichaud or jnthn.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Feb 7, 2011

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 7, 2011

From @pmichaud

On Mon, Feb 07, 2011 at 11​:36​:22AM +0100, Moritz Lenz wrote​:

+ | '/' \s* '/' <.panic​: "Null regex in substitution not allowed">

But I fear this is the wrong approach. Instead of doing a separate
null pattern check in every quoting construct, the check should be
done in the regex parsing code once, as STD.pm6 does it.

I completely agree; the check for null regex needs to be done in the
regex parsing code. In particular, the following regex should also
produce a "null pattern" exception of some sort, which the patch
doesn't address​:

  / abc | | def /

Patch rejected; thanks for submitting!

Pm

@p6rt
Copy link
Author

p6rt commented Feb 7, 2011

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 9, 2011

From anteusz@freemail.hu

2011.02.07. 11​:36 keltezéssel, Moritz Lenz via RT írta​:

And as an actual patch​:

--- a/src/Perl6/Grammar.pm
+++ b/src/Perl6/Grammar.pm
@​@​ -1477,6 +1477,7 @​@​ token quote​:sym<s> {
}
<.setup_quotepairs>
[
+ | '/' \s* '/'<.panic​: "Null regex in substitution not allowed">
| '/'<p6regex=.LANG('Regex','nibbler')> <?[/]> <quote_EXPR​:
'​:qq'> <.old_rx_mods>?
| '['<p6regex=.LANG('Regex','nibbler')> ']'
<.ws> [ '=' ||<.panic​: "Missing assignment operator"> ]

But I fear this is the wrong approach. Instead of doing a separate null
pattern check in every quoting construct, the check should be done in
the regex parsing code once, as STD.pm6 does it.

But I'll leave the final say to pmichaud or jnthn.

Cheers,
Moritz

Note , this approach has been used already in the same grammar.pm. If
you search for Null regex, you will find it.

Jaffa4

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @coke

On Wed Jan 12 09​:29​:31 2011, masak wrote​:

<masak> rakudo​: $_ = 'foo'; s​:g/ /a/; say 'alive'
<p6eval> rakudo 8681da​: OUTPUT«alive␤»
<masak> std​: $_ = 'foo'; s​:g/ /a/
<p6eval> std 625303c​: OUTPUT«�[31m===�[0mSORRY!�[31m===�[0m␤Null
pattern not allowed [...] FAILED 00​:01 122m␤»
* masak submits rakudobug

This now dies correctly​:

19​:46 < [Coke]> m​: $_ = 'foo'; s​:g/ /a/; say 'alive'
19​:46 <+camelia> rakudo-moar 974d00​: OUTPUT«===SORRY!=== Error while compiling
  /tmp/LZQwMHpP5h␤Null regex not allowed␤at
  /tmp/LZQwMHpP5h​:1␤------> $_ = 'foo'; s​:g/ ⏏/a/; say 'alive'␤
  expecting any of​:␤ colon pair (restricted)␤»

Closable with tests.
--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @moritz

On Tue Feb 25 16​:46​:33 2014, coke wrote​:

On Wed Jan 12 09​:29​:31 2011, masak wrote​:

<masak> rakudo​: $_ = 'foo'; s​:g/ /a/; say 'alive'
<p6eval> rakudo 8681da​: OUTPUT«alive␤»
<masak> std​: $_ = 'foo'; s​:g/ /a/
<p6eval> std 625303c​: OUTPUT«�[31m===�[0mSORRY!�[31m===�[0m␤Null
pattern not allowed [...] FAILED 00​:01 122m␤»
* masak submits rakudobug

This now dies correctly​:

19​:46 < [Coke]> m​: $_ = 'foo'; s​:g/ /a/; say 'alive'
19​:46 <+camelia> rakudo-moar 974d00​: OUTPUT«===SORRY!=== Error while
compiling
/tmp/LZQwMHpP5h␤Null regex not allowed␤at
/tmp/LZQwMHpP5h​:1␤------> $_ = 'foo'; s​:g/ ⏏/a/; say
'alive'␤
expecting any of​:␤ colon pair (restricted)␤»

Closable with tests.

We have tests now​:

commit fb9afbd6a49546a69b002816da99e0d0b5a0afc8
Author​: Moritz Lenz <mlenz@​noris.net>
Date​: Wed Feb 26 09​:24​:27 2014 +0100

  Test for RT #​82142

Inline Patch
diff --git a/S32-exceptions/misc.t b/S32-exceptions/misc.t
index 1dd6284..52938e6 100644
--- a/S32-exceptions/misc.t
+++ b/S32-exceptions/misc.t
@@ -142,6 +142,8 @@ throws_like q[/ a & /], X::Syntax::Regex::NullRegex;
 # RT 67554
 throws_like q{/ [] /}, X::Syntax::Regex::NullRegex;
 throws_like q{/ | /}, X::Syntax::Regex::NullRegex;
+# RT #82142
+throws_like q{s//b/}, X::Syntax::Regex::NullRegex;
 
 
 throws_like 'sub f($a?, $b) { }', X::Parameter::WrongOrder,

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

@moritz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant