Recover from errors even inside REPT/FOR loops (#1683)

This commit is contained in:
Rangi
2025-05-04 17:51:53 -04:00
committed by GitHub
parent e1ae92709c
commit e95ac6fb06
6 changed files with 12 additions and 10 deletions

View File

@@ -71,7 +71,6 @@ void fstk_RunFor(
int32_t reptLineNo,
ContentSpan const &span
);
void fstk_StopRept();
bool fstk_Break();
void fstk_NewRecursionDepth(size_t newDepth);

View File

@@ -392,17 +392,13 @@ void fstk_RunFor(
context.forName = symName;
}
void fstk_StopRept() {
contextStack.top().nbReptIters = 0; // Prevent more iterations
}
bool fstk_Break() {
if (contextStack.top().fileInfo->type != NODE_REPT) {
error("BREAK can only be used inside a REPT/FOR block\n");
return false;
}
fstk_StopRept();
contextStack.top().nbReptIters = 0; // Prevent more iterations
return true;
}

View File

@@ -425,7 +425,6 @@ lines:
lexer_SetMode(LEXER_NORMAL);
lexer_ToggleStringExpansion(true);
} endofline {
fstk_StopRept();
yyerrok;
}
;

View File

@@ -2,7 +2,7 @@
println 42, 1 2 3 4
for n, 5
for n, 3
println "start {d:n}"
println syntax error
println "finish {d:n}"

View File

@@ -2,4 +2,8 @@ error: error-recovery.asm(3):
syntax error, unexpected number
error: error-recovery.asm(5) -> error-recovery.asm::REPT~1(7):
syntax error, unexpected symbol
error: Assembly aborted (2 errors)!
error: error-recovery.asm(5) -> error-recovery.asm::REPT~2(7):
syntax error, unexpected symbol
error: error-recovery.asm(5) -> error-recovery.asm::REPT~3(7):
syntax error, unexpected symbol
error: Assembly aborted (4 errors)!

View File

@@ -1,4 +1,8 @@
begin
$2Astart 0
finish 0
end 0
start 1
finish 1
start 2
finish 2
end 3