Files
zig/stage0/parser.h
Motiejus Jakštys 19b233e29b unify error handling: SET_ERROR(ctx, msg) for both parser and astgen
Replace parser's fail() and astgen's flag-only SET_ERROR(ag) with a
single SET_ERROR(ctx, msg) macro in common.h that stores the error
message in ctx->err_buf and sets ctx->has_compile_errors.  Both Parser
and AstGenCtx now carry the same err_buf[ERR_BUF_SIZE] field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 17:02:00 +00:00

37 lines
772 B
C

// parser.h
#ifndef _ZIG0_PARSE_H__
#define _ZIG0_PARSE_H__
#include "ast.h"
#include "common.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;
bool has_warn;
bool has_compile_errors;
char err_buf[ERR_BUF_SIZE];
} Parser;
// warn records a non-fatal parse error (like Zig's Parse.warn).
// Parsing continues.
static inline void warn(Parser* p) { p->has_warn = true; }
Parser* parserInit(const char* source, uint32_t len);
void parserDeinit(Parser* parser);
void parseRoot(Parser* parser);
#endif