Drop redundant parameter from ConsumeAndAddCloseSymbol (#6724)

This commit is contained in:
Geoff Romer
2026-02-12 01:56:15 +00:00
committed by GitHub
parent 320096da67
commit 3719d200d6
7 changed files with 16 additions and 21 deletions
+3 -4
View File
@@ -68,10 +68,9 @@ auto Context::ConsumeAndAddOpenParen(Lex::TokenIndex default_token,
}
}
auto Context::ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open,
State state, NodeKind close_kind)
auto Context::ConsumeAndAddCloseSymbol(State state, NodeKind close_kind)
-> void {
Lex::TokenKind open_token_kind = tokens().GetKind(expected_open);
Lex::TokenKind open_token_kind = tokens().GetKind(state.token);
if (!open_token_kind.is_opening_symbol()) {
AddNode(close_kind, state.token, /*has_error=*/true);
@@ -85,7 +84,7 @@ auto Context::ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open,
emitter_.Emit(*position_, ExpectedCloseSymbol,
open_token_kind.closing_symbol());
SkipTo(tokens().GetMatchedClosingToken(expected_open));
SkipTo(tokens().GetMatchedClosingToken(state.token));
AddNode(close_kind, Consume(), /*has_error=*/true);
}
}
+6 -7
View File
@@ -196,13 +196,12 @@ class Context {
NodeKind start_kind)
-> std::optional<Lex::TokenIndex>;
// Parses a closing symbol corresponding to the opening symbol
// `expected_open`, possibly skipping forward and diagnosing if necessary.
// Creates a parse node of the specified close kind. If `expected_open` is not
// an opening symbol, the parse node will be associated with `state.token`,
// no input will be consumed, and no diagnostic will be emitted.
auto ConsumeAndAddCloseSymbol(Lex::TokenIndex expected_open, State state,
NodeKind close_kind) -> void;
// Parses a closing symbol corresponding to the opening symbol `state.token`,
// possibly skipping forward and diagnosing if necessary. Creates a parse node
// of the specified close kind. If `state.token` is not an opening symbol,
// no input will be consumed, and no diagnostic will be emitted, but the parse
// node will still be marked as having an error.
auto ConsumeAndAddCloseSymbol(State state, NodeKind close_kind) -> void;
// Composes `ConsumeIf` and `AddLeafNode`, returning false when ConsumeIf
// fails.
+1 -2
View File
@@ -41,8 +41,7 @@ auto HandleArrayExprComma(Context& context) -> void {
auto HandleArrayExprFinish(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(*(Lex::TokenIterator(state.token)), state,
NodeKind::ArrayExpr);
context.ConsumeAndAddCloseSymbol(state, NodeKind::ArrayExpr);
}
} // namespace Carbon::Parse
+1 -1
View File
@@ -72,7 +72,7 @@ auto HandlePrimitiveFormFinish(Context& context) -> void {
auto HandleFormLiteralFinish(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::FormLiteral);
context.ConsumeAndAddCloseSymbol(state, NodeKind::FormLiteral);
}
} // namespace Carbon::Parse
+1 -1
View File
@@ -20,7 +20,7 @@ auto HandleIndexExpr(Context& context) -> void {
auto HandleIndexExprFinish(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::IndexExpr);
context.ConsumeAndAddCloseSymbol(state, NodeKind::IndexExpr);
}
} // namespace Carbon::Parse
+3 -5
View File
@@ -49,21 +49,19 @@ auto HandleParenConditionAsMatch(Context& context) -> void {
auto HandleParenConditionFinishAsIf(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::IfCondition);
context.ConsumeAndAddCloseSymbol(state, NodeKind::IfCondition);
}
auto HandleParenConditionFinishAsWhile(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(state.token, state,
NodeKind::WhileCondition);
context.ConsumeAndAddCloseSymbol(state, NodeKind::WhileCondition);
}
auto HandleParenConditionFinishAsMatch(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(state.token, state,
NodeKind::MatchCondition);
context.ConsumeAndAddCloseSymbol(state, NodeKind::MatchCondition);
}
} // namespace Carbon::Parse
+1 -1
View File
@@ -156,7 +156,7 @@ auto HandleStatementForHeaderIn(Context& context) -> void {
auto HandleStatementForHeaderFinish(Context& context) -> void {
auto state = context.PopState();
context.ConsumeAndAddCloseSymbol(state.token, state, NodeKind::ForHeader);
context.ConsumeAndAddCloseSymbol(state, NodeKind::ForHeader);
context.PushState(StateKind::CodeBlock);
}