📝 docs(tsl): align agent-facing guidance

This commit is contained in:
csh
2026-05-28 19:12:34 +08:00
parent c48354e0cb
commit d8eb418277
63 changed files with 1921 additions and 371 deletions
+22 -5
View File
@@ -14,6 +14,14 @@
回答“哪些写法最容易凭直觉写出来,但在 TSL 里会编译失败、运行出错,或语义并不可靠”。
## Agent 常见误写判断流程
1. 先识别用户写法属于值、变量、函数、表达式、对象、unit、TS-SQL 还是外部调用误区。
2. 遇到本页反例时,不要修成相邻语言习惯,必须跳回对应语法页找已验证正例。
3. 反例只用于排错和避免误写,不作为可照写模板。
4. 修复时保留 `.tsl` / `.tsf` 文件模型判断,不要只改局部语句。
5. 没有已验证代码块时不要发明替代语法。
## 这页怎么用
- 先按主题扫一遍,再回到对应正文看正确写法。
@@ -43,6 +51,12 @@ end;
a = 1;
```
代码块身份:已验证输出片段
```text
invalid statement
```
这会编译失败。正确页:见 [07_expressions_and_operators.md](07_expressions_and_operators.md)
#### 3. 把字符串当成 0 基下标
@@ -89,20 +103,23 @@ WriteLn(Length(s));
这不要按 C 风格字符串去理解。当前解释器里这里输出 `3`,说明 `#0` 仍是字符串内容的一部分。正确页:见 [04_values_and_literals.md](04_values_and_literals.md)
#### 7. 把顶层函数定义和松散语句混写
#### 7. 在 `.tsl` 声明区后面继续写脚本语句
代码块身份:反例 / 不可照写
```text
function Add(a, b);
a := 1;
test();
function test();
begin
return a + b;
echo "test";
end;
value := Add(1, 2);
echo "after declaration";
```
这会编译失败。正确页:见 [03_core_model.md](03_core_model.md)
`.tsl` 可以有语句区和声明区,但顺序必须清楚:语句区在前并按顺序执行,函数/类声明区在后。不要在声明区后面继续写脚本语句。正确页:见 [03_core_model.md](03_core_model.md)
#### 8. 顶层单独写 `const Name = value;`