Files
c2/v0/token.h
T
seeseemelk c1106d8e66 Update tokenstream_open to accept Buffer parameter instead of file path
The tokenstream_open function now takes a Buffer* parameter instead of a file
path string, making the API more flexible and allowing the caller to manage
buffer lifetime. The tokenstream_close function continues to close the underlying
buffer as documented.

- Changed tokenstream_open signature from (const char* path) to (Buffer* buffer)
- Updated implementation to accept and use the provided buffer directly
- Updated all tests to open buffers separately and pass them to tokenstream_open
- Added #include "buffer.h" to token.h for Buffer type definition
- All 15 tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 09:41:18 +02:00

61 lines
1.1 KiB
C

/**
* Contains the interface for reading tokens from a file.
*/
#ifndef TOKEN_H
#define TOKEN_H
#include "buffer.h"
typedef enum {
// Keywords
TOKEN_MODULE,
TOKEN_IMPORT,
TOKEN_SEMICOLON,
// Symbols
TOKEN_PARENT_OPEN,
TOKEN_PARENT_CLOSE,
TOKEN_BRACKET_OPEN,
TOKEN_BRACKET_CLOSE,
TOKEN_COMMA,
// Primitives
TOKEN_VOID,
// Variable
TOKEN_IDENTIFIER,
} Token;
typedef struct TokenStream TokenStream;
/**
* Convert a Token enum to its string representation.
* @param token The token to convert.
* @returns The string name of the token.
*/
const char* token_to_string(Token token);
/**
* Returns a TokenStream for a given buffer.
*
* When the tokenstream is closed, the underlying buffer is also closed.
*
* @param buffer The buffer to read from.
* @returns A handle to the TokenStream.
*/
TokenStream* tokenstream_open(Buffer* buffer);
/**
* 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