Skip to content

Commit a4d969d

Browse files
committed
feature apostrophe_as_package_separator implementation
1 parent c4ec484 commit a4d969d

File tree

11 files changed

+188
-91
lines changed

11 files changed

+188
-91
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -6105,6 +6105,7 @@ t/lib/Devel/switchd_empty.pm Module for t/run/switchd.t
61056105
t/lib/Devel/switchd_goto.pm Module for t/run/switchd.t
61066106
t/lib/Dies.pm For test case in op/require_errors.t
61076107
t/lib/feature/api Test API for checking features enabled/disabled
6108+
t/lib/feature/apos_as_pack_sep Tests for enabling/disabling apostrophe_as_package_separator feature
61086109
t/lib/feature/bareword_filehandles Tests for enabling/disabling bareword_filehandles feature
61096110
t/lib/feature/bits Tests for feature bit handling
61106111
t/lib/feature/bundle Tests for feature bundles

embed.fnc

+1-8
Original file line numberDiff line numberDiff line change
@@ -3018,12 +3018,6 @@ EXpx |char * |scan_word |NN char *s \
30183018
|STRLEN destlen \
30193019
|int allow_package \
30203020
|NN STRLEN *slp
3021-
EXpx |char * |scan_word6 |NN char *s \
3022-
|NN char *dest \
3023-
|STRLEN destlen \
3024-
|int allow_package \
3025-
|NN STRLEN *slp \
3026-
|bool warn_tick
30273021
Cp |U32 |seed
30283022
: Only used by perl.c/miniperl.c, but defined in caretx.c
30293023
ep |void |set_caret_X
@@ -5909,8 +5903,7 @@ S |void |parse_ident |NN char **s \
59095903
|NN char * const e \
59105904
|int allow_package \
59115905
|bool is_utf8 \
5912-
|bool check_dollar \
5913-
|bool tick_warn
5906+
|bool check_dollar
59145907
S |int |pending_ident
59155908
RS |char * |scan_const |NN char *start
59165909
RS |char * |scan_formline |NN char *s

embed.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@
16291629
# define intuit_more(a,b) S_intuit_more(aTHX_ a,b)
16301630
# define lop(a,b,c) S_lop(aTHX_ a,b,c)
16311631
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
1632-
# define parse_ident(a,b,c,d,e,f,g) S_parse_ident(aTHX_ a,b,c,d,e,f,g)
1632+
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
16331633
# define pending_ident() S_pending_ident(aTHX)
16341634
# define scan_const(a) S_scan_const(aTHX_ a)
16351635
# define scan_formline(a) S_scan_formline(aTHX_ a)
@@ -1766,7 +1766,6 @@
17661766
# define report_uninit(a) Perl_report_uninit(aTHX_ a)
17671767
# define scan_str(a,b,c,d,e) Perl_scan_str(aTHX_ a,b,c,d,e)
17681768
# define scan_word(a,b,c,d,e) Perl_scan_word(aTHX_ a,b,c,d,e)
1769-
# define scan_word6(a,b,c,d,e,f) Perl_scan_word6(aTHX_ a,b,c,d,e,f)
17701769
# define skipspace_flags(a,b) Perl_skipspace_flags(aTHX_ a,b)
17711770
# define sv_magicext_mglob(a) Perl_sv_magicext_mglob(aTHX_ a)
17721771
# define sv_only_taint_gmagic Perl_sv_only_taint_gmagic

lib/overload.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,7 @@ is eval {"$a"}, overload::StrVal($a),
23952395
{
23962396
package mane;
23972397
use overload q\""\ => "bear::strength";
2398-
use overload bool => "bear'bouillon";
2398+
use overload bool => "bear::bouillon";
23992399
}
24002400
@bear::ISA = 'food';
24012401
sub food::strength { 'twine' }

pod/perldata.pod

+8-13
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,17 @@ generic characters, and identifiers should match
136136
That is, any word character in the ASCII range, as long as the first
137137
character is not a digit.
138138

