Add PushState overload to combine Parse::State change with StateStackEntry (#3485)

Shortens a common `PushState` pattern
This commit is contained in:
josh11b
2023-12-08 23:58:30 +00:00
committed by GitHub
parent 6e65a30b5d
commit b7d129b88c
17 changed files with 47 additions and 87 deletions
+4 -8
View File
@@ -14,11 +14,9 @@ auto HandleParenExpr(Context& context) -> void {
context.ConsumeChecked(Lex::TokenKind::OpenParen));
if (context.PositionIs(Lex::TokenKind::CloseParen)) {
state.state = State::TupleLiteralFinish;
context.PushState(state);
context.PushState(state, State::TupleLiteralFinish);
} else {
state.state = State::ParenExprFinish;
context.PushState(state);
context.PushState(state, State::ParenExprFinish);
context.PushState(State::ExprAfterOpenParenFinish);
context.PushState(State::Expr);
}
@@ -37,14 +35,12 @@ auto HandleExprAfterOpenParenFinish(Context& context) -> void {
auto finish_state = context.PopState();
CARBON_CHECK(finish_state.state == State::ParenExprFinish)
<< "Unexpected parent state, found: " << finish_state.state;
finish_state.state = State::TupleLiteralFinish;
context.PushState(finish_state);
context.PushState(finish_state, State::TupleLiteralFinish);
// If the comma is not immediately followed by a close paren, push handlers
// for the next tuple element.
if (list_token_kind != Context::ListTokenKind::CommaClose) {
state.state = State::TupleLiteralElementFinish;
context.PushState(state);
context.PushState(state, State::TupleLiteralElementFinish);
context.PushState(State::Expr);
}
}