larpcc/main.c
2026-09-28 03:31:04 +02:00

59 lines
1.4 KiB
C

#include "collection.h"
#include "parse.h"
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[])
{
if (argc < 2) {
fprintf(stderr, "error: no filename\n");
return EXIT_FAILURE;
}
char* filename = argv[1];
char* text = read_textfile(filename);
if (!text) {
return EXIT_FAILURE;
}
printf("--- text ---\n%s\n", text);
Arena tok_arena;
arena_init(&tok_arena, 4096);
Preproc* preproc = preproc_new(strdup(filename), text, &tok_arena);
TokStream tokstream;
tokstream_init(&tokstream, preproc, &tok_arena);
printf("--- tokens ---\n");
Loc loc = { 1, 1 };
Tok tok;
while ((tok = tokstream_next(&tokstream)).ty != Tok_Eof) {
// printf("%s\t%s\n", tokty_str(tok.ty), tok.text);
Loc tok_loc = tok.loc;
if (loc.line > tok_loc.line) {
loc.line = 0;
}
while (loc.line < tok_loc.line) {
printf("\n");
loc.line += 1;
loc.col = 1;
}
while (loc.col < tok_loc.col) {
printf(" ");
loc.col += 1;
}
printf("%s", tok.text);
loc.line = tok_loc.line;
loc.col = tok_loc.col + strlen(tok.text);
}
fputs("\n", stdout);
preproc_free(preproc);
arena_deinit(&tok_arena);
}