Files
zig/parser.h
Motiejus Jakštys f5f54fcbe8 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>
2026-02-11 14:40:31 +00:00

32 lines
588 B
C

// parser.h
#ifndef _ZIG0_PARSE_H__
#define _ZIG0_PARSE_H__
#include "ast.h"
#include "common.h"
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
typedef struct {
const char* source;
uint32_t source_len;
TokenizerTag* token_tags;
AstIndex* token_starts;
uint32_t tokens_len;
AstTokenIndex tok_i;
AstNodeList nodes;
AstNodeIndexSlice extra_data;
AstNodeIndexSlice scratch;
jmp_buf error_jmp;
} Parser;
Parser* parserInit(const char* source, uint32_t len);
void parserDeinit(Parser* parser);
void parseRoot(Parser* parser);
#endif