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

172 lines
4.7 KiB
Plaintext

SOURCE_FILE@0..112
FN@0..33
FN_KW@0..2 "fn"
WHITESPACE@2..3 " "
NAME@3..4
IDENT@3..4 "a"
PARAM_LIST@4..6
L_PAREN@4..5 "("
R_PAREN@5..6 ")"
WHITESPACE@6..7 " "
BLOCK_EXPR@7..33
STMT_LIST@7..33
L_CURLY@7..8 "{"
WHITESPACE@8..9 " "
EXPR_STMT@9..17
ARRAY_EXPR@9..17
L_BRACK@9..10 "["
LITERAL@10..11
INT_NUMBER@10..11 "1"
COMMA@11..12 ","
WHITESPACE@12..13 " "
LITERAL@13..14
INT_NUMBER@13..14 "2"
COMMA@14..15 ","
WHITESPACE@15..16 " "
ERROR@16..17
AT@16..17 "@"
ERROR@17..18
COMMA@17..18 ","
WHITESPACE@18..19 " "
STRUCT@19..26
STRUCT_KW@19..25 "struct"
ERROR@25..26
COMMA@25..26 ","
WHITESPACE@26..27 " "
LET_STMT@27..31
LET_KW@27..30 "let"
ERROR@30..31
R_BRACK@30..31 "]"
WHITESPACE@31..32 " "
R_CURLY@32..33 "}"
WHITESPACE@33..34 "\n"
FN@34..68
FN_KW@34..36 "fn"
WHITESPACE@36..37 " "
NAME@37..38
IDENT@37..38 "b"
PARAM_LIST@38..40
L_PAREN@38..39 "("
R_PAREN@39..40 ")"
WHITESPACE@40..41 " "
BLOCK_EXPR@41..68
STMT_LIST@41..68
L_CURLY@41..42 "{"
WHITESPACE@42..43 " "
EXPR_STMT@43..54
CALL_EXPR@43..54
PATH_EXPR@43..46
PATH@43..46
PATH_SEGMENT@43..46
NAME_REF@43..46
IDENT@43..46 "foo"
ARG_LIST@46..54
L_PAREN@46..47 "("
LITERAL@47..48
INT_NUMBER@47..48 "1"
COMMA@48..49 ","
WHITESPACE@49..50 " "
LITERAL@50..51
INT_NUMBER@50..51 "2"
COMMA@51..52 ","
WHITESPACE@52..53 " "
ERROR@53..54
AT@53..54 "@"
ERROR@54..55
COMMA@54..55 ","
WHITESPACE@55..56 " "
IMPL@56..60
IMPL_KW@56..60 "impl"
ERROR@60..61
COMMA@60..61 ","
WHITESPACE@61..62 " "
LET_STMT@62..65
LET_KW@62..65 "let"
ERROR@65..66
R_PAREN@65..66 ")"
WHITESPACE@66..67 " "
R_CURLY@67..68 "}"
WHITESPACE@68..69 "\n"
FN@69..111
FN_KW@69..71 "fn"
WHITESPACE@71..72 " "
NAME@72..73
IDENT@72..73 "c"
PARAM_LIST@73..75
L_PAREN@73..74 "("
R_PAREN@74..75 ")"
WHITESPACE@75..76 " "
BLOCK_EXPR@76..111
STMT_LIST@76..111
L_CURLY@76..77 "{"
WHITESPACE@77..78 " "
EXPR_STMT@78..93
METHOD_CALL_EXPR@78..93
PATH_EXPR@78..81
PATH@78..81
PATH_SEGMENT@78..81
NAME_REF@78..81
IDENT@78..81 "foo"
DOT@81..82 "."
NAME_REF@82..85
IDENT@82..85 "bar"
ARG_LIST@85..93
L_PAREN@85..86 "("
LITERAL@86..87
INT_NUMBER@86..87 "1"
COMMA@87..88 ","
WHITESPACE@88..89 " "
LITERAL@89..90
INT_NUMBER@89..90 "2"
COMMA@90..91 ","
WHITESPACE@91..92 " "
ERROR@92..93
AT@92..93 "@"
ERROR@93..94
COMMA@93..94 ","
WHITESPACE@94..95 " "
ERROR@95..96
R_BRACK@95..96 "]"
ERROR@96..97
COMMA@96..97 ","
WHITESPACE@97..98 " "
TRAIT@98..104
TRAIT_KW@98..103 "trait"
ERROR@103..104
COMMA@103..104 ","
WHITESPACE@104..105 " "
LET_STMT@105..108
LET_KW@105..108 "let"
ERROR@108..109
R_PAREN@108..109 ")"
WHITESPACE@109..110 " "
R_CURLY@110..111 "}"
WHITESPACE@111..112 "\n"
error 16..16: expected expression
error 17..17: expected R_BRACK
error 17..17: expected SEMICOLON
error 17..17: expected expression
error 25..25: expected a name
error 26..26: expected `;`, `{`, or `(`
error 30..30: expected pattern
error 31..31: expected SEMICOLON
error 53..53: expected expression
error 54..54: expected SEMICOLON
error 54..54: expected expression
error 60..60: expected type
error 60..60: expected `{`
error 60..60: expected expression
error 65..65: expected pattern
error 65..65: expected SEMICOLON
error 65..65: expected expression
error 92..92: expected expression
error 93..93: expected SEMICOLON
error 93..93: expected expression
error 95..95: expected expression
error 96..96: expected expression
error 103..103: expected a name
error 104..104: expected `{`
error 108..108: expected pattern
error 108..108: expected SEMICOLON
error 108..108: expected expression