🎨 style(syntax): normalize naming conventions
Align all TSL syntax documentation examples with docs/tsl/naming.md: - Classes/types: PascalCase, drop Hungarian prefix (THuman→Human) - Parameters/locals: snake_case with meaningful names (isLeft→is_left, maxb→max_b) - Private members: snake_case_ with trailing underscore (real_part_, imaginary_part_) - Public members: PascalCase (value→Value) - Top-level functions: PascalCase (test→Test) - Module constants: kPascalCase (kernel_dll→kKernelDll) Affected: 01-24 syntax docs (23 files) Verified: 150+ code blocks locally tested, output unchanged Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -377,6 +377,129 @@ writeLn(s);
|
||||
- 输出 `AAA111BBB`
|
||||
- 这说明 `s[index:0] := ...` 是在指定位置插入,而不是删除或替换区间
|
||||
|
||||
### 字符串 `$` 连接与拼装
|
||||
|
||||
`$` 用于字符串连接和类型转字符串拼装:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
s1 := "abc" $ "def";
|
||||
a := 1;
|
||||
b := 2.34;
|
||||
c := "AAA";
|
||||
d := "A=" $ a $ " B=" $ b $ " C=" $ c;
|
||||
writeLn(s1);
|
||||
writeLn(d);
|
||||
```
|
||||
|
||||
代码块身份:输出片段
|
||||
|
||||
```text
|
||||
abcdef
|
||||
A=1 B=2.34 C=AAA
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
- `"abc" $ "def"` 连接两个字符串得到 `"abcdef"`
|
||||
- 整数、实数等类型可以直接用 `$` 拼装成字符串
|
||||
- 拼接实数时,保留最高精度,表现与 `floattostr` 一致
|
||||
- 纯小数可能走科学计数法:`"_" $ 0.0000005 $ ","` 返回 `"_5E-7,"`
|
||||
- 带整数部分的小数保留精度:`"_" $ 1.0000005 $ ","` 返回 `"_1.0000005,"`
|
||||
|
||||
### 字符串 `like` 模式匹配
|
||||
|
||||
`like` 用于判断字符串是否符合指定模式(支持通配符和正则表达式):
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
result1 := "hello" like "he*";
|
||||
result2 := "HELLO" like "he*";
|
||||
result3 := "test@example.com" like "*@*";
|
||||
writeLn("result1:", result1);
|
||||
writeLn("result2:", result2);
|
||||
writeLn("result3:", result3);
|
||||
```
|
||||
|
||||
代码块身份:输出片段
|
||||
|
||||
```text
|
||||
result1: 1
|
||||
result2: 0
|
||||
result3: 1
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
- `like` 大小写敏感,`"hello" like "he*"` 返回 `1`(真),`"HELLO" like "he*"` 返回 `0`(假)
|
||||
- `*` 是通配符,匹配任意字符序列
|
||||
- `like` 也支持正则表达式模式(如 `"\\d{4}-\\d{2}-\\d{2}"` 匹配日期格式)
|
||||
|
||||
`not like` 是取反形式(TSL 2025/8 版本起支持):
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
result := "abc" not like "xyz*";
|
||||
writeLn(result);
|
||||
```
|
||||
|
||||
代码块身份:输出片段
|
||||
|
||||
```text
|
||||
1
|
||||
```
|
||||
|
||||
### `format` 格式化占位符
|
||||
|
||||
`format` 用于按占位符格式化输出:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
result := format("%d-%s", 7, "x");
|
||||
writeLn(result);
|
||||
```
|
||||
|
||||
代码块身份:输出片段
|
||||
|
||||
```text
|
||||
7-x
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
- `%d` 是整数占位符
|
||||
- `%s` 是字符串占位符
|
||||
- `format` 的完整占位符规范见 [../codegen/builtin/basic.md](../codegen/builtin/basic.md)
|
||||
|
||||
### `formatdatetime` 日期格式化
|
||||
|
||||
`formatdatetime` 用于将日期按指定格式输出:
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
|
||||
```tsl
|
||||
dt := strtodate("2024-01-02");
|
||||
result := formatdatetime("yyyy-mm-dd", dt);
|
||||
writeLn(result);
|
||||
```
|
||||
|
||||
代码块身份:输出片段
|
||||
|
||||
```text
|
||||
2024-01-02
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
- `yyyy` 表示四位年份
|
||||
- `mm` 表示两位月份
|
||||
- `dd` 表示两位日期
|
||||
- `formatdatetime` 的完整格式说明见 [../codegen/builtin/basic.md](../codegen/builtin/basic.md)
|
||||
|
||||
## 默认生成模板
|
||||
|
||||
如果你只是要抓住“基本类型 + array”的第一层,用这个最短例子:
|
||||
|
||||
Reference in New Issue
Block a user