🐛 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,10 +1,5 @@
# TSL 对象重载与迭代
文档类型:语法深水专题
是否可直接用于生成代码:仅部分
是否含可直接照写示例:是
是否含不可照写反例:否
这一篇只讲对象直接参与语言级操作的文档能力:基础算符重载、`[]` 重载、`for in` 重载,以及 `mrows` / `mcols` / `msize` 这类矩阵关键字重载。
## 本篇职责
@@ -90,7 +85,7 @@ end;
- 依次输出 `20``0``1``1`
- 说明 `obj + value` 可以通过成员 `operator +` 接管
- 说明带 `is_left` 的比较算符可以同时处理 `obj < value``value < obj`
- 私有成员用尾随下划线的 `real_part_` / `imaginary_part_`,对外`PascalCase` property 暴露
- 本例私有成员 `real_part_` / `imaginary_part_`,对外通过 property 暴露(命名风格本身不属于本页事实)
代码块身份:输出片段
@@ -137,18 +132,32 @@ end;
### `[]` 重载:`operator[0]` / `operator[1]`
沿用上一段的 `bb` 类与测试主体,只把读取签名从 `function operator[](index);` 改成 `function operator[0](index, s1);`
读取签名也可以写成 `function operator[0](index, s1);`(与上一段 `operator[]` 等价的另一组写法)
代码块身份:配置片段 / 概念骨架
代码块身份:可直接照写示例
```tsl
t := array(1, 2, 3, 4, 5);
b := new IndexableBox(t);
writeLn(b[2]);
b[3] := 999;
writeLn(b.data[3]);
type IndexableBox = class
public
// 其余字段、create()、operator[1] 和测试主体同上一段
data;
function create(v);
begin
data := v;
end;
function operator[0](index, s1);
begin
return data[index];
end;
function operator[1](index, v);
begin
data[index] := v;
end;
end;
```
@@ -207,7 +216,7 @@ end;
- 说明 `operator for(flag)` 可以重载 `for in`
- 也说明同一个对象可以按返回值形态同时支持“单变量遍历”和“索引 + 值遍历”
### `mrows` / `mcols` / `msize` 重载
### `mrows` / `mcols` / `msize` 重载(带参形态,支持下标列表)
代码块身份:可直接照写示例
@@ -263,7 +272,7 @@ end;
- 说明 `mrows(obj)``mcols(obj)``msize(obj)` 都可由对象重载接管
- 说明对象方法式调用 `obj.mcols(1)` 也可继续取得列下标列表
### `++` `+=`
### `++` / `+=` / `--` / `-=` 自增自减重载
代码块身份:可直接照写示例
@@ -306,8 +315,8 @@ end;
结果说明:
- 依次输出 `11``11``12``17`
- 说明前置 `++` 会直接修改对象状态
- 说明这个最小样例里,后置 `counter++` 返回的是递增前快照
- 前置 `++counter``v``0` 分支,直接原地修改对象状态
- 后置 `counter++` `v = 0` 分支:分支构造并返回递增后的新对象,运行时用它更新 `counter` 本身,而后置表达式的取值是递增前的原对象(所以 `c.data``11``counter.data``12`
- 说明 `operator += (v)` 可以接管 `counter += 5`
`--``-=` 与之对称:
@@ -349,7 +358,7 @@ end;
- 输出 `7`
- 说明 `operator -= (v)` 可以接管 `counter -= 3`
- `operator--(v)``operator++(v)` 结构对称:`v = 0` 分支返回递减前快照,否则原地递减
- `operator--(v)``operator++(v)` 结构对称:`v = 0`(后置)分支构造并返回递减后的新对象供运行时更新变量本身,后置表达式的取值是递减前的原对象;`v``0`(前置)时原地递减
### 二进制函数重载:`operator funcName`
@@ -435,7 +444,8 @@ end;
结果说明:
- 输出 `array(1,314)``ret``1`(转换成功),出参 `msg``314`
- 说明类内需要调用被重载的同名全局函数时,用 `::` 前缀指定全局版本,否则会递归回自己
- 重载的分派按实参类型决定:本类对象走重载版本,非对象实参(如 `value` 是字符串)走全局版本
- 因此当被重载的实参已经不是本类对象(如上面 `DateToStr` 两例把对象拆成基础类型再调用)时,不加 `::` 也不会递归;只有当传给同名函数的实参仍是本类对象时才会递归回自己,这时用 `::` 前缀强制指定全局版本
- 重载函数支持通过参数传出返回值(`msg` 作为出参被赋值)
### `::` / `:.` 遍历重载与 `mcell` / `mrow` / `mcol` / `mIndexCount` / `mIndex`
@@ -512,7 +522,7 @@ end;
- `:.`(深度遍历)重载方式与 `::` 相同,把内部 `data::begin ... end` 换成 `data:.begin ... end` 即可
- 遍历体里用到的 `mcell` / `mrow` / `mcol` / `mIndexCount` / `mIndex` 必须各自重载,否则报 `override function not found`
### 关键字函数重载:`msize` / `mrows` / `mcols`
### `mrows` / `mcols` / `msize` 重载(无参形态,只取数量且免 `::`)
`msize` / `mrows` / `mcols` 这类关键字函数也能重载,形态同二进制函数重载 `[class] function operator KeyWord(...)`,但**关键字重载不需要 `::` 指定全局**