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>
This commit is contained in:
+8
-3
@@ -4,6 +4,8 @@
|
||||
#ifndef TOKEN_H
|
||||
#define TOKEN_H
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
typedef enum {
|
||||
// Keywords
|
||||
TOKEN_MODULE,
|
||||
@@ -34,11 +36,14 @@ typedef struct TokenStream TokenStream;
|
||||
const char* token_to_string(Token token);
|
||||
|
||||
/**
|
||||
* Opens a file and returns a TokenStream for it.
|
||||
* @param path The path to the file.
|
||||
* 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(const char* path);
|
||||
TokenStream* tokenstream_open(Buffer* buffer);
|
||||
|
||||
/**
|
||||
* Closes a TokenStream.
|
||||
|
||||
Reference in New Issue
Block a user