Skip to content

Commit

Permalink
Fixed too eager tuple parsing in match expression
Browse files Browse the repository at this point in the history
  • Loading branch information
codefionn committed Nov 11, 2023
1 parent 635f619 commit bd192f2
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,28 +522,37 @@ impl<I: Iterator<Item = (SyntaxKind, String)>> Parser<I> {
}

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();
Expand Down

0 comments on commit bd192f2

Please sign in to comment.