From 1d2a47f0b25b34eadcd594c3d9851ce432bbb11b Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Wed, 26 Jan 2000 21:45:41 +0000 Subject: revised attribute syntax: C, C and C are all valid (from Spider Boardman) p4raw-id: //depot/perl@4907 --- lib/AutoSplit.pm | 6 +++--- lib/SelfLoader.pm | 4 ++-- lib/attributes.pm | 15 ++++++++------- pod/perldelta.pod | 8 ++++---- pod/perldiag.pod | 2 +- pod/perlsub.pod | 8 ++++---- t/op/attrs.t | 4 ++-- toke.c | 4 +++- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/AutoSplit.pm b/lib/AutoSplit.pm index 936edc4758..41d5489531 100644 --- a/lib/AutoSplit.pm +++ b/lib/AutoSplit.pm @@ -10,7 +10,7 @@ use strict; our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen, $CheckForAutoloader, $CheckModTime); -$VERSION = "1.0304"; +$VERSION = "1.0305"; @ISA = qw(Exporter); @EXPORT = qw(&autosplit &autosplit_lib_modules); @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime); @@ -149,7 +149,7 @@ my $Is_VMS = ($^O eq 'VMS'); # allow checking for valid ': attrlist' attachments my $nested; $nested = qr{ \( (?: (?> [^()]+ ) | (?p{ $nested }) )* \) }x; -my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) [\s,]* }x; +my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x; my $attr_list = qr{ \s* : \s* (?: $one_attr )* }x; @@ -468,5 +468,5 @@ package Yet::Another::AutoSplit; sub testtesttesttest4_1 ($) { "another test 4\n"; } sub testtesttesttest4_2 ($$) { "another duplicate test 4\n"; } package Yet::More::Attributes; -sub test_a1 ($) : locked { 1; } +sub test_a1 ($) : locked :locked { 1; } sub test_a2 : locked { 1; } diff --git a/lib/SelfLoader.pm b/lib/SelfLoader.pm index 4672ac49da..2aa29303fd 100644 --- a/lib/SelfLoader.pm +++ b/lib/SelfLoader.pm @@ -3,7 +3,7 @@ package SelfLoader; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(AUTOLOAD); -$VERSION = "1.09"; +$VERSION = "1.0901"; sub Version {$VERSION} $DEBUG = 0; @@ -12,7 +12,7 @@ my %Cache; # private cache for all SelfLoader's client packages # allow checking for valid ': attrlist' attachments my $nested; $nested = qr{ \( (?: (?> [^()]+ ) | (?p{ $nested }) )* \) }x; -my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) [\s,]* }x; +my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x; my $attr_list = qr{ \s* : \s* (?: $one_attr )* }x; sub croak { require Carp; goto &Carp::croak } diff --git a/lib/attributes.pm b/lib/attributes.pm index 09f355139f..bbbb8b78ee 100644 --- a/lib/attributes.pm +++ b/lib/attributes.pm @@ -1,6 +1,6 @@ package attributes; -$VERSION = 0.02; +$VERSION = 0.03; @EXPORT_OK = qw(get reftype); @EXPORT = (); @@ -54,7 +54,7 @@ sub import { my $s = ((@pkgattrs == 1) ? '' : 's'); carp "$svtype package attribute$s " . "may clash with future reserved word$s: " . - join(' , ' , @pkgattrs); + join(' : ' , @pkgattrs); } } } @@ -65,7 +65,7 @@ sub import { croak "Invalid $svtype attribute" . (( @badattrs == 1 ) ? '' : 's') . ": " . - join(' , ', @badattrs); + join(' : ', @badattrs); } } @@ -267,7 +267,8 @@ will use that package name. =head2 Syntax of Attribute Lists An attribute list is a sequence of attribute specifications, separated by -whitespace, commas, or both. Each attribute specification is a simple +whitespace or a colon (with optional whitespace). +Each attribute specification is a simple name, optionally followed by a parenthesised parameter list. If such a parameter list is present, it is scanned past as for the rules for the C operator. (See L.) @@ -275,8 +276,8 @@ The parameter list is passed as it was found, however, and not as per C. Some examples of syntactically valid attribute lists: - switch(10,foo(7,3)) , , expensive - Ugly('\(") , Bad + switch(10,foo(7,3)) : expensive + Ugly('\(") :Bad _5x5 locked method @@ -286,7 +287,7 @@ Some examples of syntactically invalid attribute lists (with annotation): Ugly('(') # ()-string not balanced 5x5 # "5x5" not a valid identifier Y2::north # "Y2::north" not a simple identifier - foo + bar # "+" neither a comma nor whitespace + foo + bar # "+" neither a colon nor whitespace =head1 EXPORTS diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 495e2ff2e9..f61ee697c1 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -679,9 +679,9 @@ as requiring an automatic lock() when it is entered, you had to declare that with a C pragma in the body of the subroutine. That can now be accomplished with a declaration syntax, like this: - sub mymethod : locked, method ; + sub mymethod : locked method ; ... - sub mymethod : locked, method { + sub mymethod : locked :method { ... } @@ -1914,14 +1914,14 @@ The offending range is now explicitly displayed. =item Invalid separator character %s in attribute list -(F) Something other than a comma or whitespace was seen between the +(F) Something other than a colon or whitespace was seen between the elements of an attribute list. If the previous attribute had a parenthesised parameter list, perhaps that list was terminated too soon. See L. =item Invalid separator character %s in subroutine attribute list -(F) Something other than a comma or whitespace was seen between the +(F) Something other than a colon or whitespace was seen between the elements of a subroutine attribute list. If the previous attribute had a parenthesised parameter list, perhaps that list was terminated too soon. diff --git a/pod/perldiag.pod b/pod/perldiag.pod index f3d72605af..b7e115fb71 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1745,7 +1745,7 @@ See L. =item Invalid separator character %s in attribute list -(F) Something other than a comma or whitespace was seen between the +(F) Something other than a colon or whitespace was seen between the elements of an attribute list. If the previous attribute had a parenthesised parameter list, perhaps that list was terminated too soon. See L. diff --git a/pod/perlsub.pod b/pod/perlsub.pod index ebb9e55774..927e944c93 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -1230,7 +1230,7 @@ functions to Perl code in L. A subroutine declaration or definition may have a list of attributes associated with it. If such an attribute list is present, it is -broken up at space or comma boundaries and treated as though a +broken up at space or colon boundaries and treated as though a C had been seen. See L for details about what attributes are currently supported. Unlike the limitation with the obsolescent C, the @@ -1244,8 +1244,8 @@ nest properly. Examples of valid syntax (even though the attributes are unknown): - sub fnord (&\%) : switch(10,foo(7,3)) , , expensive ; - sub plugh () : Ugly('\(") , Bad ; + sub fnord (&\%) : switch(10,foo(7,3)) : expensive ; + sub plugh () : Ugly('\(") :Bad ; sub xyzzy : _5x5 { ... } Examples of invalid syntax: @@ -1254,7 +1254,7 @@ Examples of invalid syntax: sub snoid : Ugly('(') ; # ()-string not balanced sub xyzzy : 5x5 ; # "5x5" not a valid identifier sub plugh : Y2::north ; # "Y2::north" not a simple identifier - sub snurt : foo + bar ; # "+" not a comma or space + sub snurt : foo + bar ; # "+" not a colon or space The attribute list is passed as a list of constant strings to the code which associates them with the subroutine. In particular, the second example diff --git a/t/op/attrs.t b/t/op/attrs.t index e89c2cb816..615e4d3343 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -63,12 +63,12 @@ mytest; BEGIN {++$ntests} my $anon1; -eval '$anon1 = sub ($) : locked,,method { $_[0]++ }'; +eval '$anon1 = sub ($) : locked:method { $_[0]++ }'; mytest; BEGIN {++$ntests} my $anon2; -eval '$anon2 = sub : locked , method { $_[0]++ }'; +eval '$anon2 = sub : locked : method { $_[0]++ }'; mytest; BEGIN {++$ntests} diff --git a/toke.c b/toke.c index f2f8fa5e5b..e7e217473e 100644 --- a/toke.c +++ b/toke.c @@ -2797,8 +2797,10 @@ Perl_yylex(pTHX) newSVpvn(s, len))); } s = skipspace(d); - while (*s == ',') + if (*s == ':' && s[1] != ':') s = skipspace(s+1); + else if (s == d) + break; /* require real whitespace or :'s */ } tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) { -- cgit v1.2.1