feat(tsl-syntax-reference): harden retrieval contracts

Add stable section IDs, structural and routing regressions, quickstart consistency checks, and CI enforcement.

BREAKING CHANGE: replace heading-derived Section IDs with explicit syntax-NN-NNN identifiers.
This commit is contained in:
csh
2026-07-31 10:05:15 +08:00
parent 21e688a436
commit 736d1a8ad7
30 changed files with 1635 additions and 137 deletions
@@ -4,10 +4,14 @@
## 本篇职责
<!-- section-id: syntax-23-001 -->
回答“当类不只是普通对象,而要直接参与 `obj + x``obj[index]``for v in obj``mrows(obj)` 这类语言级操作时,支持哪些文档明确写法”。
## 核心规则
<!-- section-id: syntax-23-002 -->
- 对象二元算符重载的最小可靠形态是成员方法 `function operator + (other);` 这一类写法。
- 比较算符可写成 `function operator < (other, is_left);`,用 `is_left` 区分对象在左边还是右边。
- 对象 `[]` 读取有两种文档明确写法:`function operator[](index);``function operator[0](index, s1);`
@@ -21,8 +25,12 @@
## 可直接照写示例
<!-- section-id: syntax-23-003 -->
### 二元算符重载
<!-- section-id: syntax-23-004 -->
<!-- tags: 让对象支持加号, 自定义加减, 对象相加, 运算符重载 -->
代码块身份:可直接照写示例
@@ -92,6 +100,8 @@ end;
### `[]` 重载:`operator[]` / `operator[1]`
<!-- section-id: syntax-23-005 -->
<!-- tags: 中括号取值, 方括号访问, 对象当数组用, 下标读写 -->
代码块身份:可直接照写示例
@@ -128,6 +138,8 @@ end;
### `[]` 重载:`operator[0]` / `operator[1]`
<!-- section-id: syntax-23-006 -->
<!-- tags: 中括号读写分离, 取值和赋值签名 -->
读取签名也可以写成 `function operator[0](index, s1);`(与上一段 `operator[]` 等价的另一组写法):
@@ -166,6 +178,8 @@ end;
### `for in` 重载
<!-- section-id: syntax-23-007 -->
<!-- tags: 让对象可遍历, 自定义迭代, 支持 for in -->
代码块身份:可直接照写示例
@@ -218,6 +232,8 @@ end;
### `mrows` / `mcols` / `msize` 重载(带参形态,支持下标列表)
<!-- section-id: syntax-23-008 -->
<!-- tags: 对象当矩阵, 自定义行列数, 带下标查询 -->
代码块身份:可直接照写示例
@@ -276,6 +292,8 @@ end;
### `++` / `+=` / `--` / `-=` 自增自减重载
<!-- section-id: syntax-23-009 -->
<!-- tags: 自增自减, 加等于, 对象累加 -->
代码块身份:可直接照写示例
@@ -366,6 +384,8 @@ end;
### 二进制函数重载:`operator funcName`
<!-- section-id: syntax-23-010 -->
<!-- tags: 重载具名函数, 让内置函数认识我的对象 -->
除了符号算符,`operator` 还能重载具名的全局二进制函数(如 `DateToStr``TryStrToInt` 等)。定义写成 `[class] function operator funcName(...)``class` 关键字可选,加上表示类方法,不加表示成员函数。
@@ -456,6 +476,8 @@ end;
### `::` / `:.` 遍历重载与 `mcell` / `mrow` / `mcol` / `mIndexCount` / `mIndex`
<!-- section-id: syntax-23-011 -->
<!-- tags: 对象支持矩阵遍历, 自定义单元访问 -->
重载 `::`(二维遍历)或 `:.`(深度遍历)后,对象就能像矩阵一样被 `obj::begin ... end` 遍历。遍历体里用到的 `mcell` / `mrow` / `mcol` / `mIndexCount` / `mIndex(n)` 也各自重载,返回当前单元的值、行下标、列下标、维度数和第 `n` 维下标。`operator ::(flag)``flag``0` 表示第一次循环、`1` 表示后续循环,返回 `0``nil` 结束遍历、返回非零数字继续:
@@ -532,6 +554,8 @@ end;
### `mrows` / `mcols` / `msize` 重载(无参形态,只取数量且免 `::`)
<!-- section-id: syntax-23-012 -->
<!-- tags: 只取数量, 无参形态, 免遍历取行列数 -->
`msize` / `mrows` / `mcols` 这类关键字函数也能重载,形态同二进制函数重载 `[class] function operator KeyWord(...)`,但**关键字重载不需要 `::` 指定全局**
@@ -563,6 +587,8 @@ end;
## 本页不生成的范围
<!-- section-id: syntax-23-013 -->
- 多级 `[]` 下标重载
- 右侧算术如 `value + obj`
@@ -570,6 +596,8 @@ end;
## 禁止项
<!-- section-id: syntax-23-014 -->
- 不要从本页 `operator` 示例外推未写入文档的重载族。
- 重载 `::` / `:.` 遍历时,不要漏掉配套的 `mcell` / `mrow` / `mcol` / `mIndexCount` / `mIndex` 重载,否则遍历体会报 `override function not found`
- 不要把多级 `[]` 下标重载或 `value + obj` 这类右侧算术写成文档事实。