larpcc/main.c
2026-09-26 01:41:16 +02:00

60 lines
1.3 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 arena;
arena_init(&arena, 4096);
Preproc* preproc;
preproc_init(&preproc, strdup(filename), text, &arena);
TokStream tokstream;
tokstream_init(&tokstream, preproc, &arena);
printf("--- tokens ---\n");
int line = 1;
int col = 1;
Tok tok;
while ((tok = tokstream_next(&tokstream)).ty != Tok_Eof) {
// printf("%s\t%s\n", tokty_str(tok.ty), tok.text);
if (line > tok.line) {
line = 0;
}
while (line < tok.line) {
printf("\n");
line += 1;
col = 1;
}
while (col < tok.col) {
printf(" ");
col += 1;
}
printf("%s", tok.text);
line = tok.line;
col = tok.col + strlen(tok.text);
}
fputs("\n", stdout);
preproc_deinit(preproc);
arena_deinit(&arena);
}