Skip to content

Commit

Permalink
Better error message for instance statements
Browse files Browse the repository at this point in the history
  • Loading branch information
purefunctor committed Jan 4, 2025
1 parent 56be163 commit bd21c8e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions crates/parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,22 @@ fn instance_head(p: &mut Parser) {
fn instance_statements(p: &mut Parser) {
let mut m = p.start();
p.expect(SyntaxKind::LAYOUT_START);
while p.at_in(names::LOWER) && !p.at_eof() {
instance_statement(p);
let recover_until_end = |p: &mut Parser, m: &str| {
let mut e = None;
while !p.at(SyntaxKind::LAYOUT_SEPARATOR) && !p.at(SyntaxKind::LAYOUT_END) && !p.at_eof() {
p.error_recover("Invalid token");
if e.is_none() {
e = Some(p.start());
p.error(m);
}
p.consume();
}
if let Some(mut e) = e {
e.end(p, SyntaxKind::ERROR);
}
};
while p.at_in(names::LOWER) && !p.at_eof() {
instance_statement(p);
recover_until_end(p, "Unexpected tokens in instance statement");
if !p.at(SyntaxKind::LAYOUT_END) {
p.expect(SyntaxKind::LAYOUT_SEPARATOR);
}
Expand Down

0 comments on commit bd21c8e

Please sign in to comment.