aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/lexer.c')
-rw-r--r--src/bootstrap/lexer.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/bootstrap/lexer.c b/src/bootstrap/lexer.c
index ee387dd..05324eb 100644
--- a/src/bootstrap/lexer.c
+++ b/src/bootstrap/lexer.c
@@ -1,29 +1,4 @@
1typedef enum TokenType { 1#include "lexer.h"
2 TOKEN_UNKNOWN = 0,
3 TOKEN_LPAREN,
4 TOKEN_RPAREN,
5 TOKEN_QUOTE,
6 TOKEN_TRUE,
7 TOKEN_FALSE,
8 TOKEN_NIL,
9 TOKEN_FIXNUM,
10 TOKEN_SYMBOL,
11 TOKEN_STRING,
12 TOKEN_EOF,
13} TokenType;
14
15typedef struct Token {
16 TokenType type;
17 StringView value;
18 size_t line;
19 size_t column;
20} Token;
21
22typedef struct Tokens {
23 Token *buf;
24 size_t size;
25 size_t cap;
26} Tokens;
27 2
28void 3void
29print_token(Token tok) { 4print_token(Token tok) {
@@ -69,8 +44,6 @@ print_token(Token tok) {
69 printf("\n"); 44 printf("\n");
70} 45}
71 46
72#define TOK_BUF_CAP 256
73
74void 47void
75push_token(Tokens *tokens, Token tok) { 48push_token(Tokens *tokens, Token tok) {
76 if (tokens->buf == NULL) { 49 if (tokens->buf == NULL) {
@@ -84,13 +57,6 @@ push_token(Tokens *tokens, Token tok) {
84 tokens->buf[tokens->size++] = tok; 57 tokens->buf[tokens->size++] = tok;
85} 58}
86 59
87typedef struct Scanner {
88 StringView current;
89 size_t line_number;
90 size_t col_number;
91 size_t offset;
92} Scanner;
93
94char 60char
95scan_next(Scanner *scanner) { 61scan_next(Scanner *scanner) {
96 char c = sv_next(&scanner->current); 62 char c = sv_next(&scanner->current);
@@ -157,7 +123,7 @@ is_delimiter(char c) {
157} 123}
158 124
159TokenType 125TokenType
160find_primitive_type(StringView value) { 126find_primitive_type(const StringView value) {
161 bool is_fixnum = true; 127 bool is_fixnum = true;
162 for (size_t i = 0; i < value.n; i++) { 128 for (size_t i = 0; i < value.n; i++) {
163 char c = value.start[i]; 129 char c = value.start[i];