Separate node kind for bindings inside var (#4822)

This is a step toward making binding pattern handling more robust, by
removing its reliance on the node stack for context.
This commit is contained in:
Geoff Romer
2025-01-21 20:15:19 +00:00
committed by GitHub
parent 4f024410f7
commit 943acf1ec2
159 changed files with 356 additions and 367 deletions
+7 -7
View File
@@ -10,10 +10,10 @@ namespace Carbon::Parse {
// Handles PatternListElementAs(Implicit|Tuple).
static auto HandlePatternListElement(Context& context, State pattern_state,
State finish_state) -> void {
context.PopAndDiscardState();
auto state = context.PopState();
context.PushState(finish_state);
context.PushState(pattern_state);
context.PushStateForPattern(finish_state, state.in_var_pattern);
context.PushStateForPattern(pattern_state, state.in_var_pattern);
}
auto HandlePatternListElementAsImplicit(Context& context) -> void {
@@ -39,7 +39,7 @@ static auto HandlePatternListElementFinish(Context& context,
if (context.ConsumeListToken(NodeKind::PatternListComma, close_token,
state.has_error) ==
Context::ListTokenKind::Comma) {
context.PushState(param_state);
context.PushStateForPattern(param_state, state.in_var_pattern);
}
}
@@ -58,13 +58,13 @@ static auto HandlePatternList(Context& context, NodeKind node_kind,
Lex::TokenKind open_token_kind,
Lex::TokenKind close_token_kind,
State param_state, State finish_state) -> void {
context.PopAndDiscardState();
auto state = context.PopState();
context.PushState(finish_state);
context.PushStateForPattern(finish_state, state.in_var_pattern);
context.AddLeafNode(node_kind, context.ConsumeChecked(open_token_kind));
if (!context.PositionIs(close_token_kind)) {
context.PushState(param_state);
context.PushStateForPattern(param_state, state.in_var_pattern);
}
}