@@ -2121,7 +2121,7 @@ impl Parser {
21212121 let _ = lexer. next ( ) ;
21222122 this. pop_rule_span ( lexer) ;
21232123 }
2124- ( Token :: Paren ( '{' ) | Token :: Attribute , _) => {
2124+ ( token , _) if is_start_of_compound_statement ( token ) => {
21252125 let ( inner, span) = this. block ( lexer, ctx, brace_nesting_level) ?;
21262126 block. stmts . push ( ast:: Statement {
21272127 kind : ast:: StatementKind :: Block ( inner) ,
@@ -2287,11 +2287,14 @@ impl Parser {
22872287 let value = loop {
22882288 let value = this. switch_value ( lexer, ctx) ?;
22892289 if lexer. skip ( Token :: Separator ( ',' ) ) {
2290- if lexer. skip ( Token :: Separator ( ':' ) ) {
2290+ // list of values ends with ':' or a compound statement
2291+ let next_token = lexer. peek ( ) . 0 ;
2292+ if next_token == Token :: Separator ( ':' )
2293+ || is_start_of_compound_statement ( next_token)
2294+ {
22912295 break value;
22922296 }
22932297 } else {
2294- lexer. skip ( Token :: Separator ( ':' ) ) ;
22952298 break value;
22962299 }
22972300 cases. push ( ast:: SwitchCase {
@@ -2301,6 +2304,8 @@ impl Parser {
23012304 } ) ;
23022305 } ;
23032306
2307+ lexer. skip ( Token :: Separator ( ':' ) ) ;
2308+
23042309 let body = this. block ( lexer, ctx, brace_nesting_level) ?. 0 ;
23052310
23062311 cases. push ( ast:: SwitchCase {
@@ -3244,3 +3249,7 @@ impl Parser {
32443249 } )
32453250 }
32463251}
3252+
3253+ const fn is_start_of_compound_statement < ' a > ( token : Token < ' a > ) -> bool {
3254+ matches ! ( token, Token :: Attribute | Token :: Paren ( '{' ) )
3255+ }
0 commit comments