rust/crates/syntax/test_data/parser/ok/0043_complex_assignment.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

111 lines
3.6 KiB
Plaintext

SOURCE_FILE@0..160
COMMENT@0..60 "// https://github.com ..."
WHITESPACE@60..62 "\n\n"
STRUCT@62..90
STRUCT_KW@62..68 "struct"
WHITESPACE@68..69 " "
NAME@69..73
IDENT@69..73 "Repr"
WHITESPACE@73..74 " "
RECORD_FIELD_LIST@74..90
L_CURLY@74..75 "{"
WHITESPACE@75..76 " "
RECORD_FIELD@76..88
NAME@76..79
IDENT@76..79 "raw"
COLON@79..80 ":"
WHITESPACE@80..81 " "
ARRAY_TYPE@81..88
L_BRACK@81..82 "["
PATH_TYPE@82..84
PATH@82..84
PATH_SEGMENT@82..84
NAME_REF@82..84
IDENT@82..84 "u8"
SEMICOLON@84..85 ";"
WHITESPACE@85..86 " "
LITERAL@86..87
INT_NUMBER@86..87 "1"
R_BRACK@87..88 "]"
WHITESPACE@88..89 " "
R_CURLY@89..90 "}"
WHITESPACE@90..92 "\n\n"
FN@92..159
FN_KW@92..94 "fn"
WHITESPACE@94..95 " "
NAME@95..98
IDENT@95..98 "abc"
PARAM_LIST@98..100
L_PAREN@98..99 "("
R_PAREN@99..100 ")"
WHITESPACE@100..101 " "
BLOCK_EXPR@101..159
STMT_LIST@101..159
L_CURLY@101..102 "{"
WHITESPACE@102..107 "\n "
EXPR_STMT@107..136
BIN_EXPR@107..135
INDEX_EXPR@107..131
FIELD_EXPR@107..128
RECORD_EXPR@107..124
PATH@107..111
PATH_SEGMENT@107..111
NAME_REF@107..111
IDENT@107..111 "Repr"
WHITESPACE@111..112 " "
RECORD_EXPR_FIELD_LIST@112..124
L_CURLY@112..113 "{"
WHITESPACE@113..114 " "
RECORD_EXPR_FIELD@114..122
NAME_REF@114..117
IDENT@114..117 "raw"
COLON@117..118 ":"
WHITESPACE@118..119 " "
ARRAY_EXPR@119..122
L_BRACK@119..120 "["
LITERAL@120..121
INT_NUMBER@120..121 "0"
R_BRACK@121..122 "]"
WHITESPACE@122..123 " "
R_CURLY@123..124 "}"
DOT@124..125 "."
NAME_REF@125..128
IDENT@125..128 "raw"
L_BRACK@128..129 "["
LITERAL@129..130
INT_NUMBER@129..130 "0"
R_BRACK@130..131 "]"
WHITESPACE@131..132 " "
EQ@132..133 "="
WHITESPACE@133..134 " "
LITERAL@134..135
INT_NUMBER@134..135 "0"
SEMICOLON@135..136 ";"
WHITESPACE@136..141 "\n "
EXPR_STMT@141..157
CALL_EXPR@141..156
RECORD_EXPR@141..154
PATH@141..145
PATH_SEGMENT@141..145
NAME_REF@141..145
IDENT@141..145 "Repr"
RECORD_EXPR_FIELD_LIST@145..154
L_CURLY@145..146 "{"
RECORD_EXPR_FIELD@146..153
NAME_REF@146..149
IDENT@146..149 "raw"
COLON@149..150 ":"
ARRAY_EXPR@150..153
L_BRACK@150..151 "["
LITERAL@151..152
INT_NUMBER@151..152 "0"
R_BRACK@152..153 "]"
R_CURLY@153..154 "}"
ARG_LIST@154..156
L_PAREN@154..155 "("
R_PAREN@155..156 ")"
SEMICOLON@156..157 ";"
WHITESPACE@157..158 "\n"
R_CURLY@158..159 "}"
WHITESPACE@159..160 "\n"