parser: propagate errors via setjmp/longjmp instead of exit(1)

Replace 32 parse-error exit(1) calls with longjmp to allow callers to
detect and handle parse failures. The OOM exit(1) in
astNodeListEnsureCapacity is kept as-is.

Add has_error flag to Ast, wrap parseRoot() with setjmp in astParse(),
and update test infrastructure to use the C parser for testError tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-11 10:18:22 +00:00
parent bda3329eee
commit f5f54fcbe8
5 changed files with 53 additions and 45 deletions

View File

@@ -4,6 +4,7 @@
#include "ast.h"
#include "common.h"
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
@@ -20,6 +21,7 @@ typedef struct {
AstNodeList nodes;
AstNodeIndexSlice extra_data;
AstNodeIndexSlice scratch;
jmp_buf error_jmp;
} Parser;
Parser* parserInit(const char* source, uint32_t len);