Implement basic bool and int formatting for diagnostics (#4411)

Note, this supports plurals, but doesn't apply it anywhere. I'm mainly
doing that to demonstrate the approach regarding syntax. See
format_providers.h for details.
This commit is contained in:
Jon Ross-Perkins
2024-10-16 22:46:15 +00:00
committed by GitHub
parent a5ba0eed6a
commit 96964ee534
13 changed files with 416 additions and 145 deletions
+4 -4
View File
@@ -2,6 +2,7 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/diagnostics/format_providers.h"
#include "toolchain/parse/context.h"
#include "toolchain/parse/handle.h"
@@ -36,10 +37,9 @@ static auto HandlePeriodOrArrow(Context& context, NodeKind node_kind,
return;
} else {
CARBON_DIAGNOSTIC(ExpectedIdentifierAfterPeriodOrArrow, Error,
"expected identifier after `{0}`", llvm::StringLiteral);
context.emitter().Emit(
*context.position(), ExpectedIdentifierAfterPeriodOrArrow,
is_arrow ? llvm::StringLiteral("->") : llvm::StringLiteral("."));
"expected identifier after `{0:->|.}`", BoolAsSelect);
context.emitter().Emit(*context.position(),
ExpectedIdentifierAfterPeriodOrArrow, is_arrow);
// If we see a keyword, assume it was intended to be a name.
// TODO: Should keywords be valid here?
if (context.PositionKind().is_keyword()) {