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

134 lines
4.6 KiB
Plaintext

SOURCE_FILE@0..183
IMPL@0..182
IMPL_KW@0..4 "impl"
WHITESPACE@4..5 " "
PATH_TYPE@5..13
PATH@5..13
PATH_SEGMENT@5..13
NAME_REF@5..13
IDENT@5..13 "FnScopes"
WHITESPACE@13..14 " "
ASSOC_ITEM_LIST@14..182
L_CURLY@14..15 "{"
WHITESPACE@15..20 "\n "
FN@20..161
FN_KW@20..22 "fn"
WHITESPACE@22..23 " "
NAME@23..32
IDENT@23..32 "new_scope"
PARAM_LIST@32..35
L_PAREN@32..33 "("
PARAM@33..34
REF_PAT@33..34
AMP@33..34 "&"
R_PAREN@34..35 ")"
WHITESPACE@35..36 " "
RET_TYPE@36..46
THIN_ARROW@36..38 "->"
WHITESPACE@38..39 " "
PATH_TYPE@39..46
PATH@39..46
PATH_SEGMENT@39..46
NAME_REF@39..46
IDENT@39..46 "ScopeId"
WHITESPACE@46..47 " "
BLOCK_EXPR@47..161
STMT_LIST@47..161
L_CURLY@47..48 "{"
WHITESPACE@48..57 "\n "
LET_STMT@57..85
LET_KW@57..60 "let"
WHITESPACE@60..61 " "
IDENT_PAT@61..64
NAME@61..64
IDENT@61..64 "res"
WHITESPACE@64..65 " "
EQ@65..66 "="
WHITESPACE@66..67 " "
METHOD_CALL_EXPR@67..84
FIELD_EXPR@67..78
PATH_EXPR@67..71
PATH@67..71
PATH_SEGMENT@67..71
NAME_REF@67..71
SELF_KW@67..71 "self"
DOT@71..72 "."
NAME_REF@72..78
IDENT@72..78 "scopes"
DOT@78..79 "."
NAME_REF@79..82
IDENT@79..82 "len"
ARG_LIST@82..84
L_PAREN@82..83 "("
R_PAREN@83..84 ")"
SEMICOLON@84..85 ";"
WHITESPACE@85..94 "\n "
METHOD_CALL_EXPR@94..155
FIELD_EXPR@94..105
PATH_EXPR@94..98
PATH@94..98
PATH_SEGMENT@94..98
NAME_REF@94..98
SELF_KW@94..98 "self"
DOT@98..99 "."
NAME_REF@99..105
IDENT@99..105 "scopes"
DOT@105..106 "."
NAME_REF@106..110
IDENT@106..110 "push"
ARG_LIST@110..155
L_PAREN@110..111 "("
RECORD_EXPR@111..154
PATH@111..120
PATH_SEGMENT@111..120
NAME_REF@111..120
IDENT@111..120 "ScopeData"
WHITESPACE@120..121 " "
RECORD_EXPR_FIELD_LIST@121..154
L_CURLY@121..122 "{"
WHITESPACE@122..123 " "
RECORD_EXPR_FIELD@123..135
NAME_REF@123..129
IDENT@123..129 "parent"
COLON@129..130 ":"
WHITESPACE@130..131 " "
PATH_EXPR@131..135
PATH@131..135
PATH_SEGMENT@131..135
NAME_REF@131..135
IDENT@131..135 "None"
COMMA@135..136 ","
WHITESPACE@136..137 " "
RECORD_EXPR_FIELD@137..152
NAME_REF@137..144
IDENT@137..144 "entries"
COLON@144..145 ":"
WHITESPACE@145..146 " "
MACRO_CALL@146..152
PATH@146..149
PATH_SEGMENT@146..149
NAME_REF@146..149
IDENT@146..149 "vec"
BANG@149..150 "!"
TOKEN_TREE@150..152
L_BRACK@150..151 "["
R_BRACK@151..152 "]"
WHITESPACE@152..153 " "
R_CURLY@153..154 "}"
R_PAREN@154..155 ")"
WHITESPACE@155..160 "\n "
R_CURLY@160..161 "}"
WHITESPACE@161..167 "\n\n "
FN@167..180
FN_KW@167..169 "fn"
WHITESPACE@169..170 " "
NAME@170..180
IDENT@170..180 "set_parent"
WHITESPACE@180..181 "\n"
R_CURLY@181..182 "}"
WHITESPACE@182..183 "\n"
error 34..34: expected pattern
error 34..34: missing type for function parameter
error 180..180: expected function arguments
error 180..180: expected a block