From c219c38e854fe15bc47519d2df0d6cbd7bab2ab7 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 21 Apr 2021 00:05:04 +0200 Subject: Started syntax highlighting doesn't work but don't want to fix lel. --- src/syntax.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/syntax.c (limited to 'src/syntax.c') diff --git a/src/syntax.c b/src/syntax.c new file mode 100644 index 0000000..d01496e --- /dev/null +++ b/src/syntax.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +struct pos { + u32 x; + u32 y; +}; + +static void syntax_highlight_line(struct pos *pos, char *str, u32 size) +{ + while (1) { + /* printf("%d:%d\n", pos->y, pos->x); */ + struct token tok = token_resolve(str + pos->x, size - pos->x); + + if (tok.type == NEWLINE) { + pos->x = 0; + pos->y++; + return; + } + + if (tok.type == UNKNOWN) + return; + + if (tok.type == SPACE) { + pos->x += tok.length; + continue; + } + + token_print(&tok); + + /* if (tok.type > INSTR_START && tok.type < INSTR_END) */ + /* gui_highlight(pos->x, pos->y, tok.length, "instr"); */ + /* else if (tok.type > REGS_START && tok.type < REGS_END) { */ + /* gui_highlight(pos->x, pos->y, tok.length, "regs"); */ + /* } */ + + pos->x += tok.length; + } +} + +void syntax_highlight(char *buf, u32 size) +{ + return; // TODO: Fix some stuff + struct pos pos = { 0 }; + + char *start = buf; + for (u32 i = 0; i < size; i++) { + if (buf[i] == '\0') + break; + + if (buf[i] == '\n') { + pos.x = 0; + syntax_highlight_line(&pos, start, i); + start += i; + } + } +} -- cgit v1.2.3