🐛 fix(tsl_syntax): repair lookup engine and reconcile reference facts

lookup.py: exempt code-anchored ASCII identifiers from the mixed
zh/en gate so exact hits are no longer dropped; dedup parent/child
sections in results; validate write-prelude anchors in --check.

references: correct interpreter-verified facts (case-as-expression,
control-flow semicolons, __line__/__stack_frame, tslObjects order,
destroy timing, ErrDefine, truncated outputs), fix headings, scope
qualifiers and reversed quotes; strip dead preamble metadata from all
24 pages.

packaging: exclude __pycache__/*.pyc from playbook and bundle copies;
update build test file-count assertion to match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
csh
2026-07-13 09:16:57 +08:00
co-authored by Claude Fable 5
parent 923bce91b0
commit b597edfc70
29 changed files with 356 additions and 256 deletions
@@ -1,17 +1,12 @@
# TSL 对象与类
文档类型:语法主线
是否可直接用于生成代码:仅部分
是否含可直接照写示例:是
是否含不可照写反例:是
这一篇收拢面向对象语法,只保留语言层规则。
## 本篇职责
回答“`type Name = class`、字段、`static`、方法、`property`、析构、类类型、继承和对象创建在 TSL 里怎样写”。
本页后半段有少量依赖 `unit` 的双文件示例;如果你还没建立 `unit` / `uses` 的多文件心智模型,先看 [09_units_and_scope.md](09_units_and_scope.md)。
本页后半段有少量依赖 `unit` 的双文件示例;`unit` / `uses` 的多文件模型事实见 [09_units_and_scope.md](09_units_and_scope.md)。
## 智能体对象/类判断流程
@@ -43,7 +38,7 @@
- 基础 `property` 形态:`property Name read fieldOrMethod write fieldOrMethod`
- `property Name: Type ...` 这种类型注解写法可用。
- 参数化 `property` 可用;本页只写基础模式。
- 参数化 `property` 的 accessor 方法记录两种常见模式:读方法接同参数个数写方法接“参数个数 + 赋值值”。
- 参数化 `property` 的 accessor 方法记录两种常见模式:读方法接同参数个数(如 `getItem(i)`),也可以写成无参形态(如 `getDateV()`);写方法接“参数个数 + 赋值值”。
- 索引型 `property` 可用;调用时用圆括号 `obj.Prop(index)`
- 固定 `index` property 可用;它可以把某个固定索引直接映射成普通属性读写。
- `class(Name)``findClass("Name")` 都可以拿到类类型。
@@ -57,7 +52,7 @@
- 创建对象有两种方式:`new ClassName()` 最常用,`createObject(...)` 作为次选。
- 普通本地类实例化默认生成 `new ClassName()``createObject("ClassName")``createObject(ClassType)` 只在字符串类名、类类型变量或跨 `unit` 路径场景生成。
- 如果类里定义了 `function create(...)``new``createObject("ClassName", ...)``createObject(ClassType, ...)` 都可以透传构造参数,也都支持默认参数和命名参数。
- 析构写法是无参 `function destroy();`对象引用设为 `nil` 时会触发它。
- 析构写法是无参 `function destroy();`;对象的最后一个引用被清空(如设为 `nil`时会触发它。存在别名引用时,只清空其中一个引用不会触发。
- 工厂式 `self(0)` / `self(1)` 可用;不要生成 `self()` 这种无参工厂式写法。
-`unit` 类路径创建和继承属于多文件边界;相关事实见 [09_units_and_scope.md](09_units_and_scope.md) 和 [19_namespace_libpath_and_unit_runtime.md](19_namespace_libpath_and_unit_runtime.md),不要从普通单文件 `new` / `createObject` 规则直接泛化。
- `{$ifdef parentClassInUnit}` 为真,可用于探测“继承和构造单元中的类”能力是否可用。
@@ -750,8 +745,8 @@ end;
输出说明:
- `read getItem` 这种读方法接同参数个数”的写法可以通过
- `write setItem` 这种写方法接参数个数 + 赋值值”的写法可以通过
- `read getItem` 这种读方法接同参数个数”的写法可以通过
- `write setItem` 这种写方法接参数个数 + 赋值值”的写法可以通过
- 上述例子中的 `obj.Item(2)` 输出 `x`
### 对象创建与类类型
@@ -904,7 +899,7 @@ end;
- `findClass("MathBox").Add(...)` 可以调用类方法
- 上述例子依次输出 `7``11`
### 类方法、重载、继承与析构
### 重载、继承与析构
`overload` 方法: