perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Apostrophe in name removal

Open tonycoz opened this issue 1 year ago • 1 comments

Do the removal described in perldeprecation

=head3 Use of C<'> as a global name separator

Perl allows use of C<'> instead of C<::> to replace the parts of a package or global variable name, for example C<A::B> and C<A'B> are equivalent.

C<'> will no longer be recognized as a name separator in Perl 5.42.

tonycoz avatar Jun 19 '24 23:06 tonycoz

I scanned the changes and ran the tests on FreeBSD; got PASS. LGTM but the C-level changes would benefit from other eyeballs.

jkeenan avatar Jun 22 '24 12:06 jkeenan

  • op.c - Perl_newATTRSUB_x Looks like it still treats ' specially:
                   || memchr(name, ':', namlen) || memchr(name, '\'', namlen)
    
  • op.c - Perl_ck_method This code should go:
        /* replace ' with :: */
        while ((compatptr = (char *) memchr(SvPVX(sv), '\'',
                                            SvEND(sv) - SvPVX(sv) )))
        {
            *compatptr = ':';
            sv_insert(sv, compatptr - SvPVX_const(sv), 0, ":", 1);
        }
    
  • mg.c - Perl_magic_setsig Another suspicious use of ':
                if (!memchr(s, ':', len) && !memchr(s, '\'', len))
    

mauke avatar Jul 27 '24 05:07 mauke

Thanks.

  • op.c - Perl_newATTRSUB_x Looks like it still treats ' specially: c || memchr(name, ':', namlen) || memchr(name, '\'', namlen)

    • op.c - Perl_ck_method This code should go:
          /* replace ' with :: */
          while ((compatptr = (char *) memchr(SvPVX(sv), '\'',
                                              SvEND(sv) - SvPVX(sv) )))
          {
              *compatptr = ':';
              sv_insert(sv, compatptr - SvPVX_const(sv), 0, ":", 1);
          }
      

I couldn't see a way to test these, but removed the left over code.

* `mg.c` - `Perl_magic_setsig`
  Another suspicious use of `'`:
  ```c
              if (!memchr(s, ':', len) && !memchr(s, '\'', len))
  ```

This one had observable behaviour which I added a test for.

tonycoz avatar Jul 29 '24 04:07 tonycoz

I assume this PR calls for an update to perldata, under the heading Identifier parsing :

While you can mix double colons with singles quotes, the quotes must come after the colons: $::::'foo and $foo::'bar are legal, but $::'::foo and $foo'::bar are not.

There's also a big old regex in that section with rules for parsing identifiers.

guest20 avatar Jul 29 '24 17:07 guest20

pod/perlmod.pod has this:

The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. It also makes C++ programmers feel like they know what's going on--as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house", you'll be accessing $owner::s; that is, the $s variable in package owner, which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house".

Using ' as a package separator is deprecated and will be removed in Perl 5.40.

mauke avatar Jul 29 '24 17:07 mauke

@tonycoz, could you respond to the 2 preceding comments in this ticket? Thanks.

jkeenan avatar Aug 06 '24 14:08 jkeenan

I've added updates to perldata and perlmod, I expect they will be squashed into the top commit on merge.

tonycoz avatar Aug 07 '24 01:08 tonycoz

applied manually, thanks everyone

tonycoz avatar Aug 12 '24 05:08 tonycoz