Skip to content

Commit

Permalink
remove use of ' as a package separator
Browse files Browse the repository at this point in the history
In general for tests I translate them to using :: if the test wasn't
specifically for ', and the test didn't duplicate a similar test
that did test ::.

This doesn't just change the parsing stage from accepting ' instead of
:: in names, but also removes the translation from ' to :: done in
several places, but that's really there to support the syntax.
  • Loading branch information
tonycoz committed Jun 19, 2024
1 parent 531b623 commit 197e7dc
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 268 deletions.
9 changes: 1 addition & 8 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -3004,12 +3004,6 @@ EXpx |char * |scan_word |NN char *s \
|STRLEN destlen \
|int allow_package \
|NN STRLEN *slp
EXpx |char * |scan_word6 |NN char *s \
|NN char *dest \
|STRLEN destlen \
|int allow_package \
|NN STRLEN *slp \
|bool warn_tick
Cp |U32 |seed
: Only used by perl.c/miniperl.c, but defined in caretx.c
ep |void |set_caret_X
Expand Down Expand Up @@ -5901,8 +5895,7 @@ S |void |parse_ident |NN char **s \
|NN char * const e \
|int allow_package \
|bool is_utf8 \
|bool check_dollar \
|bool tick_warn
|bool check_dollar
S |int |pending_ident
RS |char * |scan_const |NN char *start
RS |char * |scan_formline |NN char *s
Expand Down
3 changes: 1 addition & 2 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@
# define lop(a,b,c) S_lop(aTHX_ a,b,c)
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
# define no_op(a,b) S_no_op(aTHX_ a,b)
# define parse_ident(a,b,c,d,e,f,g) S_parse_ident(aTHX_ a,b,c,d,e,f,g)
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
# define pending_ident() S_pending_ident(aTHX)
# define scan_const(a) S_scan_const(aTHX_ a)
# define scan_formline(a) S_scan_formline(aTHX_ a)
Expand Down Expand Up @@ -1760,7 +1760,6 @@
# define report_uninit(a) Perl_report_uninit(aTHX_ a)
# define scan_str(a,b,c,d,e) Perl_scan_str(aTHX_ a,b,c,d,e)
# define scan_word(a,b,c,d,e) Perl_scan_word(aTHX_ a,b,c,d,e)
# define scan_word6(a,b,c,d,e,f) Perl_scan_word6(aTHX_ a,b,c,d,e,f)
# define skipspace_flags(a,b) Perl_skipspace_flags(aTHX_ a,b)
# define sv_magicext_mglob(a) Perl_sv_magicext_mglob(aTHX_ a)
# define sv_only_taint_gmagic Perl_sv_only_taint_gmagic
Expand Down
28 changes: 3 additions & 25 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
* method name.
*
* leaves last_separator pointing to the beginning of the
* last package separator (either ' or ::) or 0
* last package separator (::) or 0
* if none was found.
*
* leaves name pointing at the beginning of the
Expand All @@ -1176,11 +1176,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
const char *name_cursor = name;
const char * const name_em1 = name_end - 1; /* name_end minus 1 */
for (name_cursor = name; name_cursor < name_end ; name_cursor++) {
if (*name_cursor == '\'') {
last_separator = name_cursor;
name = name_cursor + 1;
}
else if (name_cursor < name_em1 && *name_cursor == ':' && name_cursor[1] == ':') {
if (name_cursor < name_em1 && *name_cursor == ':' && name_cursor[1] == ':') {
last_separator = name_cursor++;
name = name_cursor + 1;
}
Expand Down Expand Up @@ -1782,7 +1778,6 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,
const char *name_cursor;
const char *const name_end = nambeg + full_len;
const char *const name_em1 = name_end - 1;
char smallbuf[64]; /* small buffer to avoid a malloc when possible */

PERL_ARGS_ASSERT_PARSE_GV_STASH_NAME;

Expand All @@ -1796,8 +1791,7 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,

for (name_cursor = *name; name_cursor < name_end; name_cursor++) {
if (name_cursor < name_em1 &&
((*name_cursor == ':' && name_cursor[1] == ':')
|| *name_cursor == '\''))
(*name_cursor == ':' && name_cursor[1] == ':'))
{
if (!*stash)
*stash = PL_defstash;
Expand All @@ -1812,22 +1806,6 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,
key = *name;
*len += 2;
}
else { /* using ' for package separator */
/* use our pre-allocated buffer when possible to save a malloc */
char *tmpbuf;
if ( *len+2 <= sizeof smallbuf)
tmpbuf = smallbuf;
else {
/* only malloc once if needed */
if (tmpfullbuf == NULL) /* only malloc&free once, a little more than needed */
Newx(tmpfullbuf, full_len+2, char);
tmpbuf = tmpfullbuf;
}
Copy(*name, tmpbuf, *len, char);
tmpbuf[(*len)++] = ':';
tmpbuf[(*len)++] = ':';
key = tmpbuf;
}
gvp = (GV**)hv_fetch(*stash, key, is_utf8 ? -((I32)*len) : (I32)*len, add);
*gv = gvp ? *gvp : NULL;
if (!*gv || *gv == (const GV *)&PL_sv_undef) {
Expand Down
2 changes: 1 addition & 1 deletion lib/overload.t
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ is eval {"$a"}, overload::StrVal($a),
{
package mane;
use overload q\""\ => "bear::strength";
use overload bool => "bear'bouillon";
use overload bool => "bear::bouillon";
}
@bear::ISA = 'food';
sub food::strength { 'twine' }
Expand Down
18 changes: 1 addition & 17 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ results.
of Perl. Check the #! line, or manually feed your script into
Perl yourself.

=item Bad name after %s
=item Bad name after %s::

(F) You started to name a symbol by using a package prefix, and then
didn't finish the symbol. In particular, you can't interpolate outside
Expand Down Expand Up @@ -4782,22 +4782,6 @@ C<sysread()>ing a file, or when seeking past the end of a scalar opened
for I/O (in anticipation of future reads and to imitate the behavior
with real files).

=item Old package separator "'" deprecated

(D deprecated::apostrophe_as_package_separator, syntax) You used the old package
separator "'" in a variable, subroutine or package name. Support for the
old package separator will be removed in Perl 5.42.

=item Old package separator used in string

(D deprecated::apostrophe_as_package_separator, syntax) You used the old package
separator, "'", in a variable named inside a double-quoted string; e.g.,
C<"In $name's house">. This is equivalent to C<"In $name::s house">. If
you meant the former, put a backslash before the apostrophe
(C<"In $name\'s house">).

Support for the old package separator will be removed in Perl 5.42.

=item Only scalar fields can take a :param attribute

(F) You tried to apply the C<:param> attribute to an array or hash field.
Expand Down
7 changes: 1 addition & 6 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions t/comp/package.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ $bar = 4;

{
package ABC;
no warnings qw(syntax deprecated);
$blurfl = 5;
$main'a = $'b;
}
{
no warnings qw(syntax deprecated);
$ABC'dyick = 6;
$main::a = $::b;
}

$ABC::dyick = 6;

$xyz = 2;

$main = join(':', sort(keys %main::));
Expand All @@ -36,13 +33,10 @@ $ABC = join(':', sort(keys %ABC::));
if ('a' lt 'A') {
print $xyz eq 'bar:main:new:xyz:ABC' ? "ok 1\n" : "not ok 1 '$xyz'\n";
} else {
print $xyz eq 'ABC:BEGIN:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
}
print $ABC eq 'BEGIN:blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
{
no warnings qw(syntax deprecated);
print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
print $xyz eq 'ABC:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
}
print $ABC eq 'blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
print $main::blurfl == 123 ? "ok 3\n" : "not ok 3\n";

package ABC;

Expand Down
37 changes: 10 additions & 27 deletions t/comp/parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
chdir 't' if -d 't';
}

print "1..191\n";
print "1..189\n";

sub failed {
my ($got, $expected, $name) = @_;
Expand Down Expand Up @@ -222,8 +222,12 @@ EOF
# tests for "Bad name"
eval q{ foo::$bar };
like( $@, qr/Bad name after foo::/, 'Bad name after foo::' );
eval q{ foo''bar };
like( $@, qr/Bad name after foo'/, 'Bad name after foo\'' );
{
# since ' is no longer usable in symbols, the error is no longer "Bad name"
no warnings "syntax"; # suppress String found where operator expeected
eval q{ foo''bar };
like( $@, qr/syntax error at \(eval \d+\) line 1, near "foo''/, 'Syntax error for foo\'' );
}

# test for ?: context error
eval q{($a ? $x : ($y)) = 5};
Expand Down Expand Up @@ -368,12 +372,11 @@ like($@, qr/BEGIN failed--compilation aborted/, 'BEGIN 7' );
}

{
no warnings;
# [perl #113016] CORE::print::foo
sub CORE'print'foo { 43 } # apostrophes intentional; do not tempt fate
sub CORE'foo'bar { 43 }
sub CORE::print::foo { 43 }
sub CORE::foo::bar { 43 }
is CORE::print::foo, 43, 'CORE::print::foo is not CORE::print ::foo';
is scalar eval "CORE::foo'bar", 43, "CORE::foo'bar is not an error";
is scalar eval "CORE::foo::bar", 43, "CORE::foo'bar is not an error";
}

# bug #71748
Expand Down Expand Up @@ -451,11 +454,6 @@ END
eval 's/${<<END}//';
eval 's//${<<END}/';
print "ok ", ++$test, " - unterminated here-docs in s/// in string eval\n";
{
no warnings qw(syntax deprecated);
sub 'Hello'_he_said (_);
}
is prototype "Hello::_he_said", '_', 'initial tick in sub declaration';

{
my @x = 'string';
Expand All @@ -474,21 +472,6 @@ for my $pkg(()){}
$pkg = 3;
is $pkg, 3, '[perl #114942] for my $foo()){} $foo';

# Check that format 'Foo still works after removing the hack from
# force_word
{
no warnings qw(syntax deprecated);
$test++;
format 'one =
ok @<< - format 'foo still works
$test
.
}
{
local $~ = "one";
write();
}
$test++;
format ::two =
ok @<< - format ::foo still works
Expand Down
18 changes: 17 additions & 1 deletion t/lib/croak/toke
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ has cxxc => (
EXPECT
Bareword found where operator expected (Do you need to predeclare "isa"?) at - line 9, near "isa => 'Int"
(Might be a runaway multi-line '' string starting on line 4)
Bad name after Int' at - line 9.
syntax error at - line 9, near "isa => 'Int"
Execution of - aborted due to compilation errors.
########
# NAME Bad name after :: (with other helpful messages)
sub has{}
Expand Down Expand Up @@ -611,3 +612,18 @@ syntax error at - line 2, near "[
=="
(Might be a runaway multi-line // string starting on line 1)
Execution of - aborted due to compilation errors.
########
# NAME tick in names: initial character of sub name
sub 'Hello'_he_said (_);
EXPECT
Illegal declaration of anonymous subroutine at - line 1.
########
# NAME tick in names: initial character of format name
format 'one =
ok @<< - format 'foo still works
$test
.
EXPECT
syntax error at - line 2, near "ok @<< - format '"
(Might be a runaway multi-line '' string starting on line 1)
Execution of - aborted due to compilation errors.
31 changes: 8 additions & 23 deletions t/lib/warnings/toke
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ sort ("")
EXPECT

########
# NAME ' no longer is part of the symbol character set
# previously these would parse like:
# "${foo'bar}", but now they parse like "${foo}'bar"
# and any ' parsing for symbols is now gone, so no warning
@foo::bar = 1..3;
() = "$foo'bar";
() = "@foo'bar";
Expand All @@ -421,19 +425,8 @@ no warnings 'syntax', 'deprecated' ;
() = "@foo'bar";
() = "$#foo'bar";
EXPECT
Old package separator used in string at - line 2.
(Did you mean "$foo\'bar" instead?)
Old package separator used in string at - line 3.
(Did you mean "@foo\'bar" instead?)
Old package separator used in string at - line 4.
(Did you mean "$#foo\'bar" instead?)
Old package separator used in string at - line 6.
(Did you mean "$foo\'bar" instead?)
Old package separator used in string at - line 7.
(Did you mean "@foo\'bar" instead?)
Old package separator used in string at - line 8.
(Did you mean "$#foo\'bar" instead?)
########
# similar to the test above in that the parsing has changed
use warnings 'syntax'; use utf8;
@fooл::barл = 1..3;
() = "$fooл'barл";
Expand All @@ -444,12 +437,7 @@ no warnings 'syntax', 'deprecated' ;
() = "@fooл'barл";
() = "$#fooл'barл";
EXPECT
Old package separator used in string at - line 3.
(Did you mean "$fooл\'barл" instead?)
Old package separator used in string at - line 4.
(Did you mean "@fooл\'barл" instead?)
Old package separator used in string at - line 5.
(Did you mean "$#fooл\'barл" instead?)
Possible unintended interpolation of @fooл in string at - line 5.
########
# NAME deprecation of ' in names
sub foo'bar { 1 }
Expand All @@ -458,11 +446,8 @@ $a'b = 1;
%a'd = ();
package a'e;
EXPECT
Old package separator "'" deprecated at - line 1.
Old package separator "'" deprecated at - line 2.
Old package separator "'" deprecated at - line 3.
Old package separator "'" deprecated at - line 4.
Old package separator "'" deprecated at - line 5.
OPTION fatal
Illegal declaration of subroutine main::foo at - line 1.
########
# toke.c
use warnings 'ambiguous' ;
Expand Down
8 changes: 1 addition & 7 deletions t/op/method.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BEGIN {
use strict;
no warnings 'once';

plan(tests => 163);
plan(tests => 161);

{
# RT #126042 &{1==1} * &{1==1} would crash
Expand Down Expand Up @@ -253,12 +253,6 @@ sub OtherSouper::method { "Isidore Ropen, Draft Manager" }
my @ret = $o->SUPER::method('whatever');
::is $ret[0], $o, 'object passed to SUPER::method';
::is $ret[1], 'whatever', 'argument passed to SUPER::method';
{
no warnings qw(syntax deprecated);
@ret = $o->SUPER'method('whatever');
}
::is $ret[0], $o, "object passed to SUPER'method";
::is $ret[1], 'whatever', "argument passed to SUPER'method";
@ret = Saab->SUPER::method;
::is $ret[0], 'Saab', "package name passed to SUPER::method";
@ret = OtherSaab->SUPER::method;
Expand Down
Loading

0 comments on commit 197e7dc

Please sign in to comment.