rust/crates/syntax/test_data/parser/ok/0049_async_block.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

37 lines
990 B
Plaintext

SOURCE_FILE@0..47
FN@0..45
FN_KW@0..2 "fn"
WHITESPACE@2..3 " "
NAME@3..6
IDENT@3..6 "foo"
PARAM_LIST@6..8
L_PAREN@6..7 "("
R_PAREN@7..8 ")"
WHITESPACE@8..9 " "
BLOCK_EXPR@9..45
STMT_LIST@9..45
L_CURLY@9..10 "{"
WHITESPACE@10..15 "\n "
EXPR_STMT@15..24
BLOCK_EXPR@15..23
ASYNC_KW@15..20 "async"
WHITESPACE@20..21 " "
STMT_LIST@21..23
L_CURLY@21..22 "{"
R_CURLY@22..23 "}"
SEMICOLON@23..24 ";"
WHITESPACE@24..29 "\n "
EXPR_STMT@29..43
BLOCK_EXPR@29..42
ASYNC_KW@29..34 "async"
WHITESPACE@34..35 " "
MOVE_KW@35..39 "move"
WHITESPACE@39..40 " "
STMT_LIST@40..42
L_CURLY@40..41 "{"
R_CURLY@41..42 "}"
SEMICOLON@42..43 ";"
WHITESPACE@43..44 "\n"
R_CURLY@44..45 "}"
WHITESPACE@45..47 "\n\n"