rust/crates/syntax/test_data/parser/err/0020_fn_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

22 lines
486 B
Plaintext

SOURCE_FILE@0..16
FN@0..2
FN_KW@0..2 "fn"
WHITESPACE@2..4 "\n\n"
FN@4..15
FN_KW@4..6 "fn"
WHITESPACE@6..7 " "
NAME@7..10
IDENT@7..10 "foo"
PARAM_LIST@10..12
L_PAREN@10..11 "("
R_PAREN@11..12 ")"
WHITESPACE@12..13 " "
BLOCK_EXPR@13..15
STMT_LIST@13..15
L_CURLY@13..14 "{"
R_CURLY@14..15 "}"
WHITESPACE@15..16 "\n"
error 2..2: expected a name
error 2..2: expected function arguments
error 2..2: expected a block