🔬24. Obsolete syntax error messages in Perl 6, part 3

🔬24. Obsolete syntax error messages in Raku, part 3

N. B. Perl 6 has been renamed to Raku. Click to read more.


A couple of weeks ago, we looked at some error messages that Perl 6 generates when it sees the Perl 5 constructions. Let us continue and go through another portion of the messages that are there in today’s Rakudo.

\x[]

We start with a simple error message that informs you to use new syntax when embedding a character by its code. In Perl 5, you could use \x{23} to get a hash characters, while in Perl 6 it is an error:

$ perl6 -e'say "\x{23}"'
===SORRY!=== Error while compiling -e
Unsupported use of curlies around escape argument;
in Perl 6 please use square brackets
at -e:1
------> say "\x{⏏23}"

Neither it works with regexes, for example:

say "###" ~~ /\x{23}/

Replacing braces with square brackets helps:

$ perl6 -e'say "\x[23]"'
#

Similarly, Perl 6 expects the brackets for octal numbers:

$ perl6 -e'say "\o[123]"'
S

In the Grammar, this situation is caught by the following tokens.

For quoted strings:

role b1 {
    token backslash:sym<x> {
        :dba('hex character') <sym> [ <hexint> | 
        '[' ~ ']' <hexints> | '{' <.obsbrace1> ] }
    . . .
}

For regexes:

token backslash:sym<x> { 
    :i :dba('hex character') <sym> [ <hexint> | 
    '[' ~ ']' <hexints> | '{' <.obsbrace> ] }

. . .

token metachar:sym<{}> { \\<[xo]>'{' <.obsbrace> }

The obsbrace method itself is just a simple error message call:

token obsbrace { <.obs('curlies around escape argument',
                       'square brackets')> }

Old regex modifiers

As soon as we are talking about regexes, here’s another set of error catchers complaining about the Perl 5 syntax of the regex modifiers:

token old_rx_mods {
    (<[ i g s m x c e ]>)
    {
        my $m := $/[0].Str;
        if $m eq 'i' { $/.obs('/i',':i'); }
        elsif $m eq 'g' { $/.obs('/g',':g'); }
        elsif $m eq 'm' { $/.obs('/m','^^ and $$ anchors'); }
        elsif $m eq 's' { $/.obs('/s','. or \N'); }
        elsif $m eq 'x' { $/.obs('/x','normal default whitespace'); }
        elsif $m eq 'c' { $/.obs('/c',':c or :p'); }
        elsif $m eq 'e' { $/.obs('/e','interpolated {...} or s{} = ... form'); }
        else { $/.obs('suffix regex modifiers','prefix adverbs'); }
    }
}

This code is quite self-explanatory, so a simple example would be enough:

$ ./perl6 -e'"abc" ~~ /a/i'
===SORRY!=== Error while compiling -e
Unsupported use of /i; in Perl 6 please use :i
at -e:1
------> "abc" ~~ /a/i⏏<EOL>

One of the following correct forms is expected:

$ ./perl6 -e'say "abc" ~~ m:i/A/'
「a」

$ ./perl6 -e'say "abc" ~~ /[:i A]/'
「a」

As an exercise, write an incorrect Perl 6 code that generates the last error message, Unsupported use of suffix regex modifiers, in Perl 6 please use prefix adverbs.

tr///

Another regex-related construct, y/// does not exist in Perl 6, only the tr/// form is supported now:

token quote:sym<y> {
    <sym>
    <?before \h*\W>
    {} <.qok($/)>
    <.obs('y///','tr///')>
}

Here is an example of the correct program:

my $x = "abc";
$x ~~ tr/b/p/;
say $x; # apc

That’s it for today. We will continue with more obsolete errors in a few days.

One thought on “🔬24. Obsolete syntax error messages in Perl 6, part 3”

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code