Add 'stage0/' from commit 'b3d106ec971300a9c745f4681fab3df7518c4346'

git-subtree-dir: stage0
git-subtree-mainline: 3db960767d
git-subtree-split: b3d106ec97
This commit is contained in:
2026-02-13 23:32:08 +02:00
26 changed files with 26186 additions and 0 deletions

44
stage0/parser.h Normal file
View File

@@ -0,0 +1,44 @@
// 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>
#include <string.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;
char* err_buf;
} Parser;
#define PARSE_ERR_BUF_SIZE 200
_Noreturn static inline void fail(Parser* p, const char* msg) {
size_t len = strlen(msg);
if (len >= PARSE_ERR_BUF_SIZE)
len = PARSE_ERR_BUF_SIZE - 1;
memcpy(p->err_buf, msg, len);
p->err_buf[len] = '\0';
longjmp(p->error_jmp, 1);
}
Parser* parserInit(const char* source, uint32_t len);
void parserDeinit(Parser* parser);
void parseRoot(Parser* parser);
#endif