Files
carbon-lang/toolchain/parse/handle_friend.cpp
T
Geoff Romer 8f258eaaa6 Parse support for simple friend declarations (#7889)
This change only supports `friend` with an identifier operand, because
there are a lot of open questions about the desired syntax beyond that.
2026-10-05 17:30:29 +00:00

35 lines
1.3 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/parse/context.h"
#include "toolchain/parse/handle.h"
namespace Carbon::Parse {
// Handles processing of a complete `friend X` declaration.
auto HandleFriendDecl(Context& context) -> void {
auto state = context.PopState();
if (state.has_error) {
context.RecoverFromDeclError(state, NodeKind::FriendDecl,
/*skip_past_likely_end=*/true);
return;
}
if (!context.ConsumeAndAddLeafNodeIf(Lex::TokenKind::Identifier,
NodeKind::IdentifierNameExpr)) {
state.has_error = true;
CARBON_DIAGNOSTIC(ExpectedIdentifierForFriend, Error,
"expected identifier for friend declaration");
context.emitter().Emit(*context.position(), ExpectedIdentifierForFriend);
context.RecoverFromDeclError(state, NodeKind::FriendDecl,
/*skip_past_likely_end=*/true);
return;
}
context.AddNodeExpectingDeclSemi(state, NodeKind::FriendDecl,
Lex::TokenKind::Friend,
/*is_def_allowed=*/false);
}
} // namespace Carbon::Parse