[parse] Implement initial parsing support for Lambda expressions (#6583)

This adds the necessary parser infrastructure to recognize and parse
lambda expressions in Carbon.

Key changes:
- Added  and  Parse Node Kinds.
- Updated  to use  to accommodate the growing number of node kinds.
- Implemented parser states and handlers for lambda syntax ( or ).
- Added  structure to .
- Added diagnostics for missing lambda bodies.
- Added a stub in  phase to defer semantic analysis using .
- Added parser tests for lambdas.
This commit is contained in:
Burak Emir
2026-01-14 16:58:15 +00:00
committed by GitHub
parent 83651bb9ee
commit 80639a02f0
19 changed files with 496 additions and 15 deletions
+19
View File
@@ -51,6 +51,13 @@ auto HandleFunctionSignatureFinish(Context& context) -> void {
context.PushState(StateKind::StatementScopeLoop);
break;
}
case Lex::TokenKind::EqualGreater: {
context.AddFunctionDefinitionStart(context.Consume(), state.has_error);
context.AddLeafNode(NodeKind::TerseBodyArrow, *(context.position() - 1));
context.PushState(state, StateKind::FunctionTerseBodyFinish);
context.PushStateForExpr(PrecedenceGroup::ForTopLevelExpr());
break;
}
case Lex::TokenKind::Equal: {
context.AddNode(NodeKind::BuiltinFunctionDefinitionStart,
context.Consume(), state.has_error);
@@ -95,4 +102,16 @@ auto HandleFunctionDefinitionFinish(Context& context) -> void {
context.AddFunctionDefinition(context.Consume(), state.has_error);
}
auto HandleFunctionTerseBodyFinish(Context& context) -> void {
auto state = context.PopState();
auto semi = context.ConsumeIf(Lex::TokenKind::Semi);
if (!semi && !state.has_error) {
context.DiagnoseExpectedDeclSemi(Lex::TokenKind::Fn);
state.has_error = true;
}
context.AddFunctionTerseDefinition(semi ? *semi : *(context.position() - 1),
state.has_error);
}
} // namespace Carbon::Parse