rust/crates/syntax/test_data/parser/err/0005_attribute_recover.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

63 lines
1.5 KiB
Plaintext

SOURCE_FILE@0..54
FN@0..31
ATTR@0..18
POUND@0..1 "#"
L_BRACK@1..2 "["
META@2..17
PATH@2..5
PATH_SEGMENT@2..5
NAME_REF@2..5
IDENT@2..5 "foo"
TOKEN_TREE@5..17
L_PAREN@5..6 "("
IDENT@6..9 "foo"
COMMA@9..10 ","
WHITESPACE@10..11 " "
PLUS@11..12 "+"
COMMA@12..13 ","
WHITESPACE@13..14 " "
INT_NUMBER@14..16 "92"
R_PAREN@16..17 ")"
R_BRACK@17..18 "]"
WHITESPACE@18..19 "\n"
FN_KW@19..21 "fn"
WHITESPACE@21..22 " "
NAME@22..25
IDENT@22..25 "foo"
PARAM_LIST@25..27
L_PAREN@25..26 "("
R_PAREN@26..27 ")"
WHITESPACE@27..28 " "
BLOCK_EXPR@28..31
STMT_LIST@28..31
L_CURLY@28..29 "{"
WHITESPACE@29..30 "\n"
R_CURLY@30..31 "}"
WHITESPACE@31..34 "\n\n\n"
ATTR@34..53
POUND@34..35 "#"
L_BRACK@35..36 "["
META@36..53
PATH@36..39
PATH_SEGMENT@36..39
NAME_REF@36..39
IDENT@36..39 "foo"
TOKEN_TREE@39..53
L_PAREN@39..40 "("
WHITESPACE@40..41 "\n"
FN_KW@41..43 "fn"
WHITESPACE@43..44 " "
IDENT@44..47 "foo"
TOKEN_TREE@47..49
L_PAREN@47..48 "("
R_PAREN@48..49 ")"
WHITESPACE@49..50 " "
TOKEN_TREE@50..53
L_CURLY@50..51 "{"
WHITESPACE@51..52 "\n"
R_CURLY@52..53 "}"
WHITESPACE@53..54 "\n"
error 53..53: expected R_PAREN
error 53..53: expected `]`
error 53..53: expected an item