rust/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast
Aleksey Kladov 2bf81922f7 internal: more reasonable grammar for blocks
Consider these expples

        { 92 }
  async { 92 }
    'a: { 92 }
   #[a] { 92 }

Previously the tree for them were

  BLOCK_EXPR
    { ... }

  EFFECT_EXPR
    async
    BLOCK_EXPR
      { ... }

  EFFECT_EXPR
    'a:
    BLOCK_EXPR
      { ... }

  BLOCK_EXPR
    #[a]
    { ... }

As you see, it gets progressively worse :) The last two items are
especially odd. The last one even violates the balanced curleys
invariant we have (#10357) The new approach is to say that the stuff in
`{}` is stmt_list, and the block is stmt_list + optional modifiers

  BLOCK_EXPR
    STMT_LIST
      { ... }

  BLOCK_EXPR
    async
    STMT_LIST
      { ... }

  BLOCK_EXPR
    'a:
    STMT_LIST
      { ... }

  BLOCK_EXPR
    #[a]
    STMT_LIST
      { ... }
2021-09-26 19:16:09 +03:00

62 lines
1.4 KiB
Plaintext

SOURCE_FILE@0..60
FN@0..34
ATTR@0..12
POUND@0..1 "#"
L_BRACK@1..2 "["
META@2..11
PATH@2..5
PATH_SEGMENT@2..5
NAME_REF@2..5
IDENT@2..5 "cfg"
TOKEN_TREE@5..11
L_PAREN@5..6 "("
IDENT@6..10 "test"
R_PAREN@10..11 ")"
R_BRACK@11..12 "]"
WHITESPACE@12..13 "\n"
ATTR@13..22
POUND@13..14 "#"
L_BRACK@14..15 "["
META@15..21
PATH@15..21
PATH_SEGMENT@15..21
NAME_REF@15..21
IDENT@15..21 "Ignore"
R_BRACK@21..22 "]"
WHITESPACE@22..23 "\n"
FN_KW@23..25 "fn"
WHITESPACE@25..26 " "
NAME@26..29
IDENT@26..29 "foo"
PARAM_LIST@29..31
L_PAREN@29..30 "("
R_PAREN@30..31 ")"
WHITESPACE@31..32 " "
BLOCK_EXPR@32..34
STMT_LIST@32..34
L_CURLY@32..33 "{"
R_CURLY@33..34 "}"
WHITESPACE@34..36 "\n\n"
MODULE@36..59
ATTR@36..52
POUND@36..37 "#"
L_BRACK@37..38 "["
META@38..51
PATH@38..42
PATH_SEGMENT@38..42
NAME_REF@38..42
IDENT@38..42 "path"
WHITESPACE@42..43 " "
EQ@43..44 "="
WHITESPACE@44..45 " "
LITERAL@45..51
STRING@45..51 "\"a.rs\""
R_BRACK@51..52 "]"
WHITESPACE@52..53 "\n"
MOD_KW@53..56 "mod"
WHITESPACE@56..57 " "
NAME@57..58
IDENT@57..58 "b"
SEMICOLON@58..59 ";"
WHITESPACE@59..60 "\n"