refactor(lex_parser): replace core_pos_* functions with scc_pos_* equivalents

Update all position tracking calls in lex_parser.c to use the scc_pos_* function family (scc_pos_next, scc_pos_next_line) instead of the deprecated core_pos_* variants. This ensures consistency with the scc naming convention and prepares for future removal of the old core functions.
This commit is contained in:
zzy
2025-12-12 21:33:51 +08:00
parent 897ef449fb
commit 94d3f46fac
5 changed files with 27 additions and 54 deletions

View File

@@ -10,10 +10,10 @@ void lex_parse_skip_endline(scc_probe_stream_t *input, scc_pos_t *pos) {
if (ch == '\n') {
scc_probe_stream_consume(input);
}
core_pos_next_line(pos);
scc_pos_next_line(pos);
} else if (ch == '\n') {
scc_probe_stream_consume(input);
core_pos_next_line(pos);
scc_pos_next_line(pos);
} else {
LOG_WARN("not a newline character");
}
@@ -74,7 +74,7 @@ void lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos) {
return;
} else {
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
}
}
}
@@ -85,11 +85,11 @@ void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) {
int ch;
scc_probe_stream_reset(stream);
ch = scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
// FIXME Assertion
Assert(ch == '/');
ch = scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
Assert(ch == '*');
// all ready match `/*`
@@ -107,12 +107,12 @@ void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) {
continue;
}
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
if (ch == '*') {
ch = scc_probe_stream_peek(stream);
if (ch == '/') {
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
return;
}
}
@@ -131,7 +131,7 @@ void lex_parse_skip_whitespace(scc_probe_stream_t *input, scc_pos_t *pos) {
}
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
}
}
@@ -167,7 +167,7 @@ static inline cbool _lex_parse_uint(scc_probe_stream_t *input, scc_pos_t *pos,
}
scc_probe_stream_consume(input);
core_pos_next(pos);
scc_pos_next(pos);
n = n * base + tmp;
// TODO number overflow
}
@@ -202,17 +202,17 @@ int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
goto ERR;
}
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
ch = scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
if (ch == core_stream_eof) {
LOG_WARN("Unexpected EOF at middle");
goto ERR;
} else if (ch == '\\') {
ch = scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
if (ch == '0') {
// 数字转义序列
// \nnn 任意八进制值 码元 nnn
@@ -239,7 +239,7 @@ int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) {
}
if ((ch = scc_probe_stream_consume(stream)) != '\'') {
LOG_ERROR("Unclosed character literal '%c' at end, expect `'`", ch);
core_pos_next(pos);
scc_pos_next(pos);
goto ERR;
}
@@ -273,7 +273,7 @@ cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos,
goto ERR;
}
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
scc_cstring_t str = scc_cstring_from_cstr("");
while (1) {
@@ -298,12 +298,12 @@ cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos,
}
} else if (ch == '"') {
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
break;
}
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
scc_cstring_append_ch(&str, ch);
}
@@ -339,7 +339,7 @@ cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
if (ch == '0') {
// 消费 '0'
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
// 查看下一个字符
ch = scc_probe_stream_peek(stream);
@@ -347,12 +347,12 @@ cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
// 十六进制
base = 16;
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
} else if (ch == 'b' || ch == 'B') {
// 二进制 (C23扩展)
base = 2;
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
} else if (ch >= '0' && ch <= '7') {
// 八进制
base = 8;
@@ -384,7 +384,7 @@ cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos,
// 我们需要消费这个数字并返回它的值
if (ch >= '1' && ch <= '9') {
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
*output = ch - '0';
return true;
}
@@ -421,7 +421,7 @@ cbool lex_parse_identifier(scc_probe_stream_t *input, scc_pos_t *pos,
while (1) {
scc_cstring_append_ch(output, ch);
scc_probe_stream_consume(stream);
core_pos_next(pos);
scc_pos_next(pos);
ch = scc_probe_stream_peek(stream);
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch == '_') || (ch >= '0' && ch <= '9')) {

View File

@@ -105,7 +105,7 @@ static void parse_line(scc_lexer_t *lexer, lexer_tok_t *token) {
for (int i = 0; i < (int)sizeof(line); i++) {
ch = scc_probe_stream_consume(stream);
core_pos_next(&lexer->pos);
scc_pos_next(&lexer->pos);
if (ch != line[i]) {
LEX_WARN("Maroc does not support in lexer rather in preprocessor, "
"it will be ignored");
@@ -453,13 +453,13 @@ void scc_lexer_get_token(scc_lexer_t *lexer, lexer_tok_t *token) {
goto once_char;
triple_char:
scc_probe_stream_consume(stream);
core_pos_next(&lexer->pos);
scc_pos_next(&lexer->pos);
double_char:
scc_probe_stream_consume(stream);
core_pos_next(&lexer->pos);
scc_pos_next(&lexer->pos);
once_char:
scc_probe_stream_consume(stream);
core_pos_next(&lexer->pos);
scc_pos_next(&lexer->pos);
token->type = type;
END:
LEX_DEBUG("get token `%s` in %s:%d:%d", scc_get_tok_name(token->type),

View File

@@ -14,12 +14,12 @@ static inline scc_pos_t scc_pos_init() {
return (scc_pos_t){scc_cstring_new(), 1, 1, 0};
}
static inline void core_pos_next(scc_pos_t *pos) {
static inline void scc_pos_next(scc_pos_t *pos) {
pos->offset++;
pos->col++;
}
static inline void core_pos_next_line(scc_pos_t *pos) {
static inline void scc_pos_next_line(scc_pos_t *pos) {
pos->offset++;
pos->line++;
pos->col = 1;

View File

@@ -79,12 +79,6 @@ void init_logger(logger_t *logger, const char *name) {
log_set_level(logger, LOG_LEVEL_ALL);
}
logger_t *log_get(const char *name) {
// TODO for -Wunused-parameter
(void)name;
return &__default_logger_root;
}
void log_set_level(logger_t *logger, int level) {
if (logger)
logger->level = level;
@@ -98,9 +92,3 @@ void log_set_handler(logger_t *logger, log_handler handler) {
else
__default_logger_root.handler = handler;
}
void logger_destroy(logger_t *logger) {
// TODO for -Wunused-parameter
(void)logger;
return;
}

View File

@@ -96,16 +96,6 @@ extern logger_t __default_logger_root;
*/
void init_logger(logger_t *logger, const char *name);
// TODO log_set(); 暂未实现 日志注册
/**
* @brief 获取或创建日志器实例
* @param[in] name 日志器名称NULL表示获取默认日志器
* @return 日志器实例指针
* @warning 若没有找到相应日志器则会返回根日志器
*/
logger_t *log_get(const char *name);
/**
* @brief 设置日志级别
* @param[in] logger 目标日志器实例
@@ -120,11 +110,6 @@ void log_set_level(logger_t *logger, int level);
*/
void log_set_handler(logger_t *logger, log_handler handler);
/**
* @todo TODO impliment
*/
void logger_destroy(logger_t *logger);
#ifndef LOG_MAX_MAROC_BUF_SIZE
#define LOG_MAX_MAROC_BUF_SIZE LOGGER_MAX_BUF_SIZE ///< 宏展开缓冲区尺寸
#endif