aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/lexer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/lexer.h')
-rw-r--r--src/bootstrap/lexer.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/bootstrap/lexer.h b/src/bootstrap/lexer.h
new file mode 100644
index 0000000..129fd9a
--- /dev/null
+++ b/src/bootstrap/lexer.h
@@ -0,0 +1,66 @@
1#ifndef BDL_LEXER_H
2#define BDL_LEXER_H
3
4typedef enum TokenType {
5 TOKEN_UNKNOWN = 0,
6 TOKEN_LPAREN,
7 TOKEN_RPAREN,
8 TOKEN_QUOTE,
9 TOKEN_TRUE,
10 TOKEN_FALSE,
11 TOKEN_NIL,
12 TOKEN_FIXNUM,
13 TOKEN_SYMBOL,
14 TOKEN_STRING,
15 TOKEN_EOF,
16} TokenType;
17
18typedef struct Token {
19 TokenType type;
20 StringView value;
21 size_t line;
22 size_t column;
23} Token;
24
25typedef struct Tokens {
26 Token *buf;
27 size_t size;
28 size_t cap;
29} Tokens;
30
31typedef struct Scanner {
32 StringView current;
33 size_t line_number;
34 size_t col_number;
35 size_t offset;
36} Scanner;
37
38// Print a token to standard output for debugging purposes.
39void print_token(Token tok);
40
41// Push a token to the token list.
42void push_token(Tokens *tokens, Token tok);
43
44// Same functionality as the ScanView pairs, but keeping track of line and
45// column numbers.
46char scan_next(Scanner *scanner);
47char scan_peek(const Scanner *scanner);
48
49// Check if the current scanner still have characters left.
50bool scan_has_next(const Scanner *scanner);
51
52// Advance the scanner until we ran out of whitespace.
53void skip_whitespace(Scanner *scanner);
54
55// Check if a given character is a delimiter.
56bool is_delimiter(char c);
57
58// Extract the token type from the current string.
59TokenType find_primitive_type(const StringView value);
60
61// Generate a list of tokens from the given string.
62Tokens tokenize(const StringView *sv);
63
64#define TOK_BUF_CAP 256
65
66#endif // BDL_LEXER_H