mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Add a macro to simplify XAsY variant state generation (#2679)
This is just a mild simplification to address repeat macro use. I'm hoping it makes it clearer and easier in parser_state.def to write down the multiple variants. I'm writing these macros in a simple form that I think is easy to read, versus some complex macro recursion which I think is _possible_ but would be harder to reason. And, we don't really need arbitrary arg counts -- this is probably going to stay fairly limited long-term, although I could easily see something like a half dozen in some cases so maybe I'll be wrong and it'll go higher. But, I feel like these macros still make it easier to focus on the _intent_ of cases, rather than visually comparing each line for differences. Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Chandler Carruth
parent
bcbeb7af08
commit
51f887c348
@@ -1360,7 +1360,7 @@ auto Parser::HandleParenExpressionState() -> void {
|
||||
state.state = ParserState::ParenExpressionFinishAsTuple;
|
||||
PushState(state);
|
||||
} else {
|
||||
state.state = ParserState::ParenExpressionFinish;
|
||||
state.state = ParserState::ParenExpressionFinishAsNormal;
|
||||
PushState(state);
|
||||
PushState(ParserState::ParenExpressionParameterFinishAsUnknown);
|
||||
PushState(ParserState::Expression);
|
||||
@@ -1383,7 +1383,8 @@ auto Parser::HandleParenExpressionParameterFinish(bool as_tuple) -> void {
|
||||
state.state = ParserState::ParenExpressionParameterFinishAsTuple;
|
||||
|
||||
auto finish_state = PopState();
|
||||
CARBON_CHECK(finish_state.state == ParserState::ParenExpressionFinish)
|
||||
CARBON_CHECK(finish_state.state ==
|
||||
ParserState::ParenExpressionFinishAsNormal)
|
||||
<< "Unexpected parent state, found: " << finish_state.state;
|
||||
finish_state.state = ParserState::ParenExpressionFinishAsTuple;
|
||||
PushState(finish_state);
|
||||
@@ -1404,7 +1405,7 @@ auto Parser::HandleParenExpressionParameterFinishAsTupleState() -> void {
|
||||
HandleParenExpressionParameterFinish(/*as_tuple=*/true);
|
||||
}
|
||||
|
||||
auto Parser::HandleParenExpressionFinishState() -> void {
|
||||
auto Parser::HandleParenExpressionFinishAsNormalState() -> void {
|
||||
auto state = PopState();
|
||||
|
||||
AddNode(ParseNodeKind::ParenExpression, Consume(), state.subtree_start,
|
||||
|
||||
Reference in New Issue
Block a user