mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-14 22:48:30 +00:00
This change only supports `friend` with an identifier operand, because there are a lot of open questions about the desired syntax beyond that.
35 lines
1.3 KiB
C++
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
|