feat 重构stream流API并适配lex_parse和lexer

This commit is contained in:
zzy
2025-12-08 23:04:11 +08:00
parent 1ab07a5815
commit 36bff64a91
17 changed files with 402 additions and 244 deletions

View File

@@ -8,10 +8,10 @@ static inline void test_lexer_string(const char *input,
token_type_t expected_type) {
smcc_lexer_t lexer;
lexer_tok_t token;
core_mem_stream_t stream;
core_mem_probe_stream_t stream;
lexer_init(&lexer,
core_mem_stream_init(&stream, input, strlen(input), false));
lexer_init(&lexer, core_mem_probe_stream_init(&stream, input, strlen(input),
false));
lexer_get_token(&lexer, &token);
TEST_CHECK(token.type == expected_type);
@@ -167,4 +167,4 @@ TEST_LIST = {{"operators", test_operators},
{"literals", test_literals},
{"edge_cases", test_edge_cases},
// {"error_handling", test_error_handling},
{NULL, NULL}};
{NULL, NULL}};

View File

@@ -63,9 +63,9 @@ int main(int argc, char *argv[]) {
}
smcc_lexer_t lexer;
core_mem_stream_t mem_stream = {0};
core_stream_t *stream =
core_mem_stream_init(&mem_stream, buffer, fsize, false);
core_mem_probe_stream_t mem_stream = {0};
core_probe_stream_t *stream =
core_mem_probe_stream_init(&mem_stream, buffer, fsize, false);
Assert(stream != null);
cstring_clear(&stream->name);
cstring_push_cstr(&stream->name, file_name, strlen(file_name));
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
break;
}
LOG_DEBUG("token `%s` at %s:%u:%u", get_tok_name(tok.type),
tok.loc.name, tok.loc.line, tok.loc.col);
cstring_as_cstr(&tok.loc.name), tok.loc.line, tok.loc.col);
Assert(tok.loc.offset <= fsize);
// LOG_DEBUG("%s", tok.val.str);
// printf("line: %d, column: %d, type: %3d, typename: %s\n",