What's allowed in a Perl 6 identifier?

后端 未结 1 1848
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 12:00

Synopsis 2 says:

An identifier is composed of an alphabetic character followed by any sequence of alphanumeric characters. The definitions of al

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 12:41

    The grammar has an identifer defined as

    token apostrophe {
        <[ ' \- ]>
    }
    
    token identifier {
        <.ident> [ <.apostrophe> <.ident> ]*
    }
    

    with ident a method on cursors which accepts input that starts with a CCLASS_ALPHABETIC character or an underscore _ and continues with zero or more CCLASS_WORD characters.

    These classes are implemented in MoarVM and map to various Unicode categories.

    Specifically, CCLASS_ALPHABETIC checks for Letter, Lowercase; Letter, Uppercase; Letter, Titlecase; Letter, Modifier and Letter, Other.

    CCLASS_WORD additionally accepts characters of category Number, Decimal Digit as well as undercores.

    As to why postfix operators do not break identifiers, that's due to longest token matching.

    If you want to call a postfix operator Δ on a variable , you have to add a backslash, ie

    multi sub postfix:<Δ>(Int $n) { 137 };
    my $Δ = 6;
    say $Δ\Δ;
    

    or an 'unspace'

    say $Δ\   Δ;
    

    0 讨论(0)
提交回复
热议问题