Lex and parse support for ... statements and expand. (#7832)

No support for `each` yet, but this should be enough that we can try out
an implementation approach supporting expanding a statement across
elements of a tuple without building "real" variadics.

Assisted-by: Claude via Antigravity
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-05 22:23:12 +00:00
1 parent ae5d1efd13
commit 2ec4bab59b
12 files changed
+958 -430

No files matched your search

+13
View File
@@ -51,6 +51,12 @@ auto HandleStatement(Context& context) -> void {
context.PushState(StateKind::MatchIntroducer);
break;
}
case Lex::TokenKind::PeriodPeriodPeriod: {
context.PushState(StateKind::StatementPackExpansionFinish);
context.AddLeafNode(NodeKind::PackExpansionStart, context.Consume());
context.PushState(StateKind::Statement);
break;
}
#define CARBON_PARSE_NODE_KIND(Name)
#define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name) case Lex::TokenKind::Name:
#include "toolchain/parse/node_kind.def"
@@ -228,6 +234,13 @@ auto HandleStatementReturnFinish(Context& context) -> void {
HandleStatementKeywordFinish(context, NodeKind::ReturnStatement);
}
auto HandleStatementPackExpansionFinish(Context& context) -> void {
auto state = context.PopState();
context.AddNode(NodeKind::PackExpansionStatement, state.token,
state.has_error);
}
auto HandleStatementScopeLoop(Context& context) -> void {
// This maintains the current state until we're at the end of the scope.