#define _POSIX_C_SOURCE 200809L #include #include #include #include #include "parse.h" #include "util.h" static noreturn void error(struct location loc, const char *fmt, ...) { fprintf(stderr, "%s:%d:%d ", loc.file, loc.line, loc.column); va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); exit(EXIT_PARSE); } static void append(struct path *path, const char *name) { if (path->seglen >= path->segsz) { path->segsz *= 2; size_t sz = sizeof(const char *) * path->segsz; path->segments = must_realloc(path->segments, sz); } path->segments[path->seglen++] = name; } static bool parse_path(struct lexer *lexer, struct path *out) { struct token name; if (lex(lexer, &name) != T_NAME) { unlex(lexer, &name); return false; } out->segments = must_calloc(1, sizeof(const char *)); out->segments[0] = name.info.str; out->seglen = 1; out->segsz = 1; while (match(lexer, T_MODDELIM)) { if (lex(lexer, &name) != T_NAME) { error(name.loc, "syntax error: expected name"); } append(out, name.info.str); } return true; } void parse(struct lexer *lexer, struct ast_unit *u) { }