139-
There are two package separators in Perl: A double colon (C<::>) and a single
140-
quote (C<'>). Use of C<'> as the package separator is deprecated and will be
141-
removed in Perl 5.40. Normal identifiers can start or end with a double
142-
colon, and can contain several parts delimited by double colons. Single
143-
quotes have similar rules, but with the exception that they are not legal at
144-
the end of an identifier: That is, C<$'foo> and C<$foo'bar> are legal, but
145-
C<$foo'bar'> is not.
139+
There is one package separator in Perl: A double colon (C<::>).
140+
Normal identifiers can start or end with a double colon, and can
141+
contain several parts delimited by double colons.
142+
143+
Previously you could use C<'> as a package separator, this was removed
144+
in Perl 5.42.
146145

147146
Additionally, if the identifier is preceded by a sigil --
148147
that is, if the identifier is part of a variable name -- it
149148
may optionally be enclosed in braces.
150149

151-
While you can mix double colons with singles quotes, the quotes must come
152-
after the colons: C<$::::'foo> and C<$foo::'bar> are legal, but C<$::'::foo>
153-
and C<$foo'::bar> are not.
154-
155150
Put together, a grammar to match a basic identifier becomes
156151

157152
/
@@ -164,9 +159,9 @@ Put together, a grammar to match a basic identifier becomes
164159
)
165160
)
166161
(?<normal_identifier>
167-
(?: :: )* '?
162+
(?: :: )*
168163
(?&basic_identifier)
169-
(?: (?= (?: :: )+ '? | (?: :: )* ' ) (?&normal_identifier) )?
164+
(?: (?= :: ) (?&normal_identifier) )?
170165
(?: :: )*
171166
)
172167
(?<basic_identifier>

proto.h

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

t/comp/package.t

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#!./perl
22

3-
BEGIN {
4-
@INC = qw(. ../lib);
5-
chdir 't' if -d 't';
6-
}
7-
83
print "1..14\n";
94

105
$blurfl = 123;
@@ -18,14 +13,10 @@ $bar = 4;
1813

1914
{
2015
package ABC;
21-
no warnings qw(syntax deprecated);
2216
$blurfl = 5;
2317
$main'a = $'b;
2418
}
25-
{
26-
no warnings qw(syntax deprecated);
27-
$ABC'dyick = 6;
28-
}
19+
$ABC'dyick = 6;
2920
3021
$xyz = 2;
3122
@@ -36,13 +27,10 @@ $ABC = join(':', sort(keys %ABC::));
3627
if ('a' lt 'A') {
3728
print $xyz eq 'bar:main:new:xyz:ABC' ? "ok 1\n" : "not ok 1 '$xyz'\n";
3829
} else {
39-
print $xyz eq 'ABC:BEGIN:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
40-
}
41-
print $ABC eq 'BEGIN:blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
42-
{
43-
no warnings qw(syntax deprecated);
44-
print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
30+
print $xyz eq 'ABC:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
4531
}
32+
print $ABC eq 'blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
33+
print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
4634

4735
package ABC;
4836

t/lib/croak/toke

+30
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,33 @@ syntax error at - line 2, near "[
611611
=="
612612
(Might be a runaway multi-line // string starting on line 1)
613613
Execution of - aborted due to compilation errors.
614+
########
615+
# NAME tick in names: initial character of sub name (reverted)
616+
sub 'Hello'_he_said (_);
617+
EXPECT
618+
OPTIONS nonfatal
619+
########
620+
# NAME tick in names: initial character of sub name (no feature)
621+
no feature 'apostrophe_as_package_separator';
622+
sub 'Hello'_he_said (_);
623+
EXPECT
624+
Illegal declaration of anonymous subroutine at - line 2.
625+
########
626+
# NAME tick in names: initial character of format name (reverted)
627+
format 'one =
628+
ok @<< - format 'foo still works
629+
$test
630+
.
631+
EXPECT
632+
OPTIONS nonfatal
633+
########
634+
# NAME tick in names: initial character of format name (no feature_
635+
no feature 'apostrophe_as_package_separator';
636+
format 'one =
637+
ok @<< - format 'foo still works
638+
$test
639+
.
640+
EXPECT
641+
syntax error at - line 3, near "ok @<< - format '"
642+
(Might be a runaway multi-line '' string starting on line 2)
643+
Execution of - aborted due to compilation errors.

t/lib/feature/apos_as_pack_sep

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Check apostrophe_as_package_separator feature
2+
3+
__END__
4+
# NAME check default and 5.41 bundle
5+
$foo'bar = 1;
6+
use v5.41;
7+
$foo'bar = 2;
8+
EXPECT
9+
OPTIONS fatal
10+
Global symbol "$foo" requires explicit package name (did you forget to declare "my $foo"?) at - line 3.
11+
Can't find string terminator "'" anywhere before EOF at - line 3.
12+
########
13+
# NAME no feature apostrophe_as_package_separator
14+
$foo'bar = 1;
15+
no feature 'apostrophe_as_package_separator';
16+
$foo'bar = 2;
17+
EXPECT
18+
OPTIONS fatal
19+
Can't find string terminator "'" anywhere before EOF at - line 3.
20+
########
21+
# NAME use feature apostrophe_as_package_separator
22+
use v5.41;
23+
use feature 'apostrophe_as_package_separator';
24+
$foo'bar = 2;
25+
$foo'bar = 3; # suppress used only once
26+
EXPECT
27+
########
28+
# NAME ' in symbolic refs always works and is treated as ::
29+
my $x = "foo'bar";
30+
no feature 'apostrophe_as_package_separator';
31+
$$x = "Hello\n";
32+
print $foo::bar;
33+
EXPECT
34+
Hello

t/lib/warnings/toke

+74
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,80 @@ no warnings 'syntax' ;
407407
sort ("")
408408
EXPECT
409409

410+
########
411+
@foo::bar = 1..3;
412+
() = "$foo'bar";
413+
() = "@foo'bar";
414+
() = "$#foo'bar";
415+
use warnings 'syntax';
416+
() = "$foo'bar";
417+
() = "@foo'bar";
418+
() = "$#foo'bar";
419+
no warnings 'syntax', 'deprecated' ;
420+
() = "$foo'bar";
421+
() = "@foo'bar";
422+
() = "$#foo'bar";
423+
# ' in names no longer deprecated, ensure we don't warn
424+
EXPECT
425+
########
426+
use warnings 'syntax'; use utf8;
427+
@fooл::barл = 1..3;
428+
() = "$fooл'barл";
429+
() = "@fooл'barл";
430+
() = "$#fooл'barл";
431+
no warnings 'syntax', 'deprecated' ;
432+
() = "$fooл'barл";
433+
() = "@fooл'barл";
434+
() = "$#fooл'barл";
435+
# ' in names no longer deprecated, ensure we don't warn
436+
EXPECT
437+
########
438+
# NAME deprecation of ' in names reverted
439+
sub foo'bar { 1 }
440+
$a'b = 1;
441+
@a'c = ();
442+
%a'd = ();
443+
package a'e;
444+
# ' in names no longer deprecated, ensure we don't warn
445+
EXPECT
446+
########
447+
# NAME ' no longer is part of the symbol character set (reverted)
448+
# previously these would parse like:
449+
# "${foo'bar}", but they did parse like "${foo}'bar"
450+
# but now they parse in names again
451+
@foo::bar = 1..3;
452+
() = "$foo'bar";
453+
() = "@foo'bar";
454+
() = "$#foo'bar";
455+
use warnings 'syntax';
456+
() = "$foo'bar";
457+
() = "@foo'bar";
458+
() = "$#foo'bar";
459+
no warnings 'syntax', 'deprecated' ;
460+
() = "$foo'bar";
461+
() = "@foo'bar";
462+
() = "$#foo'bar";
463+
EXPECT
464+
########
465+
# similar to the test above in that the parsing has changed
466+
use warnings 'syntax'; use utf8;
467+
@fooл::barл = 1..3;
468+
() = "$fooл'barл";
469+
() = "@fooл'barл";
470+
() = "$#fooл'barл";
471+
no warnings 'syntax', 'deprecated' ;
472+
() = "$fooл'barл";
473+
() = "@fooл'barл";
474+
() = "$#fooл'barл";
475+
EXPECT
476+
########
477+
# NAME deprecation of ' in names (reverted)
478+
sub foo'bar { 1 }
479+
$a'b = 1;
480+
@a'c = ();
481+
%a'd = ();
482+
package a'e;
483+
EXPECT
410484
########
411485
# toke.c
412486
use warnings 'ambiguous' ;

0 commit comments

Comments
 (0)