aboutsummaryrefslogtreecommitdiff
path: root/src/lexer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer.h')
-rw-r--r--src/lexer.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lexer.h b/src/lexer.h
new file mode 100644
index 0000000..7c67028
--- /dev/null
+++ b/src/lexer.h
@@ -0,0 +1,58 @@
+#ifndef LEXER_H
+#define LEXER_H
+
+#include <stdio.h>
+
+#define TOKEN_TYPES(X) \
+ X(TOKEN_LP) \
+ X(TOKEN_RP) \
+ X(TOKEN_ID) \
+ X(TOKEN_STR) \
+ X(TOKEN_INT) \
+ X(TOKEN_DOT) \
+ X(TOKEN_QUOTE) \
+ X(TOKEN_UNQUOTE) \
+ X(TOKEN_LAMBDA) \
+ X(TOKEN_DEFINE) \
+ X(TOKEN_QUOTE_FORM) \
+ X(TOKEN_NONE)
+
+#define TO_ENUM(type) type,
+#define TO_STRING(type) #type,
+
+extern const char * const token_type_string[];
+
+struct token {
+ enum token_type {
+ TOKEN_TYPES(TO_ENUM)
+ } type;
+
+ union {
+ char *id;
+ char *str;
+ int num;
+ } value;
+};
+
+typedef struct lexer * lexer_t;
+#define LEXER_EMPTY NULL
+
+struct lexer {
+ FILE *fp;
+ size_t line;
+
+ char str[256];
+ size_t str_idx;
+
+ struct token token;
+ char acc[256];
+ size_t acc_idx;
+};
+
+lexer_t lexer_create(FILE *fp);
+void lexer_destroy(lexer_t lexer);
+int lexer_token_next(lexer_t lexer, struct token *token);
+
+int token_value_string(struct token *token, size_t buf_sz, char *buf);
+
+#endif