#ifndef LEXER_H #define LEXER_H #include #include typedef enum { TokenTypeEof, TokenTypeInvalidChar, TokenTypeMalformedMultilineComment, TokenTypeMalformedChar, TokenTypeMalformedString, TokenTypeId, TokenTypeInt, TokenTypeIntDoubleDot, TokenTypeHex, TokenTypeBinary, TokenTypeFloat, TokenTypeChar, TokenTypeString, TokenTypeIf, TokenTypeElse, TokenTypeLoop, TokenTypeWhile, TokenTypeFor, TokenTypeIn, TokenTypeBreak, TokenTypeLet, TokenTypeMatch, TokenTypeFalse, TokenTypeTrue, TokenTypeNot, TokenTypeAnd, TokenTypeOr, TokenTypeFn, TokenTypeReturn, TokenTypeMut, TokenTypeDefer, TokenTypeLParen, TokenTypeRParen, TokenTypeLBrace, TokenTypeRBrace, TokenTypeLBracket, TokenTypeRBracket, TokenTypeComma, TokenTypeColon, TokenTypeDoubleColon, TokenTypeDoubleColonLt, TokenTypeSemicolon, TokenTypeAmpersand, TokenTypeUnderscore, TokenTypeDot, TokenTypeDoubleDot, TokenTypeDoubleDotEqual, TokenTypeDoubleDotLt, TokenTypePlusEqual, TokenTypeMinusEqual, TokenTypeAsteriskEqual, TokenTypeSlashEqual, TokenTypePercentEqual, TokenTypeDoubleEqual, TokenTypeExclamationEqual, TokenTypeLtEqual, TokenTypeGtEqual, TokenTypePlus, TokenTypeMinus, TokenTypeAsterisk, TokenTypeSlash, TokenTypePercent, TokenTypeEqual, TokenTypeExclamation, TokenTypeLt, TokenTypeGt, } TokenType; const char* token_type_to_string(TokenType type); typedef struct { size_t index; int line, column; } Position; typedef struct { TokenType type; Position position; size_t length; } Token; char* token_string(const Token* token, const char* text); char* token_to_string(const Token* token, const char* text); typedef struct { const char* text; size_t index, length; int line, column; } Lexer; void lexer_create(Lexer* lexer, const char* text, size_t text_length); Token lexer_next(Lexer* lexer); char* lexer_token_string(const Lexer* lexer, const Token* token); Token lexer_skip_whitespace(Lexer* lexer); Token lexer_make_int_or_float(Lexer* lexer); Token lexer_make_id(Lexer* lexer); bool lexer_span_matches(const Lexer* lexer, Position begin, const char* value); Token lexer_make_static_token(Lexer* lexer); Token lexer_make_int_hex_binary_or_float(Lexer* lexer); Token lexer_make_char(Lexer* lexer); Token lexer_make_string(Lexer* lexer); void lexer_skip_literal_char(Lexer* lexer); Token lexer_make_single_char_token(Lexer* lexer, TokenType type); Token lexer_make_dot_token(Lexer* lexer); Token lexer_make_colon_token(Lexer* lexer); Token lexer_make_slash_token(Lexer* lexer); Token lexer_skip_singleline_comment(Lexer* lexer); Token lexer_make_single_or_double_char_token(Lexer* lexer, TokenType single_type, char second_char, TokenType double_type); Token lexer_skip_multiline_comment(Lexer* lexer); Token lexer_make_invalid_char(Lexer* lexer); Position lexer_position(const Lexer* lexer); Token lexer_token(const Lexer* lexer, TokenType type, Position begin); bool lexer_done(const Lexer* lexer); char lexer_current(const Lexer* lexer); void lexer_step(Lexer* lexer); #endif