fix(pproc): 修复宏参数解析中的空白字符处理问题

- 在宏参数解析过程中使用 scc_lexer_next_non_blank 替代直接的 ring 操作,
  确保正确跳过空白字符

- 更新 scc_pproc_expand_by_src 和 rescan 函数中使用
  scc_lexer_peek_non_blank 替代原来的 scc_ring_peek,
  以正确处理预处理器展开时的空白字符

- 修正测试用例中的预期输出,移除多余的空格
This commit is contained in:
zzy
2026-03-01 16:02:04 +08:00
parent 60cdfd2c33
commit 46f5328183
3 changed files with 4 additions and 4 deletions

View File

@@ -55,10 +55,10 @@ void scc_pproc_parse_macro_arguments(scc_lexer_tok_ring_t *ring,
int ok;
do {
scc_ring_next_consume(*ring, tok, ok);
// ok = scc_lexer_next_non_blank(ring, &tok);
if (!ok) {
return;
}
// scc_lexer_next_non_blank(ring, &tok);
if (tok.type == SCC_TOK_R_PAREN) {
depth--;
}

View File

@@ -109,7 +109,7 @@ void scc_pproc_expand_by_src(scc_pproc_macro_table_t *macro_table,
scc_pproc_parse_macro_arguments(input, &expaned_buffer, true);
}
while (1) {
scc_ring_peek(*input, tok, ok);
ok = scc_lexer_peek_non_blank(input, &tok);
if (ok == false) {
break;
}
@@ -288,7 +288,7 @@ static void rescan(scc_pproc_expand_t *expand_ctx,
int ok = false;
scc_lexer_tok_t tok;
scc_ring_peek(*expand_ctx->input, tok, ok);
ok = scc_lexer_peek_non_blank(expand_ctx->input, &tok);
if (ok && tok.type == SCC_TOK_L_PAREN) {
scc_lexer_tok_vec_t expaned_buffer;
scc_vec_init(expaned_buffer);

View File

@@ -568,7 +568,7 @@ static void test_c99_docs(void) {
"\t\t\tt(10,,), t(,11,), t(,,12), t(,,) };\n",
"int j[] = { 123, 45, 67, 89,\n"
"\t\t\t10, 11, 12, };\n");
"\t\t\t10, 11, 12, };\n");
TEST_CASE("EXAMPLE 6 To demonstrate the redefinition rules, the following "
"sequence is valid.");