fix(ast/parser): extern 无 body 形式消费本行 NewLine,修复 Phase1a-pre 7 文件扫描失败

extern def A(...) -> T(无 ': pass')解析完返回时 cur 停在 NewLine token,
模块级/类体语句循环只 _skip_nl(Nl)不跳 NewLine,下一轮把 NewLine 当
表达式解析(_parse_atom error_count++)→ parse_tokens 返回 None →
Phase1a-pre 报 7 个文件扫描失败(w32 7 个 extern 文件全挂的根因)。
This commit is contained in:
TermiNexus committed 2026-08-17 11:57:01 +08:00
1 parent a641c7c8da
commit 451e7a0391
8 files changed
+211 -205

No files matched your search

+7 -1
View File
@@ -2288,7 +2288,13 @@ def _parse_funcdef(ps: Parser | t.CPtr, is_async: t.CInt) -> AST | t.CPtr:
if is_extern_fd == 0 or _match_op(ps, TokOp.Colon):
_expect_op(ps, TokOp.Colon)
_parse_suite_into_children(ps, node)
# extern 无 ': pass' 形式(extern A(...) -> int):body 为空,仅声明
else:
# extern 无 ': pass' 形式(extern A(...) -> int):body 为空,仅声明。
# 必须消费本行 NewLine:模块级/类体语句循环只 _skip_nl(Nl),
# 残留 NewLine 会被下一轮当表达式解析(_parse_atom → error_count++)
# → parse_tokens 返回 None(TPV 编译 extern 文件报 7 个扫描失败的根因)
if _cur_type(ps) == TokenType.NewLine:
_advance(ps)
_set_pos(node, lineno, col, 0, 0)
return node