mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:00:13 +01:00
Drop redundant parameter from ConsumeAndAddCloseSymbol (#6724)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user