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>
This commit is contained in:
@@ -28,9 +28,6 @@ static TestCase s_tests[] = {
|
||||
{"buffer_string_eof_after_content", test_buffer_string_eof_after_content},
|
||||
{"buffer_file_reads_chars", test_buffer_file_reads_chars},
|
||||
{"buffer_file_open_fail", test_buffer_file_open_fail},
|
||||
{"token_to_string_keywords", test_token_to_string_keywords},
|
||||
{"token_to_string_symbols", test_token_to_string_symbols},
|
||||
{"token_to_string_identifier", test_token_to_string_identifier},
|
||||
{"tokenstream_open_fail", test_tokenstream_open_fail},
|
||||
{"tokenstream_simple_keyword", test_tokenstream_simple_keyword},
|
||||
{"tokenstream_keywords_and_symbols", test_tokenstream_keywords_and_symbols},
|
||||
|
||||
Reference in New Issue
Block a user