From ee615b2b3b2b7b336fdd4334dba68801681c9c7b Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 15:11:15 +0000 Subject: fix(parser): accept bare NEXT and read its identifier only from the same line Co-Authored-By: Claude Sonnet 5.5 --- lib/Parser/ParserControlFlow.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'lib/Parser/ParserControlFlow.cc') diff --git a/lib/Parser/ParserControlFlow.cc b/lib/Parser/ParserControlFlow.cc index feedf44..7caf555 100644 --- a/lib/Parser/ParserControlFlow.cc +++ b/lib/Parser/ParserControlFlow.cc @@ -124,18 +124,17 @@ std::unique_ptr Parser::ParseForStmt() { return nullptr; } getNextToken(); - - if (CurTok != tok_identifier) { - cps::sourceError(Lex.getLine(), "expected identifier after NEXT (e.g., NEXT %s)", VarName.c_str()); - return nullptr; - } - if (!sameIdentifier(Lex.IdentifierStr, VarName)) { - cps::sourceError(Lex.getLine(), "NEXT identifier '%s' does not match FOR variable '%s'", - Lex.IdentifierStr.c_str(), VarName.c_str()); - return nullptr; + // The identifier after NEXT is optional; one on the next line starts a + // new statement. + if (CurTok == tok_identifier && !StartsLine) { + if (!sameIdentifier(Lex.IdentifierStr, VarName)) { + cps::sourceError(Lex.getLine(), "NEXT identifier '%s' does not match FOR variable '%s'", + Lex.IdentifierStr.c_str(), VarName.c_str()); + return nullptr; + } + getNextToken(); } - getNextToken(); return std::make_unique(VarName, std::move(Start), std::move(End), std::move(Step), std::move(Body)); } -- cgit v1.3.1-4-g156e