aboutsummaryrefslogtreecommitdiffstats
path: root/src/lexer.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-02-01 18:36:52 +0100
committerBad Diode <bd@badd10de.dev>2022-02-01 18:36:52 +0100
commitee1a5de91c875fb66724dc21c02333bfebe2a812 (patch)
treed3eaa226816d295bb9dc48a2aed27044832ec413 /src/lexer.h
parent3156265c7b2da8cc43fee996c0518ea274d39c8a (diff)
downloadbdl-ee1a5de91c875fb66724dc21c02333bfebe2a812.tar.gz
bdl-ee1a5de91c875fb66724dc21c02333bfebe2a812.zip
Add new syntax to lexer and prepare refactor
Diffstat (limited to 'src/lexer.h')
-rw-r--r--src/lexer.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lexer.h b/src/lexer.h
index c477fbd..d864a1d 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -9,9 +9,13 @@ typedef enum TokenType {
9 // Parentheses. 9 // Parentheses.
10 TOKEN_LPAREN, 10 TOKEN_LPAREN,
11 TOKEN_RPAREN, 11 TOKEN_RPAREN,
12 TOKEN_LSQUARE,
13 TOKEN_RSQUARE,
14 TOKEN_LCURLY,
15 TOKEN_RCURLY,
12 16
13 // Primitive types. 17 // Primitive types.
14 TOKEN_FIXNUM, 18 TOKEN_NUMBER,
15 TOKEN_SYMBOL, 19 TOKEN_SYMBOL,
16 TOKEN_STRING, 20 TOKEN_STRING,
17 TOKEN_NIL, 21 TOKEN_NIL,
@@ -24,6 +28,12 @@ typedef enum TokenType {
24 TOKEN_DEF, 28 TOKEN_DEF,
25 TOKEN_SET, 29 TOKEN_SET,
26 TOKEN_FUN, 30 TOKEN_FUN,
31 TOKEN_STRUCT,
32
33 // Special operators.
34 TOKEN_COLON,
35 TOKEN_DOT,
36 TOKEN_AT,
27 37
28 // End of file. 38 // End of file.
29 TOKEN_EOF, 39 TOKEN_EOF,
@@ -46,8 +56,8 @@ typedef struct Scanner {
46// Print a token to standard output for debugging purposes. 56// Print a token to standard output for debugging purposes.
47void print_token(Token tok); 57void print_token(Token tok);
48 58
49// Same functionality as the ScanView pairs, but keeping track of line and 59// Same functionality as with StringView, but keeping track of line and column
50// column numbers. 60// numbers.
51char scan_next(Scanner *scanner); 61char scan_next(Scanner *scanner);
52char scan_peek(const Scanner *scanner); 62char scan_peek(const Scanner *scanner);
53 63
@@ -61,9 +71,12 @@ void skip_whitespace(Scanner *scanner);
61bool is_delimiter(char c); 71bool is_delimiter(char c);
62 72
63// Extract the token type from the current string. 73// Extract the token type from the current string.
64TokenType find_primitive_type(const StringView value); 74TokenType find_token_type(const StringView value);
65 75
66// Generate a list of tokens from the given string. 76// Generate a list of tokens from the given string.
67Token * tokenize(const StringView *sv, Errors *errors); 77Token * tokenize(const StringView *sv);
78
79// Display tokens from token list.
80void print_tokens(Token *tokens);
68 81
69#endif // BDL_LEXER_H 82#endif // BDL_LEXER_H