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