aboutsummaryrefslogtreecommitdiffstats
path: root/src/treewalk/lexer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/treewalk/lexer.h')
-rw-r--r--src/treewalk/lexer.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/treewalk/lexer.h b/src/treewalk/lexer.h
new file mode 100644
index 0000000..2b2789f
--- /dev/null
+++ b/src/treewalk/lexer.h
@@ -0,0 +1,57 @@
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 Scanner {
26 StringView current;
27 size_t line_number;
28 size_t col_number;
29 size_t offset;
30} Scanner;
31
32// Print a token to standard output for debugging purposes.
33void print_token(Token tok);
34
35// Same functionality as the ScanView pairs, but keeping track of line and
36// column numbers.
37char scan_next(Scanner *scanner);
38char scan_peek(const Scanner *scanner);
39
40// Check if the current scanner still have characters left.
41bool scan_has_next(const Scanner *scanner);
42
43// Advance the scanner until we ran out of whitespace.
44void skip_whitespace(Scanner *scanner);
45
46// Check if a given character is a delimiter.
47bool is_delimiter(char c);
48
49// Extract the token type from the current string.
50TokenType find_primitive_type(const StringView value);
51
52// Generate a list of tokens from the given string.
53Token * tokenize(const StringView *sv);
54
55#define TOK_BUF_CAP 256
56
57#endif // BDL_LEXER_H