summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorthing1 <thing1@seacrossedlovers.xyz>2025-04-22 11:18:16 +0100
committerthing1 <thing1@seacrossedlovers.xyz>2025-04-22 11:18:16 +0100
commit69eae10356e807c61192d025eee4d88896881619 (patch)
tree4e7515c93718c77c92aa3ab8ce0533343eee9db2 /main.c
Diffstat (limited to 'main.c')
-rw-r--r--main.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..cd6eb22
--- /dev/null
+++ b/main.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define STB_C_LEXER_SELF_TEST
+#define STB_C_LEXER_IMPLEMENTATION
+#include "stb_c_lexer.h"
+
+static int
+filelen(FILE *f) {
+ fseek(f, 0, SEEK_END);
+ int len = ftell(f);
+ rewind(f);
+ return len;
+}
+
+static char *
+readfile(FILE *f) {
+ int l = filelen(f);
+ char *conts = malloc(l+1);
+ conts[l] = 0;
+ fread(conts, sizeof(char), l, f);
+ return conts;
+}
+
+int
+main() {
+ FILE *f = fopen("sample.b", "r");
+ char *contents = readfile(f);
+ fclose(f);
+
+ stb_lexer l = {0};
+ char storage[1024] = {0};
+ stb_c_lexer_init(&l, contents, &contents[strlen(contents)], storage, 1024);
+
+ while (stb_c_lexer_get_token(&l) != 0) {
+ if (l.token == CLEX_parse_error) {
+ stb_lex_location loc = {0};
+ stb_c_lexer_get_location(&l, l.where_firstchar, &loc);
+ printf("%d:%d, error\n", loc.line_number, loc.line_offset);
+ }
+ print_token(&l);
+ printf("\n");
+ }
+
+ return 0;
+}