rust/crates/syntax/test_data/parser/err/0035_use_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

56 lines
1.4 KiB
Plaintext

SOURCE_FILE@0..48
USE@0..13
USE_KW@0..3 "use"
WHITESPACE@3..4 " "
USE_TREE@4..12
PATH@4..12
PATH@4..7
PATH_SEGMENT@4..7
NAME_REF@4..7
IDENT@4..7 "foo"
COLON2@7..9 "::"
PATH_SEGMENT@9..12
NAME_REF@9..12
IDENT@9..12 "bar"
SEMICOLON@12..13 ";"
WHITESPACE@13..14 "\n"
USE@14..17
USE_KW@14..17 "use"
WHITESPACE@17..18 "\n"
USE@18..33
USE_KW@18..21 "use"
WHITESPACE@21..22 " "
USE_TREE@22..32
PATH@22..32
PATH@22..27
PATH_SEGMENT@22..27
NAME_REF@22..27
CRATE_KW@22..27 "crate"
COLON2@27..29 "::"
PATH_SEGMENT@29..32
NAME_REF@29..32
IDENT@29..32 "baz"
SEMICOLON@32..33 ";"
WHITESPACE@33..34 "\n"
USE@34..37
USE_KW@34..37 "use"
WHITESPACE@37..38 "\n"
FN@38..47
FN_KW@38..40 "fn"
WHITESPACE@40..41 " "
NAME@41..42
IDENT@41..42 "f"
PARAM_LIST@42..44
L_PAREN@42..43 "("
R_PAREN@43..44 ")"
WHITESPACE@44..45 " "
BLOCK_EXPR@45..47
STMT_LIST@45..47
L_CURLY@45..46 "{"
R_CURLY@46..47 "}"
WHITESPACE@47..48 "\n"
error 17..17: expected one of `*`, `::`, `{`, `self`, `super` or an identifier
error 17..17: expected SEMICOLON
error 37..37: expected one of `*`, `::`, `{`, `self`, `super` or an identifier
error 37..37: expected SEMICOLON