/** * Contains the interface for reading tokens from a file. */ #ifndef TOKEN_H #define TOKEN_H #include "location.h" /** * A list of all possible tokens. */ typedef enum { /* Keywords */ TOKEN_MODULE, TOKEN_IMPORT, TOKEN_SEMICOLON, TOKEN_ALIAS, TOKEN_PUBLIC, TOKEN_VAR, TOKEN_CONST, TOKEN_STATIC, /* Symbols */ TOKEN_PARENT_OPEN, TOKEN_PARENT_CLOSE, TOKEN_BRACKET_OPEN, TOKEN_BRACKET_CLOSE, TOKEN_COMMA, TOKEN_ASSIGN, /* Primitives */ TOKEN_VOID, TOKEN_I8, TOKEN_I16, TOKEN_I32, TOKEN_I64, TOKEN_U8, TOKEN_U16, TOKEN_U32, TOKEN_U64, /* Variable */ TOKEN_IDENTIFIER, /* Others */ TOKEN_EOF, TOKEN_UNKNOWN } TokenType; /** * Holds additional information about a token. */ typedef struct { /* @brief The actual token. */ TokenType token; /* @brief The textual representation of a token. */ String text; /* @brief The location of the token. */ Location location; } Token; typedef struct TokenStream TokenStream; /** * Returns a TokenStream for a text. * * @param filename The name of the file to read. This is only used for error reporting. * @param code The text to read. * @returns A handle to the TokenStream. */ TokenStream* tokenstream_open(const char* filename, const char* code); /** * Closes a TokenStream. * @param ts The TokenStream to close. */ void tokenstream_close(TokenStream* ts); /** * Gets the next token from the TokenStream. * @param ts The TokenStream to read from. * @returns The next token read. */ Token tokenstream_next(TokenStream* ts); #endif