feat(core): 重构词法分析器流接口并迁移至 core 库
将 lexer_stream 抽象为 core_stream,统一运行时核心组件的输入流模型。 移除了旧的 `lexer_stream.h` 定义,并将其功能完整迁移至 `core_stream.h` 中。 更新了内存流实现以适配新的 core_stream 接口,并修复部分资源释放问题。 同时调整日志模块包含方式,增强模块间解耦能力。 此变更影响词法分析器对输入流的操作方式,所有涉及 stream 的类型与函数均已替换为 core 前缀版本。 测试用例同步更新并验证通过。
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#define __SMCC_CC_LEXER_H__
|
||||
|
||||
#include <libcore.h>
|
||||
#include "lexer_stream.h"
|
||||
#include "lexer_token.h"
|
||||
|
||||
typedef struct lexer_loc {
|
||||
@@ -30,7 +29,7 @@ typedef struct lexer_token {
|
||||
* 封装词法分析所需的状态信息和缓冲区管理
|
||||
*/
|
||||
typedef struct cc_lexer {
|
||||
lexer_stream_t* stream;
|
||||
core_stream_t* stream;
|
||||
lexer_loc_t pos;
|
||||
} smcc_lexer_t;
|
||||
|
||||
@@ -39,7 +38,7 @@ typedef struct cc_lexer {
|
||||
* @param[out] lexer 要初始化的词法分析器实例
|
||||
* @param[in] stream 输入流对象指针
|
||||
*/
|
||||
void lexer_init(smcc_lexer_t* lexer, lexer_stream_t* stream);
|
||||
void lexer_init(smcc_lexer_t* lexer, core_stream_t* stream);
|
||||
|
||||
/**
|
||||
* @brief 获取原始token
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include <core_type.h>
|
||||
|
||||
typedef struct lexer_stream lexer_stream_t;
|
||||
|
||||
#define lexer_stream_eof (-1)
|
||||
|
||||
struct lexer_stream {
|
||||
const char* name;
|
||||
usize name_len;
|
||||
|
||||
/// @brief 读取指定数量的字符到缓冲区
|
||||
usize (*read_buf)(lexer_stream_t* stream, char* buffer, usize count);
|
||||
|
||||
/// @brief 获取下一个字符
|
||||
int (*peek_char)(lexer_stream_t* stream);
|
||||
|
||||
/// @brief 重置字符流位置
|
||||
void (*reset_char) (lexer_stream_t* stream);
|
||||
|
||||
/// @brief 读取并消费下一个字符(移动流位置)
|
||||
int (*next_char)(lexer_stream_t* stream);
|
||||
|
||||
/// @brief 释放资源
|
||||
void (*free_stream) (lexer_stream_t* steam);
|
||||
};
|
||||
|
||||
#ifndef __SMCC_LEXER_NO_MEM_STREAM__
|
||||
typedef struct lexer_mem_stream {
|
||||
lexer_stream_t stream;
|
||||
const char* data;
|
||||
usize data_length;
|
||||
usize curr_pos;
|
||||
usize peek_pos;
|
||||
cbool owned;
|
||||
} lexer_mem_stream_t;
|
||||
lexer_stream_t* lexer_mem_stream_init(lexer_mem_stream_t* stream, const char* data, usize length, cbool need_copy);
|
||||
#endif
|
||||
Reference in New Issue
Block a user