Add 'stage0/' from commit 'b3d106ec971300a9c745f4681fab3df7518c4346'
git-subtree-dir: stage0 git-subtree-mainline:3db960767dgit-subtree-split:b3d106ec97
This commit is contained in:
44
stage0/parser.h
Normal file
44
stage0/parser.h
Normal 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
|
||||
Reference in New Issue
Block a user