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

49 lines
1.2 KiB
Plaintext

SOURCE_FILE@0..50
ERROR@0..6
UNSAFE_KW@0..6 "unsafe"
WHITESPACE@6..7 " "
FN@7..24
ASYNC_KW@7..12 "async"
WHITESPACE@12..13 " "
FN_KW@13..15 "fn"
WHITESPACE@15..16 " "
NAME@16..19
IDENT@16..19 "foo"
PARAM_LIST@19..21
L_PAREN@19..20 "("
R_PAREN@20..21 ")"
WHITESPACE@21..22 " "
BLOCK_EXPR@22..24
STMT_LIST@22..24
L_CURLY@22..23 "{"
R_CURLY@23..24 "}"
WHITESPACE@24..25 "\n"
CONST@25..40
UNSAFE_KW@25..31 "unsafe"
WHITESPACE@31..32 " "
CONST_KW@32..37 "const"
WHITESPACE@37..38 " "
ERROR@38..40
FN_KW@38..40 "fn"
WHITESPACE@40..41 " "
MACRO_CALL@41..46
PATH@41..44
PATH_SEGMENT@41..44
NAME_REF@41..44
IDENT@41..44 "bar"
TOKEN_TREE@44..46
L_PAREN@44..45 "("
R_PAREN@45..46 ")"
WHITESPACE@46..47 " "
ERROR@47..49
L_CURLY@47..48 "{"
R_CURLY@48..49 "}"
WHITESPACE@49..50 "\n"
error 6..6: expected existential, fn, trait or impl
error 38..38: expected a name
error 40..40: missing type for `const` or `static`
error 40..40: expected SEMICOLON
error 44..44: expected BANG
error 46..46: expected SEMICOLON
error 47..47: expected an item