From fdef2814d0d7e65573d1b666ae9bc561fa35a9f9 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:11:00 +0000 Subject: refactor: extract ParseBlock/ParseExprList, resync-based error recovery Seven copy-pasted statement-block loops collapse into ParseBlock(terminators); five comma-separated expression-list loops collapse into ParseExprList(close, allowEmpty), which also fixes "arr[1 2] <- x" being silently accepted as arr[1,2] on the statement path. Error recovery now lives in one place: syncToStatementStart skips to the next statement-start/block-end token, so a bad statement no longer swallows the first token of the following good one. Drop the dead -1000/-1001 token check in ParsePrototypeArgs. Co-Authored-By: Claude Fable 5 --- include/cps/Parser.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/cps/Parser.h b/include/cps/Parser.h index c83be8b..7d19c77 100644 --- a/include/cps/Parser.h +++ b/include/cps/Parser.h @@ -2,6 +2,7 @@ #include "cps/Lexer.h" #include "cps/AST.h" #include +#include #include #include #include @@ -32,6 +33,9 @@ class Parser { std::unique_ptr ParseStatement(); std::unique_ptr ParseStatementImpl(); + std::vector> ParseBlock(std::initializer_list Terminators); + std::optional>> ParseExprList(char CloseDelim, bool AllowEmpty); + void syncToStatementStart(); std::unique_ptr ParseIfStmt(); std::unique_ptr ParseWhileStmt(); std::unique_ptr ParseRepeatStmt(); -- cgit v1.3.1-4-g156e