Commit Graph

23 Commits

Author SHA1 Message Date
seeseemelk 26a1d0285e Refactor Token to use Location struct 2026-04-24 22:07:00 +02:00
seeseemelk a89e61eedd Introduce golden file mechanism for tests 2026-04-24 21:09:47 +02:00
seeseemelk 9ca72ef5bf Split test 2026-04-24 20:41:57 +02:00
seeseemelk 0306530fe8 Better logging in tokenstream 2026-04-24 20:40:31 +02:00
seeseemelk 451a9a2a22 Token refactor and better logs 2026-04-24 20:28:08 +02:00
seeseemelk e021a2d63e During test, log to in-memory log 2026-04-24 20:04:00 +02:00
seeseemelk 0e826e05e1 Add log framework 2026-04-24 15:14:15 +02:00
seeseemelk 0fa7b599ed Implement assert_str and assert_not_null and update tests 2026-04-24 14:57:52 +02:00
seeseemelk 594e33efd6 Add parser header 2026-04-24 14:52:53 +02:00
seeseemelk a173e37adc Implement parser module and update AST 2026-04-24 14:50:54 +02:00
seeseemelk 2d1ccd52e6 Remove buffer module as it is no longer needed 2026-04-24 14:30:25 +02:00
seeseemelk b6aaa0c08f Implement tokenstream_info and refactor TokenStream interface 2026-04-24 14:28:57 +02:00
seeseemelk 1406cedd82 Add tokeninfo 2026-04-24 11:12:44 +02:00
seeseemelk 422203fdab Remove unnecessary NULL checks from token tests
Since buffer_open_string() always succeeds and tokenstream_open() always
succeeds when given a valid buffer, the NULL checks are unnecessary.
This simplifies the test code and makes it more readable.

All 12 tests still pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 11:04:05 +02:00
seeseemelk ed12c0a38e Refactor token tests to use in-memory strings instead of files
- Replaced all write_test_file() calls with buffer_open_string()
- Removed file I/O overhead - tests now run entirely in memory
- Removed unnecessary #include <stdio.h>, <stdlib.h>, <string.h> from test_token.c
- Simplified test_tokenstream_open_fail() to directly test NULL buffer handling
- Tests are faster and cleaner without temporary file creation
- No test output changes - all 12 tests still pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 11:03:14 +02:00
seeseemelk 49b9db5b75 Refactor token mapping: use keyword map for tokenization instead of strcmp
- Created KeywordMap structure with keyword-to-token mapping at top of token.c
- Added lookup_keyword() function to check if identifier is a keyword
- Replaced 3 strcmp calls (lines 99-101) with single lookup_keyword() call
- Removed token_to_string() function and its tests (3 tests removed)
- Single easy-to-read and modify keyword map serves both documentation and implementation
- Added new keywords by editing the keywords[] array at top of token.c

All 12 tests passing (removed token_to_string tests which are now unnecessary).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 09:44:19 +02:00
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
seeseemelk dccdcb8ba5 Implement token.c with comprehensive tests and easy-to-modify token mapping
- Created token-to-string mapping array parallel to Token enum in token.c
- Implemented TokenStream with lookahead buffering for proper tokenization
- Implemented tokenstream_open/close/next functions with support for:
  - Keywords (module, import, void)
  - Symbols (parentheses, brackets, comma, semicolon)
  - Identifiers (alphanumeric starting with letter or underscore)
  - Comment skipping (// style)
  - Whitespace handling
- Added token_to_string function to token.h for token inspection
- Created comprehensive test suite (15 tests) covering all token types and edge cases
- All tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 09:35:18 +02:00
seeseemelk c73f99d9e6 Project setup 2026-04-24 09:29:53 +02:00
seeseemelk c90f3afd95 Implement all @copilot Makefile and buffer test annotations
- Defined V0_SRC_DEPS and V0_TEST_DEPS in v0/include.mk
- Updated clean rule to remove dependency files
- Referenced dependency variables for .d includes
- Added and deduplicated file-read test in v0/test_buffer.c

All tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 09:25:04 +02:00
seeseemelk 4939a74752 Update test paths after flattening v0 layout
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 08:20:54 +02:00
seeseemelk 7ff3f76de5 Implement buffer interface and tests
- Implement buffer_open_file/string, buffer_read, buffer_close in v0/src/buffer.c

- Add tests in v0/tests/test_buffer.c and test_buffer.txt; register tests in v0/tests/test.c

- Update v0/include.mk and Makefile

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 08:07:38 +02:00
seeseemelk f6a1b290fc Initial commit 2026-04-24 07:24:03 +02:00