TITLE

Synopsis 2: Bits and Pieces

AUTHOR

Larry Wall <larry@wall.org>

VERSION
  Maintainer: Larry Wall <larry@wall.org>
  Date: 10 Aug 2004
  Last Modified: 16 Jun 2006
  Number: 2
  Version: 45

This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain updates to reflect the evolving design of Perl 6 over time, unlike the Apocalypses, which are frozen in time as "historical documents". These updates are not marked--if a Synopsis disagrees with its Apocalypse, assume the Synopsis is correct.)

Lexical Conventions
Whitespace and Comments
Built-In Data Types
Names and VariablesTT
NamesTTT
LiteralsTTTTTTTTTTTTT
Context
Lists
Files
Properties
Grammatical Categories

Lexing in Perl 6 is controlled by a system of grammatical categories. At each point in the parse, the lexer knows which subset of the grammatical categories are possible at that point, and follows the longest-token rule across all the active grammatical categories. (Ordering of grammatical categories matters only in case of a "tie", in which case the grammatical category that is notionally "first" in the grammar wins. For instance, a statement_control is always going to win out over a prefix operator of the same name. More specifically, you can't call a function named "if" directly because it would be hidden either by the statement_control category or the statement_modifier category.)

Here are the current grammatical categories:

    term:<...>                                  $x = {...}
    quote:<qX>                                  qX/foo/
    prefix:<!>                                  !$x (and $x.! if no postfix:<!>)
    infix:<+>                                   $x + $y
    postfix:<++>                                $x++
    circumfix:<[ ]>                             [ @x ]
    postcircumfix:<[ ]>                         $x[$y] or $x .[$y]
    regex_metachar:<,>                          /,/
    regex_backslash:<w>                         /\w/ and /\W/
    regex_assertion:<*>                         /<*stuff>/
    regex_mod_internal:<perl5>                  m:/ ... :perl5 ... /
    regex_mod_external:<nth>                    m:nth(3)/ ... /
    trait_verb:<handles>                        has $.tail handles <wag>
    trait_auxiliary:<shall>                     my $x shall conform<TR123>
    scope_declarator:<has>                      has $.x;
    statement_control:<if>                      if $condition {...} else {...}
    statement_modifier:<if>                     ... if $condition
    infix_postfix_meta_operator:<=>             $x += 2;
    postfix_prefix_meta_operator:{'»'}          @array »++
    prefix_postfix_meta_operator:{'«'}          -« @magnitudes
    infix_circumfix_meta_operator:{'»','«'}     @a »+« @b
    prefix_circumfix_meta_operator:{'[',']'}    [*]

Any category containing "circumfix" requires two token arguments, supplied in slice notation.