mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 22:08:11 +00:00
Make the `WhereAssignmentOp` node a sibling of its LHS and RHS nodes, so that we have an opportunity in check/ to perform actions between the LHS and RHS. Previously it was a parent of the LHS and RHS, so the two sides would be checked one immediately after the other without any where-assignment-specific checking in between.
60 lines
2.2 KiB
C++
60 lines
2.2 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/lex/token_kind.h"
|
|
#include "toolchain/parse/context.h"
|
|
#include "toolchain/parse/handle.h"
|
|
#include "toolchain/parse/node_kind.h"
|
|
#include "toolchain/parse/precedence.h"
|
|
#include "toolchain/parse/state.h"
|
|
#include "toolchain/parse/typed_nodes.h"
|
|
|
|
namespace Carbon::Parse {
|
|
|
|
auto HandleWhereAssignment(Context& context) -> void {
|
|
auto state = context.PopState();
|
|
|
|
if (!context.ConsumeAndAddLeafNodeIf(
|
|
Lex::TokenKind::Identifier,
|
|
NodeKind::IdentifierNameNotBeforeSignature)) {
|
|
if (!state.has_error) {
|
|
CARBON_DIAGNOSTIC(
|
|
WhereAssignmentMissingIdentifier, Error,
|
|
"expected identifier in `where` assignment declaration");
|
|
context.emitter().Emit(context.PointAfterPreviousToken(),
|
|
WhereAssignmentMissingIdentifier);
|
|
}
|
|
context.RecoverFromDeclError(state, NodeKind::WhereAssignmentDecl,
|
|
/*skip_past_likely_end=*/true);
|
|
return;
|
|
}
|
|
|
|
auto eq_token = context.ConsumeIf(Lex::TokenKind::Equal);
|
|
if (!eq_token) {
|
|
if (!state.has_error) {
|
|
CARBON_DIAGNOSTIC(WhereAssignmentMissingEquals, Error,
|
|
"missing `=` in `where` assignment");
|
|
context.emitter().Emit(context.PointAfterPreviousToken(),
|
|
WhereAssignmentMissingEquals);
|
|
}
|
|
context.RecoverFromDeclError(state, NodeKind::WhereAssignmentDecl,
|
|
/*skip_past_likely_end=*/true);
|
|
return;
|
|
}
|
|
|
|
context.AddNode(NodeKind::WhereAssignmentOperator, *eq_token,
|
|
state.has_error);
|
|
|
|
context.PushState(StateKind::WhereAssignmentDecl);
|
|
context.PushStateForExpr(PrecedenceGroup::ForRequirements());
|
|
}
|
|
|
|
auto HandleWhereAssignmentDecl(Context& context) -> void {
|
|
auto state = context.PopState();
|
|
context.AddNodeExpectingDeclSemi(state, NodeKind::WhereAssignmentDecl,
|
|
Lex::TokenKind::Where,
|
|
/*is_def_allowed=*/false);
|
|
}
|
|
} // namespace Carbon::Parse
|