Change StructLiteral and StructTypeLiteral parsing to use an ambiguous start. (#2396)

This is necessary in order to use a bracketing approach; parsing doesn't know the contained format until it parses the first element, which we don't want to do look-ahead for. I think the bracketing is higher value than knowing the format before adding the node.
This commit is contained in:
Jon Ross-Perkins authored and GitHub committed 2022-11-15 22:44:57 -08:00
1 parent b914f46ec5
commit c165ab6c2b
3 files changed
+17 -21

No files matched your search

+4 -8
View File
@@ -429,12 +429,9 @@ auto Parser::HandleBraceExpressionState() -> void {
state.state = ParserState::BraceExpressionFinishAsUnknown();
PushState(state);
// TODO: When swapping {} start/end, this should AddLeafNode the open before
// continuing.
// Advance past the open brace.
CARBON_CHECK(PositionIs(TokenKind::OpenCurlyBrace()));
++position_;
CARBON_CHECK(ConsumeAndAddLeafNodeIf(
TokenKind::OpenCurlyBrace(),
ParseNodeKind::StructLiteralOrTypeLiteralStart()));
if (!PositionIs(TokenKind::CloseCurlyBrace())) {
PushState(ParserState::BraceExpressionParameterAsUnknown());
}
@@ -612,10 +609,9 @@ auto Parser::HandleBraceExpressionParameterFinishAsUnknownState() -> void {
auto Parser::HandleBraceExpressionFinish(BraceExpressionKind kind) -> void {
auto state = PopState();
AddLeafNode(ParseNodeKind::StructEnd(), Consume());
AddNode(kind == BraceExpressionKind::Type ? ParseNodeKind::StructTypeLiteral()
: ParseNodeKind::StructLiteral(),
state.token, state.subtree_start, state.has_error);
Consume(), state.subtree_start, state.has_error);
}
auto Parser::HandleBraceExpressionFinishAsTypeState() -> void {