Require extend before base: BaseType; (#3459)

This commit is contained in:
josh11b
2023-12-06 20:14:16 +00:00
committed by GitHub
parent f4677eea8d
commit a970b1e587
18 changed files with 383 additions and 181 deletions
@@ -41,6 +41,7 @@ static auto TokenIsModifierOrIntroducer(Lex::TokenKind token_kind) -> bool {
case Lex::TokenKind::Class:
case Lex::TokenKind::Constraint:
case Lex::TokenKind::Default:
case Lex::TokenKind::Extend:
case Lex::TokenKind::Final:
case Lex::TokenKind::Fn:
case Lex::TokenKind::Impl:
@@ -188,6 +189,21 @@ auto HandleDeclScopeLoop(Context& context) -> void {
break;
}
case Lex::TokenKind::Extend: {
// `extend` is considered a declaration modifier if it is followed by
// another modifier or an introducer.
if (TokenIsModifierOrIntroducer(
context.PositionKind(Lookahead::NextToken))) {
context.AddLeafNode(NodeKind::DeclModifierKeyword, context.Consume());
saw_modifier = true;
} else {
// TODO: Treat this `extend` token as a declaration introducer
HandleUnrecognizedDecl(context, state.subtree_start);
return;
}
break;
}
// If we see a declaration introducer keyword token, replace the
// placeholder node and switch to a state to parse the rest of the
// declaration. We don't allow namespace or empty declarations here since