summaryrefslogtreecommitdiff
path: root/src/lex.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lex.h')
-rw-r--r--src/lex.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/lex.h b/src/lex.h
new file mode 100644
index 0000000..02e427e
--- /dev/null
+++ b/src/lex.h
@@ -0,0 +1,76 @@
+#ifndef LEX_H
+#define LEX_H
+
+#include "sv.h"
+
+#include <stddef.h>
+
+#define TOKEN_EOF (struct token){ \
+ .type = T_EOF, \
+ .me = (struct string_view){.buf = NULL, .len = 0} \
+ }
+
+#define TOKEN_EQUAL_SIGN (struct token){ \
+ .type = T_EQUAL_SIGN, \
+ .me = (struct string_view){.buf = "=", .len = 1} \
+ }
+
+#define TOKEN_SEMICOLON (struct token){ \
+ .type = T_SEMICOL, \
+ .me = (struct string_view){.buf = ";", .len = 1} \
+ }
+
+#define TOKEN_SCOPE_START (struct token){ \
+ .type = T_SCOPESTART, \
+ .me = (struct string_view){.buf = "{", .len = 1} \
+ }
+
+#define TOKEN_SCOPE_END (struct token){ \
+ .type = T_SCOPEEND, \
+ .me = (struct string_view){.buf = "}", .len = 1} \
+ }
+
+#define T_TYPE (uint64_t)0xFF000000
+
+#define T_ERR (uint32_t)0
+#define T_ID (uint32_t)1
+#define T_STRING (uint32_t)2
+#define T_SEMICOL (uint32_t)3
+#define T_NUMBER (uint32_t)4
+#define T_EQUAL_SIGN (uint32_t)5
+#define T_SCOPESTART (uint32_t)6
+#define T_SCOPEEND (uint32_t)7
+#define T_TYPE_G64 (uint64_t)T_TYPE | (uint32_t)8
+#define T_TYPE_G32 (uint64_t)T_TYPE | (uint32_t)9
+#define T_TYPE_G16 (uint64_t)T_TYPE | (uint32_t)10
+#define T_TYPE_G8 (uint64_t)T_TYPE | (uint32_t)11
+#define T_EOF (uint32_t)12
+
+struct token {
+ uint64_t type;
+ struct string_view me;
+};
+
+struct lex_config {
+ char *src;
+ struct string_pool *sp;
+ size_t size;
+ size_t pos;
+};
+
+int lex_keyword_lookup(struct string_view sv, uint64_t *res);
+int lex_is_char(char c);
+int lex_is_digit(char c);
+int lex_within_bounds(struct lex_config *lc);
+int lex_within_obounds(struct lex_config *lc, size_t o);
+char lex_peek(struct lex_config *lc, size_t o);
+char lex_advance(struct lex_config *lc);
+int lex_is_space(char c);
+void lex_skip_whitespace(struct lex_config *lc);
+struct token lex_word(struct lex_config *lc);
+struct token lex_number(struct lex_config *lc);
+struct token lex_opcode(struct lex_config *lc);
+
+struct token lex_next(struct lex_config *lc);
+
+#endif