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:
2026-04-24 09:41:18 +02:00
parent dccdcb8ba5
commit c1106d8e66
3 changed files with 46 additions and 24 deletions
+3 -7
View File
@@ -103,19 +103,15 @@ static Token read_keyword_or_identifier(TokenStream* ts, char first) {
return TOKEN_IDENTIFIER;
}
TokenStream* tokenstream_open(const char* path) {
if (path == NULL) return NULL;
Buffer* buf = buffer_open_file(path);
if (buf == NULL) return NULL;
TokenStream* tokenstream_open(Buffer* buffer) {
if (buffer == NULL) return NULL;
TokenStream* ts = (TokenStream*)malloc(sizeof(struct TokenStream));
if (ts == NULL) {
buffer_close(buf);
return NULL;
}
ts->buffer = buf;
ts->buffer = buffer;
ts->lookahead = 0;
ts->has_lookahead = 0;
return ts;