✨ feat(tsl-syntax-reference): harden retrieval and restructure pages
- flag weak candidates (no intent/heading/identifier/tag hit) and exit 2 when every candidate is weak: mis-hits used to be indistinguishable from real hits, so the retry-with-better-terms loop never fired - accept multiple ids per --section for batch fetch, failing atomically on any unknown id so a partial fetch cannot pass as complete - move query synonyms and page intent aliases to data/lexicon.json and enforce alias/page correspondence in --check; curation data no longer lives in the engine - document the weak-hit rule, batch fetch and prelude-once guidance in SKILL.md, with curation discipline in data/README.md - drop 11_pitfalls.md, renumber the trailing pages and spread retrieval tags across topics; lexicon keys are page filenames, so the renumbering and the new --check rule cannot land in separate commits
This commit is contained in:
@@ -6,20 +6,6 @@
|
||||
|
||||
回答“`type Name = class`、字段、`static`、方法、`property`、析构、类类型、继承和对象创建在 TSL 里怎样写”。
|
||||
|
||||
本页后半段有少量依赖 `unit` 的双文件示例;`unit` / `uses` 的多文件模型事实见 [09_units_and_scope.md](09_units_and_scope.md)。
|
||||
|
||||
## 智能体对象/类判断流程
|
||||
|
||||
1. 先判断要写普通对象、继承、构造函数、类方法、静态字段还是运行时创建。
|
||||
2. 对象声明优先使用本页明确的 `type Name = class ... end;` 骨架。
|
||||
3. 普通本地类创建默认用 `new ClassName()`;只有需要字符串类名、类类型变量或跨 `unit` 路径时,才用 `createObject(...)`。
|
||||
4. 类方法和静态字段优先用 `class(Name).Member` 或文档明确反射入口,不要裸写类名调用。
|
||||
5. 构造函数默认保持 `public create`,不要把 `private` / `protected create` 当成会自动执行的构造函数。
|
||||
6. 普通类成员默认显式写 `public` 段,不依赖隐式 public。
|
||||
7. 方法体内访问当前实例成员默认直接写成员名;成员读写为了性能不加 `self` 前缀。
|
||||
8. 对象反射 / 运行时状态、内置运行时对象、对象重载 / 迭代的事实分别见 [20_object_runtime_and_introspection.md](20_object_runtime_and_introspection.md)、[21_builtin_runtime_objects.md](21_builtin_runtime_objects.md)、[24_object_overloads_and_iteration.md](24_object_overloads_and_iteration.md)。
|
||||
9. 没有文档事实时不要发明对象/类写法。
|
||||
|
||||
## 核心规则
|
||||
|
||||
- 类定义统一按 `type Name = class ... end;` 写。
|
||||
@@ -54,7 +40,7 @@
|
||||
- 如果类里定义了 `function create(...)`,`new`、`createObject("ClassName", ...)` 和 `createObject(ClassType, ...)` 都可以透传构造参数,也都支持默认参数和命名参数。
|
||||
- 析构写法是无参 `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` 规则直接泛化。
|
||||
- 跨 `unit` 类路径创建和继承属于多文件边界;相关事实见 [09_units_and_scope.md](09_units_and_scope.md) 和 [18_namespace_libpath_and_unit_runtime.md](18_namespace_libpath_and_unit_runtime.md),不要从普通单文件 `new` / `createObject` 规则直接泛化。
|
||||
- `{$ifdef parentClassInUnit}` 为真,可用于探测“继承和构造单元中的类”能力是否可用。
|
||||
- `private` / `protected` / `public` 可用;类开头未写可见性时,成员默认按 `public` 处理,但生成代码默认显式写 `public`。
|
||||
- 同一个可见性段里后续没有切换关键字的成员,会沿用前一个可见性。
|
||||
@@ -73,6 +59,8 @@
|
||||
|
||||
### 最小类与声明位置
|
||||
|
||||
<!-- tags: 定义一个类, 类怎么写, 最短类, 类放在哪, 类骨架 -->
|
||||
|
||||
最短类骨架:
|
||||
|
||||
如果任务只是要“先写出一个类”,先从这个骨架起手;后面的例子再逐步进入字段、工厂函数和声明位置边界。
|
||||
@@ -181,6 +169,8 @@ writeLn(a);
|
||||
|
||||
### 字段、静态成员、常量与可见性
|
||||
|
||||
<!-- tags: 成员变量, 静态成员, 类常量, 私有公开, 属性可见性, 只有类自己能访问 -->
|
||||
|
||||
`static` 字段:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -393,6 +383,8 @@ end;
|
||||
|
||||
### 构造函数边界
|
||||
|
||||
<!-- tags: 构造方法, 新建时初始化, create 怎么写, 带参数创建 -->
|
||||
|
||||
`create` 建议保持 `public`:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -420,6 +412,8 @@ end;
|
||||
|
||||
### 属性、类型注解与类外实现
|
||||
|
||||
<!-- tags: property, 读写属性, getter setter, 方法写在类外 -->
|
||||
|
||||
基础 `property`:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -751,6 +745,8 @@ end;
|
||||
|
||||
### 对象创建与类类型
|
||||
|
||||
<!-- tags: 创建对象, 实例化, new 怎么用, 拿到类本身, 动态建对象 -->
|
||||
|
||||
`new` 关键字:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -901,6 +897,8 @@ end;
|
||||
|
||||
### 重载、继承与析构
|
||||
|
||||
<!-- tags: 继承, 父类子类, 方法重载, 同名不同参, 析构, 对象销毁时 -->
|
||||
|
||||
`overload` 方法:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -1304,6 +1302,8 @@ end;
|
||||
|
||||
### 跨 unit 类路径
|
||||
|
||||
<!-- tags: 跨文件的类, 跨文件继承, 类的完整路径 -->
|
||||
|
||||
`unit` 中的嵌套类路径创建属于跨 `unit` 边界,这里用 `text` 展示骨架:
|
||||
|
||||
代码块身份:配置片段 / 概念骨架
|
||||
@@ -1338,7 +1338,7 @@ writeLn(obj.value);
|
||||
输出说明:
|
||||
|
||||
- 这个骨架只说明字符串路径创建需要按跨 `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)。
|
||||
- 生成实际代码所需的多文件事实见 [09_units_and_scope.md](09_units_and_scope.md) 和 [18_namespace_libpath_and_unit_runtime.md](18_namespace_libpath_and_unit_runtime.md)。
|
||||
- 不要把它直接改写成普通本地类的 `new ClassName()` 模式。
|
||||
|
||||
继承单元中的嵌套类路径属于跨 `unit` 边界,这里也用 `text` 展示骨架:
|
||||
|
||||
Reference in New Issue
Block a user