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:
2
parser.h
2
parser.h
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user