rust/crates/syntax/test_data/parser/inline/ok/0113_nocontentexpr.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

58 lines
1.6 KiB
Plaintext

SOURCE_FILE@0..50
FN@0..49
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 ")"
BLOCK_EXPR@8..49
STMT_LIST@8..49
L_CURLY@8..9 "{"
WHITESPACE@9..14 "\n "
SEMICOLON@14..15 ";"
SEMICOLON@15..16 ";"
SEMICOLON@16..17 ";"
EXPR_STMT@17..29
CALL_EXPR@17..28
PATH_EXPR@17..26
PATH@17..26
PATH_SEGMENT@17..26
NAME_REF@17..26
IDENT@17..26 "some_expr"
ARG_LIST@26..28
L_PAREN@26..27 "("
R_PAREN@27..28 ")"
SEMICOLON@28..29 ";"
SEMICOLON@29..30 ";"
SEMICOLON@30..31 ";"
SEMICOLON@31..32 ";"
EXPR_STMT@32..38
BLOCK_EXPR@32..37
STMT_LIST@32..37
L_CURLY@32..33 "{"
SEMICOLON@33..34 ";"
SEMICOLON@34..35 ";"
SEMICOLON@35..36 ";"
R_CURLY@36..37 "}"
SEMICOLON@37..38 ";"
SEMICOLON@38..39 ";"
SEMICOLON@39..40 ";"
SEMICOLON@40..41 ";"
CALL_EXPR@41..47
PATH_EXPR@41..43
PATH@41..43
PATH_SEGMENT@41..43
NAME_REF@41..43
IDENT@41..43 "Ok"
ARG_LIST@43..47
L_PAREN@43..44 "("
TUPLE_EXPR@44..46
L_PAREN@44..45 "("
R_PAREN@45..46 ")"
R_PAREN@46..47 ")"
WHITESPACE@47..48 "\n"
R_CURLY@48..49 "}"
WHITESPACE@49..50 "\n"