✨ 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,30 +6,14 @@
|
||||
|
||||
回答“赋值、算术、比较、逻辑、位运算、集合/类型关系、条件求值、表达式对象、访问/调用、点前缀运算符和专题运算符入口在 TSL 里怎样写”。
|
||||
|
||||
## 智能体表达式/运算符判断流程
|
||||
|
||||
1. 先判断要写基础表达式运算符,还是集合、矩阵、对象重载、运行时调用或 TS-SQL 这类专题运算符。
|
||||
2. 普通变量赋值只能用 `:=`,不要把 `=` 当赋值写法;`const name = value;` 是常量初始化规则,相关事实见 [04_variables_and_constants.md](04_variables_and_constants.md)。
|
||||
3. 在普通表达式里,比较才用 `=`,并且把比较表达式放在 `writeLn(...)`、条件或其他需要布尔值的位置。
|
||||
4. 函数签名里的默认参数 `name = value` 不是比较表达式;默认参数规则见 [05_functions_and_calls.md](05_functions_and_calls.md)。
|
||||
5. 普通算术优先使用 `+`、`-`、`*`、`/`、`%`;左除用 `\`;整数除法和取模可用 `div`、`mod`;幂运算用 `^`;对数用 `~`;一元倒数用 `!x`。
|
||||
6. 逻辑表达式优先使用 `and`、`or`、`not`;`&&`、`||`、`.&&`、`.||`、`.!!` 也已可用,但默认不作为主写法;不要把 `!` 写成逻辑非。
|
||||
7. 位运算使用点前缀或移位关键字:`.&`、`.|`、`.!`、`.^`、`shl`、`shr`、`rol`、`ror`;普通 `&`、`|`、`~` 不按位运算理解。
|
||||
8. 已有变量做原地更新时,才使用 `+=`、`-=`、`*=`、`/=`、`\=`、`%=`、`^=`、`~=`、`div=`、`.&=`、`.|=`、`.^=`、`.&&=`、`.||=`、`a++;`、`a--;`、`++a;`、`--a;`。
|
||||
9. 条件求值优先用 `flag ? true_value : false_value`;需要保留条件自身真值时可用 `value ?: fallback_value`;需要 Pascal 风格时可用 `if condition then true_value else false_value` 的形态,但必须带 `else`。
|
||||
10. 需要延迟求值或动态表达式对象时,才使用 `@expr` 或 `&"..."`,并用本页明确的 `eval(...)` 形态求值。
|
||||
11. 空安全访问只照本页文档明确形态写:`a?.member`、`a?.[index]`、以及 `c?.a?.[1]`。不要外推成任意深度、任意组合都可写。
|
||||
12. 需要连续比较时,标量用 `:<` / `:>` 这组链式比较;数组逐元素比较用 `::<` / `::>` 这组矩阵链式比较。
|
||||
13. 集合、矩阵、过滤、对象重载、函数值调用、网格调用、运行时后缀和 TS-SQL 的事实所有者由“专题运算符入口表”列出。
|
||||
14. `{$ifdef ...}` 只作为能力探测;编译选项边界见 [16_lexical_structure_and_compile_options.md](16_lexical_structure_and_compile_options.md)。
|
||||
15. 任务需要的运算符没有文档事实时,不要生成猜测写法;只能使用对应专题事实、项目自身文档或项目专属规则,仍无结论时记录文档缺口。
|
||||
|
||||
## 核心规则
|
||||
|
||||
- 本页是 TSL 表达式与运算符的生成规则页;写代码时只使用本页或对应专题页明确记录的运算符和表达式形态。
|
||||
|
||||
### 本页直接生成的运算符
|
||||
|
||||
<!-- tags: 运算符一览, 位运算, 逻辑运算, 算术运算, 比较运算, 移位, 按位与或 -->
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
| 类别 | 运算符 / 形态 | 生成规则 |
|
||||
| --- | --- | --- |
|
||||
@@ -39,13 +23,13 @@
|
||||
| 函数默认参数 | `name = value` | 这是函数签名规则,不按比较表达式处理。 |
|
||||
| 算术复合赋值 | `+=`、`-=`、`*=`、`/=`、`\=`、`%=`、`^=`、`~=`、`div=` | 已有变量需要原地更新时使用;`div=` 是整除复合赋值。 |
|
||||
| 点前缀复合赋值 | `.&=`、`.|=`、`.^=`、`.&&=`、`.||=` | 位运算或点前缀逻辑需要原地更新时使用。 |
|
||||
| 自增 / 自减 | `a++`、`a--`、`++a`、`--a` | 普通数字变量可直接用;对象重载语义见 [24_object_overloads_and_iteration.md](24_object_overloads_and_iteration.md)。 |
|
||||
| 自增 / 自减 | `a++`、`a--`、`++a`、`--a` | 普通数字变量可直接用;对象重载语义见 [23_object_overloads_and_iteration.md](23_object_overloads_and_iteration.md)。 |
|
||||
| 算术 | `+`、`-`、`*`、`/`、`\`、`%`、`div`、`mod`、`^`、`~` | 普通数值计算使用;`\` 是左除,`^` 是幂运算,`~` 是对数运算。 |
|
||||
| 一元正负号 | `+x`、`-x` | 可直接用于数值表达式。 |
|
||||
| 一元倒数 | `!x` | 整型、实型输入返回实型倒数;矩阵逆/广义逆见 [22_matrix_deep_dive.md](22_matrix_deep_dive.md)。 |
|
||||
| 一元倒数 | `!x` | 整型、实型输入返回实型倒数;矩阵逆/广义逆见 [21_matrix_deep_dive.md](21_matrix_deep_dive.md)。 |
|
||||
| 字符串连接 | `+`、`$` | 字符串拼接两种写法都已写入文档;默认优先用 `+`。 |
|
||||
| 比较 | `=`、`<>`、`<`、`>`、`<=`、`>=` | `=` 只作比较,不作普通赋值。 |
|
||||
| 点前缀比较 | `.=`、`.<>`、`.<`、`.>`、`.<=`、`.>=` | 标量比较可用;数组/矩阵样数据上的逐元素语义见 [12_matrix_and_collections.md](12_matrix_and_collections.md)。 |
|
||||
| 点前缀比较 | `.=`、`.<>`、`.<`、`.>`、`.<=`、`.>=` | 标量比较可用;数组/矩阵样数据上的逐元素语义见 [11_matrix_and_collections.md](11_matrix_and_collections.md)。 |
|
||||
| 逻辑 | `and`、`or`、`not`、`&&`、`||`、`.&&`、`.||`、`.!!` | 默认优先写 `and` / `or` / `not`;不要用 `!` 表示逻辑非。 |
|
||||
| 位运算 | `.&`、`.|`、`.!`、`.^`、`shl`、`shr`、`rol`、`ror` | 生成代码时写成点前缀或关键字形态;普通 `&`、`|`、`~` 不作为位运算写法。 |
|
||||
| 成员 / 下标 / 调用 | `obj.member`、`value[index]`、`Func(args)` | 普通访问和调用可直接使用;类、对象、函数细节回对应专题。 |
|
||||
@@ -55,27 +39,29 @@
|
||||
| Pascal 风格条件表达式 | `if condition then true_value else false_value` | 必须带 `else`。 |
|
||||
| 表达式对象 | `@expr`、`&"..."` | 需要延迟求值或动态表达式对象时使用,并用 `eval(...)` 求值。 |
|
||||
| 逗号表达式 | `(exp1, exp2, ..., expN)` | 从左到右求值,返回最后一个表达式结果。 |
|
||||
| 集合 / 匹配 / 类型关系 | `in`、`sqlin`、`like`、`is` | 否定形态见下一行;集合运算见 [12_matrix_and_collections.md](12_matrix_and_collections.md)。 |
|
||||
| 集合 / 匹配 / 类型关系 | `in`、`sqlin`、`like`、`is` | 否定形态见下一行;集合运算见 [11_matrix_and_collections.md](11_matrix_and_collections.md)。 |
|
||||
| 否定关系 | `not in`、`not sqlin`、`not like`、`not is` | 直接使用这几种文档明确形态,不自行重组。 |
|
||||
| 标量链式比较 | `:<`、`:>`、`:<>`、`:==`、`:>=`、`:<=` | 连续标量比较才使用。 |
|
||||
| 矩阵链式比较 | `::<`、`::>`、`::<>`、`::==`、`::>=`、`::<=` | 数组逐元素链式比较才使用;数组与矩阵样数据细节见 [12_matrix_and_collections.md](12_matrix_and_collections.md)。 |
|
||||
| 矩阵链式比较 | `::<`、`::>`、`::<>`、`::==`、`::>=`、`::<=` | 数组逐元素链式比较才使用;数组与矩阵样数据细节见 [11_matrix_and_collections.md](11_matrix_and_collections.md)。 |
|
||||
|
||||
### 专题运算符入口
|
||||
|
||||
<!-- tags: 运算符去哪查, 特殊符号归属 -->
|
||||
|
||||
| 运算符 / 形态 | 责任页 | 生成规则 |
|
||||
| --- | --- | --- |
|
||||
| `call(f, ...)`、`##f(...)`、`::FuncName(...)` | [05_functions_and_calls.md](05_functions_and_calls.md) | 函数值调用、变参转发和全局函数限定调用只按函数页生成。 |
|
||||
| 调用点 `in` / `out`、变参 `...` | [05_functions_and_calls.md](05_functions_and_calls.md) | 这是参数传递 / 变参规则,不按普通表达式运算符处理。 |
|
||||
| `#Func() with array(...)` | [10_runtime_context_and_with.md](10_runtime_context_and_with.md) | 运行时环境参数调用只按运行时上下文页生成。 |
|
||||
| `#Func(args)`、`timeout N`、`dupvalue(...)` | [10_runtime_context_and_with.md](10_runtime_context_and_with.md) | 网格调用和运行时服务后缀只按运行时上下文页生成。 |
|
||||
| `union2`、`intersect`、`minus`、`outersect`、`union2=`、`intersect=`、`minus=`、`outersect=` | [12_matrix_and_collections.md](12_matrix_and_collections.md) | 行集合并、交、差、对称差及其复合赋值只按数组/集合页生成。 |
|
||||
| `filterIn(...)`、`filterNotIn(...)` | [13_resultset_and_filters.md](13_resultset_and_filters.md) | 结果集过滤只按过滤页生成,不当作去重型集合运算。 |
|
||||
| `:*`、`:/`、`:\`、`:^`、`union`、|、`:|`、`|=`、`:|=`、`&=`、`:*=`、`:/=`、`:\=`、`:^=` | [22_matrix_deep_dive.md](22_matrix_deep_dive.md)、[23_fmarray.md](23_fmarray.md) | 矩阵乘除、左右拼接、下方拼接和矩阵复合赋值只按矩阵专题页生成。 |
|
||||
| `->`、`!matrix`、`.?`、`.?:` | [22_matrix_deep_dive.md](22_matrix_deep_dive.md) | 数列数组初始化、矩阵逆/广义逆、矩阵条件求值只按矩阵深水页生成。 |
|
||||
| `::`、`::=`、`:.`、`:.=` | [22_matrix_deep_dive.md](22_matrix_deep_dive.md)、[24_object_overloads_and_iteration.md](24_object_overloads_and_iteration.md) | 矩阵遍历/深度遍历和对象遍历重载只按专题页生成,不在普通表达式里自行套用。 |
|
||||
| 反引号转置 `` `value `` | [23_fmarray.md](23_fmarray.md) | `FMArray` 转置只按 `FMArray` 页生成。 |
|
||||
| `operator +`、`operator <`、`operator[]`、`operator[0]`、`operator[1]`、`operator for`、`operator mrows/mcols/msize`、`operator++`、`operator +=` | [24_object_overloads_and_iteration.md](24_object_overloads_and_iteration.md) | 对象运算符重载只按对象重载页生成。 |
|
||||
| `select` / `sselect` / `vselect` / `mselect`、`where`、`group by`、`order by`、`join` | [14_ts_sql.md](14_ts_sql.md) | TS-SQL 是查询语法,不按普通表达式拼接。 |
|
||||
| `union2`、`intersect`、`minus`、`outersect`、`union2=`、`intersect=`、`minus=`、`outersect=` | [11_matrix_and_collections.md](11_matrix_and_collections.md) | 行集合并、交、差、对称差及其复合赋值只按数组/集合页生成。 |
|
||||
| `filterIn(...)`、`filterNotIn(...)` | [12_resultset_and_filters.md](12_resultset_and_filters.md) | 结果集过滤只按过滤页生成,不当作去重型集合运算。 |
|
||||
| `:*`、`:/`、`:\`、`:^`、`union`、|、`:|`、`|=`、`:|=`、`&=`、`:*=`、`:/=`、`:\=`、`:^=` | [21_matrix_deep_dive.md](21_matrix_deep_dive.md)、[22_fmarray.md](22_fmarray.md) | 矩阵乘除、左右拼接、下方拼接和矩阵复合赋值只按矩阵专题页生成。 |
|
||||
| `->`、`!matrix`、`.?`、`.?:` | [21_matrix_deep_dive.md](21_matrix_deep_dive.md) | 数列数组初始化、矩阵逆/广义逆、矩阵条件求值只按矩阵深水页生成。 |
|
||||
| `::`、`::=`、`:.`、`:.=` | [21_matrix_deep_dive.md](21_matrix_deep_dive.md)、[23_object_overloads_and_iteration.md](23_object_overloads_and_iteration.md) | 矩阵遍历/深度遍历和对象遍历重载只按专题页生成,不在普通表达式里自行套用。 |
|
||||
| 反引号转置 `` `value `` | [22_fmarray.md](22_fmarray.md) | `FMArray` 转置只按 `FMArray` 页生成。 |
|
||||
| `operator +`、`operator <`、`operator[]`、`operator[0]`、`operator[1]`、`operator for`、`operator mrows/mcols/msize`、`operator++`、`operator +=` | [23_object_overloads_and_iteration.md](23_object_overloads_and_iteration.md) | 对象运算符重载只按对象重载页生成。 |
|
||||
| `select` / `sselect` / `vselect` / `mselect`、`where`、`group by`、`order by`、`join` | [13_ts_sql.md](13_ts_sql.md) | TS-SQL 是查询语法,不按普通表达式拼接。 |
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
默认生成规则:
|
||||
@@ -95,9 +81,9 @@
|
||||
按需生成规则:
|
||||
|
||||
- 已有变量需要原地更新时,才用 `+=`、`-=`、`*=`、`/=`、`\=`、`%=`、`^=`、`~=`、`div=`、`.&=`、`.|=`、`.^=`、`.&&=`、`.||=`、`a++;`、`a--;`、`++a;`、`--a;`。
|
||||
- 需要矩阵逆/广义逆时才使用 `!A`,矩阵生成规则以 [22_matrix_deep_dive.md](22_matrix_deep_dive.md) 为准。
|
||||
- 需要矩阵逆/广义逆时才使用 `!A`,矩阵生成规则以 [21_matrix_deep_dive.md](21_matrix_deep_dive.md) 为准。
|
||||
- 位运算需要明确写成点前缀或关键字形态:`.&`、`.|`、`.!`、`.^`、`shl`、`shr`、`rol`、`ror`;普通 `&` 不作为位与写法使用。
|
||||
- 点前缀比较 `.=`、`.<>`、`.<`、`.>`、`.<=`、`.>=` 命中数组/矩阵样数据时,逐元素语义以 [12_matrix_and_collections.md](12_matrix_and_collections.md) 为准。
|
||||
- 点前缀比较 `.=`、`.<>`、`.<`、`.>`、`.<=`、`.>=` 命中数组/矩阵样数据时,逐元素语义以 [11_matrix_and_collections.md](11_matrix_and_collections.md) 为准。
|
||||
- 需要延迟求值或动态表达式对象时,才用 `@expr` 或 `&"..."`,并用 `eval(...)` 求值。
|
||||
- 需要在一个表达式内按顺序执行多个子表达式时,才用逗号表达式 `(exp1, exp2, ..., expN)`。
|
||||
- 空安全访问只按 `a?.member`、`a?.[index]` 和本页示例里的 `c?.a?.[1]` 生成,不外推任意深链。
|
||||
@@ -110,7 +96,7 @@
|
||||
|
||||
- 没有文档事实的运算符,不生成猜测写法,也不从其他语言习惯反推 TSL 语法。
|
||||
- `{$ifdef ifexp}` 可用于探测 `if ... then ... else ...` 表达式能力;不要写成普通业务分支。
|
||||
- `{$ifdef nilinvoke}` 可用于探测 nil 调用相关能力;编译选项细节见 [16_lexical_structure_and_compile_options.md](16_lexical_structure_and_compile_options.md)。
|
||||
- `{$ifdef nilinvoke}` 可用于探测 nil 调用相关能力;编译选项细节见 [15_lexical_structure_and_compile_options.md](15_lexical_structure_and_compile_options.md)。
|
||||
|
||||
## 可直接照写示例
|
||||
|
||||
@@ -119,11 +105,13 @@
|
||||
- `:=` 是普通变量赋值写法;常量初始化规则见 [04_variables_and_constants.md](04_variables_and_constants.md)。
|
||||
- 函数调用、命名参数、默认参数和函数值调用边界见 [05_functions_and_calls.md](05_functions_and_calls.md);不要把函数签名里的 `name = value` 当成比较表达式。
|
||||
- 分支/循环语句见 [07_control_flow.md](07_control_flow.md);对象成员和类相关表达式见 [08_objects_and_classes.md](08_objects_and_classes.md)。
|
||||
- 字符串字面量、拼接与文本边界见 [03_values_and_literals.md](03_values_and_literals.md);数组扩展和矩阵样数据见 [12_matrix_and_collections.md](12_matrix_and_collections.md)。
|
||||
- `{$ifdef ...}` 能力探测见 [16_lexical_structure_and_compile_options.md](16_lexical_structure_and_compile_options.md),不要写成普通业务逻辑。
|
||||
- 字符串字面量、拼接与文本边界见 [03_values_and_literals.md](03_values_and_literals.md);数组扩展和矩阵样数据见 [11_matrix_and_collections.md](11_matrix_and_collections.md)。
|
||||
- `{$ifdef ...}` 能力探测见 [15_lexical_structure_and_compile_options.md](15_lexical_structure_and_compile_options.md),不要写成普通业务逻辑。
|
||||
|
||||
### 基础赋值和条件求值
|
||||
|
||||
<!-- tags: 三目运算, 问号冒号, 条件表达式, 一行判断取值 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
@@ -566,6 +554,8 @@ writeLn(if 2 > 1 then 2 else 1);
|
||||
|
||||
### 表达式对象
|
||||
|
||||
<!-- tags: 延迟求值, 表达式当值传, eval, 把式子存起来 -->
|
||||
|
||||
`@` 表达式前导:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -644,6 +634,8 @@ writeLn(result_value);
|
||||
|
||||
### 空安全访问
|
||||
|
||||
<!-- tags: 对象可能为空, 判空取属性, nil 安全, 避免空指针 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
@@ -687,6 +679,8 @@ writeLn(c?.a?.[1] = nil);
|
||||
|
||||
### 否定形式运算
|
||||
|
||||
<!-- tags: 取反, 不包含, 不匹配, not in 怎么写 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
@@ -713,6 +707,8 @@ end;
|
||||
|
||||
### 标量链式比较
|
||||
|
||||
<!-- tags: 连续比较, 区间判断, 夹在中间, 大小连写 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
@@ -737,6 +733,8 @@ writeLn(1 :<> 2 :<> 3);
|
||||
|
||||
### 矩阵链式比较
|
||||
|
||||
<!-- tags: 数组逐元素比较, 整列比较, 批量比较 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
@@ -765,6 +763,8 @@ writeLn(s[2]);
|
||||
|
||||
### 条件编译探测
|
||||
|
||||
<!-- tags: 判断支持哪些特性, 版本探测, ifdef 怎么用 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
|
||||
Reference in New Issue
Block a user