If a parse error occurs, reports an error, but then finds the next statement and returns that one instead. If a parse error occurs but there is no following statement, returns null.
fn expectStatementRecoverable(p: *Parse) Error!?Node.Index
fn expectStatementRecoverable(p: *Parse) Error!?Node.Index {
while (true) {
return p.expectStatement(true) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
error.ParseError => {
p.findNextStmt(); // Try to skip to the next statement.
switch (p.tokenTag(p.tok_i)) {
.r_brace => return null,
.eof => return error.ParseError,
else => continue,
}
},
};
}
}