aboutsummaryrefslogtreecommitdiffstats
path: root/src/lexer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer.h')
-rw-r--r--src/lexer.h99
1 files changed, 0 insertions, 99 deletions
diff --git a/src/lexer.h b/src/lexer.h
deleted file mode 100644
index 949abaf..0000000
--- a/src/lexer.h
+++ /dev/null
@@ -1,99 +0,0 @@
1#ifndef BDL_LEXER_H
2#define BDL_LEXER_H
3
4#include "string_view.h"
5
6typedef enum TokenType {
7 TOKEN_UNKNOWN = 0,
8
9 // Parentheses.
10 TOKEN_LPAREN,
11 TOKEN_RPAREN,
12 TOKEN_LSQUARE,
13 TOKEN_RSQUARE,
14 TOKEN_LCURLY,
15 TOKEN_RCURLY,
16
17 // Primitive types.
18 TOKEN_NUMBER,
19 TOKEN_SYMBOL,
20 TOKEN_STRING,
21 TOKEN_NIL,
22 TOKEN_TRUE,
23 TOKEN_FALSE,
24
25 // Keywords.
26 TOKEN_LAMBDA,
27 TOKEN_IF,
28 TOKEN_DEF,
29 TOKEN_SET,
30 TOKEN_FUN,
31 TOKEN_STRUCT,
32
33 // Arithmetic ops.
34 TOKEN_ADD,
35 TOKEN_SUB,
36 TOKEN_MUL,
37 TOKEN_DIV,
38 TOKEN_MOD,
39
40 // Boolean operations.
41 TOKEN_NOT,
42 TOKEN_AND,
43 TOKEN_OR,
44 TOKEN_EQ,
45 TOKEN_LT,
46 TOKEN_GT,
47 TOKEN_LE,
48 TOKEN_GE,
49
50 // Special operators.
51 TOKEN_COLON,
52 TOKEN_DOT,
53 TOKEN_AT,
54
55 // End of file.
56 TOKEN_EOF,
57} TokenType;
58
59typedef struct Token {
60 TokenType type;
61 StringView value;
62 size_t line;
63 size_t col;
64} Token;
65
66typedef struct Scanner {
67 StringView current;
68 size_t line_number;
69 size_t col_number;
70 size_t offset;
71} Scanner;
72
73// Print a token to standard output for debugging purposes.
74void print_token(Token tok);
75
76// Same functionality as with StringView, but keeping track of line and column
77// numbers.
78char scan_next(Scanner *scanner);
79char scan_peek(const Scanner *scanner);
80
81// Check if the current scanner still have characters left.
82bool scan_has_next(const Scanner *scanner);
83
84// Advance the scanner until we ran out of whitespace.
85void skip_whitespace(Scanner *scanner);
86
87// Check if a given character is a delimiter.
88bool is_delimiter(char c);
89
90// Extract the token type from the current string.
91TokenType find_token_type(const StringView value);
92
93// Generate a list of tokens from the given string.
94Token * tokenize(const StringView *sv);
95
96// Display tokens from token list.
97void print_tokens(Token *tokens);
98
99#endif // BDL_LEXER_H