Change return of SkipPastLikelyEnd to be last consumed token (#3493)

This approach means the parse subtree includes the full token range
consumed.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
josh11b
2023-12-11 22:11:09 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 1addf10054
commit 6067ca3f49
28 changed files with 72 additions and 94 deletions
+4 -11
View File
@@ -52,19 +52,12 @@ static auto TryHandleEndOrPackagingDecl(Context& context) -> bool {
static auto FinishAndSkipInvalidDecl(Context& context, int32_t subtree_start)
-> void {
auto cursor = *context.position();
// Consume to the next `;` or end of line. We ignore the return value since
// we only care how much was consumed, not whether it ended with a `;`.
// TODO: adjust the return of SkipPastLikelyEnd or create a new function
// to avoid going through these hoops.
context.SkipPastLikelyEnd(cursor);
// Set `iter` to the last token consumed, one before the current position.
auto iter = context.position();
--iter;
// Output an invalid parse subtree including everything up to the last token
// consumed.
// Output an invalid parse subtree including everything up to the next `;`
// or end of line.
context.ReplacePlaceholderNode(subtree_start, NodeKind::InvalidParseStart,
cursor, /*has_error=*/true);
context.AddNode(NodeKind::InvalidParseSubtree, *iter, subtree_start,
context.AddNode(NodeKind::InvalidParseSubtree,
context.SkipPastLikelyEnd(cursor), subtree_start,
/*has_error=*/true);
}