📝 docs(tsl): align syntax annotations and examples
This commit is contained in:
@@ -14,66 +14,66 @@ description: "TSL/TSF 语法与工程实践指南(基础语法/高级特性/
|
||||
### 变量与常量
|
||||
|
||||
```tsl
|
||||
A := 1;
|
||||
Name := "test";
|
||||
Items := array(1,2,3);
|
||||
Table := array("Code":"0001","Price":12.3);
|
||||
Const MaxRetries = 3;
|
||||
a := 1;
|
||||
name := "test";
|
||||
items := array(1, 2, 3);
|
||||
table_data := array("Code": "0001", "Price": 12.3);
|
||||
const kMaxRetries = 3;
|
||||
```
|
||||
|
||||
### 函数
|
||||
|
||||
```tsl
|
||||
Function Add(a,b);
|
||||
Begin
|
||||
Return a + b;
|
||||
End;
|
||||
function Add(a, b);
|
||||
begin
|
||||
return a + b;
|
||||
end;
|
||||
```
|
||||
|
||||
```tsl
|
||||
Function Parse(const s, var out_value);
|
||||
Begin
|
||||
out_value := StrToInt(s);
|
||||
Return out_value;
|
||||
End;
|
||||
function Parse(const s, var out_value);
|
||||
begin
|
||||
out_value := StrToInt(s);
|
||||
return out_value;
|
||||
end;
|
||||
```
|
||||
|
||||
### 控制流
|
||||
|
||||
```tsl
|
||||
If x>0 then
|
||||
y := 1
|
||||
else if x=0 then
|
||||
y := 0
|
||||
if x > 0 then
|
||||
y := 1;
|
||||
else if x = 0 then
|
||||
y := 0;
|
||||
else
|
||||
y := -1;
|
||||
y := -1;
|
||||
|
||||
For i := 0 to 9 do
|
||||
sum := sum + i;
|
||||
for i := 0 to 9 do
|
||||
sum := sum + i;
|
||||
|
||||
For idx,v in Items do
|
||||
total := total + v;
|
||||
for idx, v in items do
|
||||
total := total + v;
|
||||
```
|
||||
|
||||
### 异常处理
|
||||
|
||||
```tsl
|
||||
Try
|
||||
v := StrToInt(s);
|
||||
Except
|
||||
v := 0;
|
||||
Writeln(ExceptObject.ErrInfo);
|
||||
End;
|
||||
try
|
||||
v := StrToInt(s);
|
||||
except
|
||||
v := 0;
|
||||
WriteLn(ExceptObject.ErrInfo);
|
||||
end;
|
||||
```
|
||||
|
||||
### 数组与索引
|
||||
|
||||
```tsl
|
||||
arr := array(10,20,30);
|
||||
arr := array(10, 20, 30);
|
||||
value := arr[0];
|
||||
|
||||
m := array((1,2),(3,4));
|
||||
col0 := m[:,0];
|
||||
matrix := array((1, 2), (3, 4));
|
||||
col_0 := matrix[:, 0];
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user