aboutsummaryrefslogtreecommitdiff
path: root/include/cps/Parser.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 12:11:00 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 12:11:00 +0000
commitfdef2814d0d7e65573d1b666ae9bc561fa35a9f9 (patch)
tree043b9dbe477f85c82bb334d68363bc70196a9d47 /include/cps/Parser.h
parent4a25b279d8f6c662fa8152cfe42e038d1ea06901 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/Parser.h')
-rw-r--r--include/cps/Parser.h4
1 files changed, 4 insertions, 0 deletions
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 <vector>
+#include <initializer_list>
#include <memory>
#include <map>
#include <optional>
@@ -32,6 +33,9 @@ class Parser {
std::unique_ptr<StmtAST> ParseStatement();
std::unique_ptr<StmtAST> ParseStatementImpl();
+ std::vector<std::unique_ptr<StmtAST>> ParseBlock(std::initializer_list<int> Terminators);
+ std::optional<std::vector<std::unique_ptr<ExprAST>>> ParseExprList(char CloseDelim, bool AllowEmpty);
+ void syncToStatementStart();
std::unique_ptr<StmtAST> ParseIfStmt();
std::unique_ptr<StmtAST> ParseWhileStmt();
std::unique_ptr<StmtAST> ParseRepeatStmt();