-
Notifications
You must be signed in to change notification settings - Fork 560
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
Documentation "The Ellipsis Statement" of perlsyn #14054
Comments
From [email protected]This is a bug report for perl from ina.cpan@gmail.com, The Ellipsis Statement of http://perldoc.perl.org/perlsyn.html said, You can use a ; inside your block to denote that the { ... } is a 1. @transformed = map {; ... } @input; # ; disambiguates But results are: C:\>c:\strawberry\perl520\bin\perl -ce "map{;...}()" C:\>c:\strawberry\perl520\bin\perl -ce "map{...;}()" Flags: Site configuration information for perl 5.20.0: Configured by strawberry-perl at Fri May 30 23:27:10 2014. Summary of my perl5 (revision 5 version 20 subversion 0) configuration: Platform: @INC for perl 5.20.0: Environment for perl 5.20.0: |
From @jkeenanOn Sun Aug 31 00:43:58 2014, ina.cpan@gmail.com wrote:
And here's confirmation of the bug with the example code found in 'perlsyn': $ perl 122661.pl My hunch would be that in the case of { ...; } perl is not recognizing ... as the ellipsis statemente but rather as the flip-flop operator. If I use perlbrew to switch to older versions of perl, I get exactly the same syntax error output in versions older than the ellipsis statement. ##### $ perlbrew switch perl-5.10.1 $ perlbrew switch perl-5.8.9 Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @rjbs* ina cpan <perlbug-followup@perl.org> [2014-08-31T03:43:59]
I am somewhat baffled, as I have never seen "put semicolon at the end" used for -- |
From @ikegamiOn Tue, Sep 2, 2014 at 9:31 PM, Ricardo Signes <perl.p5p@rjbs.manxome.org>
Correct. Documentation error. Nothing to do with "..."
|
From [email protected]I think so too. 2014-09-03 10:31 GMT+09:00 Ricardo Signes via RT <perlbug-followup@perl.org>
|
From @jkeenanOn Tue Sep 02 18:31:46 2014, perl.p5p@rjbs.manxome.org wrote:
In order to move this ticket toward resolution, I have prepared the patch attached. Please review. Thank you very much. -- |
From @jkeenan0001-Semicolon-before-ellipsis-inside-block-disambiguates.patchFrom a10e023e280a942393a96816c96bae288a77f9d4 Mon Sep 17 00:00:00 2001
From: James E Keenan <[email protected]>
Date: Sat, 13 Sep 2014 08:51:48 -0400
Subject: [PATCH] Semicolon before ellipsis inside block disambiguates.
Correct documentation which indicated that, inside a block, a semicolon after
an ellipsis statement would disambiguate between a block and a hash reference
constructor. The semicolon must precede the ellipsis to perform this
disambiguation.
Add tests to demonstrate that whitespace around the ellipsis statement does
not impeded the disambiguation.
For: RT #122661
---
pod/perlsyn.pod | 11 +++++------
t/op/yadayada.t | 31 ++++++++++++++++++++++++++++---
2 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index cea4d50..73421a4 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -788,14 +788,13 @@ syntax error if Perl doesn't guess that the C<{ ... }> is a block. In that
case, it doesn't think the C<...> is an ellipsis because it's expecting an
expression instead of a statement:
- @transformed = map { ... } @input; # syntax error
+ @transformed = map { ... } @input; # syntax error
-You can use a C<;> inside your block to denote that the C<{ ... }> is a
-block and not a hash reference constructor. Now the ellipsis works:
+Inside your block, you can use a C<;> before the ellipsis to denote that the
+C<{ ... }> is a block and not a hash reference constructor. Now the ellipsis
+works:
- @transformed = map {; ... } @input; # ; disambiguates
-
- @transformed = map { ...; } @input; # ; disambiguates
+ @transformed = map {; ... } @input; # ';' disambiguates
Note: Some folks colloquially refer to this bit of punctuation as a
"yada-yada" or "triple-dot", but its true name
diff --git a/t/op/yadayada.t b/t/op/yadayada.t
index 770a51e..a213bec 100644
--- a/t/op/yadayada.t
+++ b/t/op/yadayada.t
@@ -8,14 +8,39 @@ BEGIN {
use strict;
-plan 5;
+plan 9;
-my $err = "Unimplemented at $0 line " . ( __LINE__ + 2 ) . ".\n";
+my $err;
+my $err1 = "Unimplemented at $0 line ";
+my $err2 = ".\n";
+$err = $err1 . ( __LINE__ + 1 ) . $err2;
eval { ... };
+is $@, $err, "Execution of ellipsis statement reported 'Unimplemented' code";
+$@ = '';
-is $@, $err;
+note("RT #122661: Semicolon before ellipsis statement disambiguates to indicate block rather than hash reference");
+my @input = (3..5);
+my @transformed;
+$err = $err1 . ( __LINE__ + 1 ) . $err2;
+eval { @transformed = map {; ... } @input; };
+is $@, $err, "Disambiguation case 1";
+$@ = '';
+$err = $err1 . ( __LINE__ + 1 ) . $err2;
+eval { @transformed = map {;...} @input; };
+is $@, $err, "Disambiguation case 2";
+$@ = '';
+
+$err = $err1 . ( __LINE__ + 1 ) . $err2;
+eval { @transformed = map {; ...} @input; };
+is $@, $err, "Disambiguation case 3";
+$@ = '';
+
+$err = $err1 . ( __LINE__ + 1 ) . $err2;
+eval { @transformed = map {;... } @input; };
+is $@, $err, "Disambiguation case 4";
+$@ = '';
#
# Regression tests, making sure ... is still parsable as an operator.
--
1.9.1
|
From @demerphqOn 3 September 2014 06:50, Eric Brine <ikegami@adaelis.com> wrote:
I think you could argue this is a bug too, although in the same category as perl -le'map { no warnings; $x++ } 1..10' That is the parser thinks the open { is the beginning of a hash constructor. This works: perl -le'map {; no warnings; $x++ } 1..10' because the {; tells the parser early enough "this can't be a hash Personally I would love to see a "once and for all" fix to this class of Yves -- |
From @cpansproutOn Sat Sep 13 06:07:36 2014, jkeenan wrote:
Your patch is good. -- Father Chrysostomos |
From @jkeenanOn Sat Sep 13 06:46:05 2014, sprout wrote:
Thanks for the review. Applied to blead in Marking ticket resolved. -- |
@jkeenan - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#122661 (status was 'resolved')
Searchable as RT122661$
The text was updated successfully, but these errors were encountered: