From bd192f2c67e387ab496738a8a1fcd8efc4c924d4 Mon Sep 17 00:00:00 2001 From: Fionn Langhans Date: Sat, 11 Nov 2023 20:11:12 +0100 Subject: [PATCH] Fixed too eager tuple parsing in match expression --- src/parser.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 7fd39b2..5c7834a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -522,28 +522,37 @@ impl> Parser { } self.skip_newlines(); - + self.tuple.push(false); if self.peek() == Some(SyntaxKind::OpMatchCase) { - self.next(); + self.next(); // eat '=>' self.skip_newlines(); self.parse_expr(false); - self.skip_newlines(); } else { self.errors.push("Expected '=>' case operator".to_string()); } + self.tuple.pop(); - if self.peek() == Some(SyntaxKind::OpComma) { - self.next(); - self.skip_newlines(); - } else { - break; + self.skip_newlines(); + match self.peek() { + Some(SyntaxKind::OpComma) => { + self.next(); + self.skip_newlines(); + } + _ => { + break; + } } } - if self.peek() == Some(SyntaxKind::Semicolon) { - self.next(); - } else { - self.errors.push("Expected semicolon ';'".to_string()); + match self.peek() { + Some(SyntaxKind::Semicolon) => { + self.next(); + } + Some(SyntaxKind::ParenRight) => {} + peeked => { + self.errors + .push(format!("Expected semicolon ';' or ')' not {:?}", peeked)); + } } self.builder.finish_node();