2024-03-16 14:07:47 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2024-03-19 15:09:51 +01:00
|
|
|
#include <sys/stat.h>
|
2024-03-16 14:07:47 +01:00
|
|
|
|
|
|
|
#include "mrk/lexer.h"
|
|
|
|
#include "mrk/parser.h"
|
|
|
|
#include "mrk/ast.h"
|
|
|
|
|
2024-03-19 15:09:51 +01:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
if (argc == 1) {
|
|
|
|
fprintf(stderr, "No file provided.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stat stat_s;
|
|
|
|
|
|
|
|
assert(stat(argv[1], &stat_s) == 0);
|
|
|
|
|
|
|
|
char *buf = malloc(stat_s.st_size);
|
|
|
|
assert(buf);
|
|
|
|
|
|
|
|
long read = 0;
|
|
|
|
|
|
|
|
FILE *f = fopen(argv[1], "rb");
|
|
|
|
assert(f);
|
|
|
|
|
|
|
|
while (read < stat_s.st_size) {
|
|
|
|
read += fread(buf + read, 1, stat_s.st_size - read, f);
|
|
|
|
}
|
2024-03-16 14:07:47 +01:00
|
|
|
|
|
|
|
mrk_lexer *lexer;
|
|
|
|
assert(mrk_lexer_init(&lexer) == mrk_err_ok);
|
2024-03-19 15:09:51 +01:00
|
|
|
mrk_lexer_open(lexer, buf, stat_s.st_size);
|
2024-03-16 14:07:47 +01:00
|
|
|
|
|
|
|
mrk_parser *parser;
|
|
|
|
assert(mrk_parser_init(&parser) == mrk_err_ok);
|
|
|
|
mrk_parser_open(parser, lexer);
|
|
|
|
|
|
|
|
mrk_ast_node *root;
|
|
|
|
assert(mrk_parser_parse(&root, parser) == mrk_err_ok);
|
|
|
|
|
|
|
|
char *html;
|
|
|
|
assert(mrk_ast_to_html(&html, buf, root) == mrk_err_ok);
|
|
|
|
|
|
|
|
printf("%s\n", html);
|
|
|
|
}
|