mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 06:41:04 +01:00
Unify more invalid declaration recovery. (#3942)
When we expect a semicolon, we should be able to provide more standard
recovery.
Note this affects a test of `base`, but it looks like a partial
improvement (the prior line was moving too far). Still, it looks like
recovery isn't handling `{}` quite right. I'm not trying to address that
here though -- leaving a TODO.
This commit is contained in:
@@ -10,20 +10,9 @@ namespace Carbon::Parse {
|
||||
auto HandleBaseDecl(Context& context) -> void {
|
||||
auto state = context.PopState();
|
||||
|
||||
auto semi = context.ConsumeIf(Lex::TokenKind::Semi);
|
||||
if (!semi && !state.has_error) {
|
||||
context.DiagnoseExpectedDeclSemi(context.tokens().GetKind(state.token));
|
||||
state.has_error = true;
|
||||
}
|
||||
|
||||
if (state.has_error) {
|
||||
context.RecoverFromDeclError(state, NodeKind::BaseDecl,
|
||||
/*skip_past_likely_end=*/true);
|
||||
return;
|
||||
}
|
||||
|
||||
context.AddNode(NodeKind::BaseDecl, *semi, state.subtree_start,
|
||||
state.has_error);
|
||||
context.AddNodeExpectingDeclSemi(state, NodeKind::BaseDecl,
|
||||
Lex::TokenKind::Base,
|
||||
/*is_def_allowed=*/false);
|
||||
}
|
||||
|
||||
} // namespace Carbon::Parse
|
||||
|
||||
Reference in New Issue
Block a user