Model var as a pattern operator (#4720)

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Geoff Romer
2025-01-17 17:51:34 +00:00
committed by GitHub
co-authored by Richard Smith
parent 6572da7314
commit 13434f0e8a
510 changed files with 11819 additions and 3352 deletions
+7
View File
@@ -16,6 +16,9 @@ static auto HandleVar(Context& context, State finish_state,
// The finished variable declaration will start at the `var` or `returned`.
context.PushState(state, finish_state);
// TODO: is there a cleaner way to give VarAfterPattern access to the `var`
// token?
state.token = *(context.position() - 1);
context.PushState(state, State::VarAfterPattern);
if (returned_token.is_valid()) {
@@ -66,6 +69,8 @@ auto HandleVarAfterPattern(Context& context) -> void {
}
}
context.AddNode(NodeKind::VariablePattern, state.token, state.has_error);
if (context.PositionIs(Lex::TokenKind::Equal)) {
context.AddLeafNode(NodeKind::VariableInitializer,
context.ConsumeChecked(Lex::TokenKind::Equal));
@@ -91,6 +96,8 @@ auto HandleVarFinishAsDecl(Context& context) -> void {
auto HandleVarFinishAsFor(Context& context) -> void {
auto state = context.PopState();
context.AddNode(NodeKind::VariablePattern, state.token, state.has_error);
auto end_token = state.token;
if (context.PositionIs(Lex::TokenKind::In)) {
end_token = context.Consume();