feat(parser): 支持 Viper 软关键字 fn/fun/func/function 展开为 def
行首缩进+软关键字+空白+标识符形态的函数定义(fn foo(): / function bar()) 展开为 def,行号不变,供 ast.parse 使用;变量名/调用/注解中的 fn 不受影响。 Converter 同步改为 stub 语法错误直接终止(fail-fast),不再生成残缺 vpi 被全局缓存命中后以 undefined symbol 形式爆发。
This commit is contained in:
1 parent
6a672037c2
commit
a99f126cfa
6 files changed
+48
-11
No files matched your search
@@ -6,7 +6,7 @@ import ast
|
||||
|
||||
from lib.core.VLogger import get_logger as _vlog
|
||||
from lib.constants.config import mode as _ConfigMode
|
||||
from lib.core.SymbolUtils import AnnotationContainsName
|
||||
from lib.core.SymbolUtils import AnnotationContainsName, ExpandSoftKeywords
|
||||
|
||||
|
||||
def compute_sha1(content: str) -> str:
|
||||
@@ -59,7 +59,10 @@ def parse_python_file(filepath: str) -> tuple[str, ast.Module] | tuple[str, None
|
||||
except Exception:
|
||||
return ('', None)
|
||||
try:
|
||||
tree: ast.Module = ast.parse(content)
|
||||
# 软关键字展开:fn/fun/func/function -> def(行号不变),供 ast.parse 使用。
|
||||
# 注意 content 保持原始文本返回(compute_sha1 必须与 Phase1 一致),
|
||||
# 仅 tree 基于展开后的代码解析。
|
||||
tree: ast.Module = ast.parse(ExpandSoftKeywords(content))
|
||||
except SyntaxError:
|
||||
return (content, None)
|
||||
_FILE_AST_CACHE[filepath] = (mtime, content, tree)
|
||||
|
||||
Reference in new issue
Block a user