parser.h (921B) - Raw
1 // parser.h 2 #ifndef _ZIG0_PARSE_H__ 3 #define _ZIG0_PARSE_H__ 4 5 #include "ast.h" 6 #include "common.h" 7 #include <setjmp.h> 8 #include <stdbool.h> 9 #include <stdint.h> 10 #include <string.h> 11 12 typedef struct { 13 const char* source; 14 uint32_t source_len; 15 16 TokenizerTag* token_tags; 17 AstIndex* token_starts; 18 uint32_t tokens_len; 19 20 AstTokenIndex tok_i; 21 22 AstNodeList nodes; 23 AstNodeIndexSlice extra_data; 24 AstNodeIndexSlice scratch; 25 jmp_buf error_jmp; 26 char* err_buf; 27 } Parser; 28 29 #define PARSE_ERR_BUF_SIZE 200 30 31 _Noreturn static inline void fail(Parser* p, const char* msg) { 32 size_t len = strlen(msg); 33 if (len >= PARSE_ERR_BUF_SIZE) 34 len = PARSE_ERR_BUF_SIZE - 1; 35 memcpy(p->err_buf, msg, len); 36 p->err_buf[len] = '\0'; 37 longjmp(p->error_jmp, 1); 38 } 39 40 Parser* parserInit(const char* source, uint32_t len); 41 void parserDeinit(Parser* parser); 42 void parseRoot(Parser* parser); 43 44 #endif