From 043a96a6b7cf55f7ef58fb5ebf8ad87b7d50b571 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 18 Oct 2021 12:31:20 +0200 Subject: Add header files for all modules --- src/bootstrap/lexer.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/bootstrap/lexer.h (limited to 'src/bootstrap/lexer.h') 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 @@ +#ifndef BDL_LEXER_H +#define BDL_LEXER_H + +typedef enum TokenType { + TOKEN_UNKNOWN = 0, + TOKEN_LPAREN, + TOKEN_RPAREN, + TOKEN_QUOTE, + TOKEN_TRUE, + TOKEN_FALSE, + TOKEN_NIL, + TOKEN_FIXNUM, + TOKEN_SYMBOL, + TOKEN_STRING, + TOKEN_EOF, +} TokenType; + +typedef struct Token { + TokenType type; + StringView value; + size_t line; + size_t column; +} Token; + +typedef struct Tokens { + Token *buf; + size_t size; + size_t cap; +} Tokens; + +typedef struct Scanner { + StringView current; + size_t line_number; + size_t col_number; + size_t offset; +} Scanner; + +// Print a token to standard output for debugging purposes. +void print_token(Token tok); + +// Push a token to the token list. +void push_token(Tokens *tokens, Token tok); + +// Same functionality as the ScanView pairs, but keeping track of line and +// column numbers. +char scan_next(Scanner *scanner); +char scan_peek(const Scanner *scanner); + +// Check if the current scanner still have characters left. +bool scan_has_next(const Scanner *scanner); + +// Advance the scanner until we ran out of whitespace. +void skip_whitespace(Scanner *scanner); + +// Check if a given character is a delimiter. +bool is_delimiter(char c); + +// Extract the token type from the current string. +TokenType find_primitive_type(const StringView value); + +// Generate a list of tokens from the given string. +Tokens tokenize(const StringView *sv); + +#define TOK_BUF_CAP 256 + +#endif // BDL_LEXER_H -- cgit v1.2.1