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

124 lines
3.9 KiB
Plaintext

SOURCE_FILE@0..90
FN@0..40
FN_KW@0..2 "fn"
WHITESPACE@2..3 " "
NAME@3..4
IDENT@3..4 "f"
PARAM_LIST@4..6
L_PAREN@4..5 "("
R_PAREN@5..6 ")"
WHITESPACE@6..7 " "
BLOCK_EXPR@7..40
STMT_LIST@7..40
L_CURLY@7..8 "{"
WHITESPACE@8..13 "\n "
EXPR_STMT@13..31
PATH_EXPR@13..31
PATH@13..31
PATH_SEGMENT@13..31
NAME_REF@13..14
IDENT@13..14 "S"
GENERIC_ARG_LIST@14..31
COLON2@14..16 "::"
L_ANGLE@16..17 "<"
TYPE_ARG@17..31
PATH_TYPE@17..31
PATH@17..31
PATH@17..28
PATH_SEGMENT@17..28
NAME_REF@17..21
IDENT@17..21 "Item"
GENERIC_ARG_LIST@21..28
COLON2@21..23 "::"
L_ANGLE@23..24 "<"
TYPE_ARG@24..27
PATH_TYPE@24..27
PATH@24..27
PATH_SEGMENT@24..27
NAME_REF@24..27
IDENT@24..27 "lol"
R_ANGLE@27..28 ">"
COLON2@28..30 "::"
ERROR@30..31
L_ANGLE@30..31 "<"
BIN_EXPR@31..38
PATH_EXPR@31..35
PATH@31..35
PATH_SEGMENT@31..35
NAME_REF@31..35
IDENT@31..35 "nope"
SHR@35..37 ">>"
ERROR@37..38
SEMICOLON@37..38 ";"
WHITESPACE@38..39 "\n"
R_CURLY@39..40 "}"
WHITESPACE@40..42 "\n\n"
FN@42..89
FN_KW@42..44 "fn"
WHITESPACE@44..45 " "
NAME@45..46
IDENT@45..46 "g"
PARAM_LIST@46..48
L_PAREN@46..47 "("
R_PAREN@47..48 ")"
WHITESPACE@48..49 " "
BLOCK_EXPR@49..89
STMT_LIST@49..89
L_CURLY@49..50 "{"
WHITESPACE@50..55 "\n "
LET_STMT@55..76
LET_KW@55..58 "let"
WHITESPACE@58..59 " "
WILDCARD_PAT@59..60
UNDERSCORE@59..60 "_"
COLON@60..61 ":"
WHITESPACE@61..62 " "
PATH_TYPE@62..76
PATH@62..76
PATH@62..73
PATH_SEGMENT@62..73
NAME_REF@62..66
IDENT@62..66 "Item"
GENERIC_ARG_LIST@66..73
COLON2@66..68 "::"
L_ANGLE@68..69 "<"
TYPE_ARG@69..72
PATH_TYPE@69..72
PATH@69..72
PATH_SEGMENT@69..72
NAME_REF@69..72
IDENT@69..72 "lol"
R_ANGLE@72..73 ">"
COLON2@73..75 "::"
ERROR@75..76
L_ANGLE@75..76 "<"
EXPR_STMT@76..83
BIN_EXPR@76..83
PATH_EXPR@76..80
PATH@76..80
PATH_SEGMENT@76..80
NAME_REF@76..80
IDENT@76..80 "nope"
R_ANGLE@80..81 ">"
WHITESPACE@81..82 " "
ERROR@82..83
EQ@82..83 "="
WHITESPACE@83..84 " "
EXPR_STMT@84..87
TUPLE_EXPR@84..86
L_PAREN@84..85 "("
R_PAREN@85..86 ")"
SEMICOLON@86..87 ";"
WHITESPACE@87..88 "\n"
R_CURLY@88..89 "}"
WHITESPACE@89..90 "\n"
error 30..30: expected identifier
error 31..31: expected COMMA
error 31..31: expected R_ANGLE
error 31..31: expected SEMICOLON
error 37..37: expected expression
error 75..75: expected identifier
error 76..76: expected SEMICOLON
error 82..82: expected expression
error 83..83: expected SEMICOLON