- Add warn() for non-fatal parse errors (like Zig's Parse.warn) - Implement finishAssignDestructureExpr for destructuring assignments - Use parseBlockExpr instead of parseBlock in for/while statement bodies - Use parseSingleAssignExpr in switch prongs - Enable x86_64/CodeGen.zig corpus entry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.1 KiB
C
50 lines
1.1 KiB
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>
|
|
#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;
|
|
bool has_warn;
|
|
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);
|
|
}
|
|
|
|
// warn records a non-fatal parse error (like Zig's Parse.warn).
|
|
// Unlike fail(), 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
|