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
@@ -20,6 +20,7 @@ from lib.utils.helpers import (
|
||||
DetectFileType, ExecuteCommand,
|
||||
AppendFileContent
|
||||
)
|
||||
from lib.core.SymbolUtils import ExpandSoftKeywords
|
||||
from lib.core.VLogger import info, warning, error, success, debug
|
||||
from lib.core.translator import Translator
|
||||
from lib.core.Handles.HandlesBase import CTypeInfo
|
||||
@@ -96,6 +97,7 @@ class TransPyC:
|
||||
|
||||
if FileType == 'py':
|
||||
# Python文件处理
|
||||
content = ExpandSoftKeywords(content)
|
||||
translator.OriginalLines = content.split('\n')
|
||||
translator.Content = content
|
||||
|
||||
@@ -416,6 +418,9 @@ class TransPyC:
|
||||
with open(InputFile, 'r', encoding=encoding) as F:
|
||||
Content: str = F.read()
|
||||
|
||||
# 软关键字展开:fn/fun/func/function -> def,供 ast.parse 使用
|
||||
Content = ExpandSoftKeywords(Content)
|
||||
|
||||
# 保存原始代码行
|
||||
self.translator.OriginalLines = Content.split('\n')
|
||||
self.translator.Content = Content
|
||||
@@ -490,6 +495,9 @@ class TransPyC:
|
||||
error('未提供代码')
|
||||
return None
|
||||
|
||||
# 软关键字展开:fn/fun/func/function -> def,供 ast.parse 使用
|
||||
self.code = ExpandSoftKeywords(self.code)
|
||||
|
||||
from lib.core.Handles.HandlesImports import ImportHandle
|
||||
ImportHandle._struct_Load_cache.clear()
|
||||
|
||||
|
||||
Reference in new issue
Block a user