Skip to content

Commit 0968e88

Browse files
committed
update kcl examples
1 parent 5633129 commit 0968e88

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

docs/kcl.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Resources
66

77
* [Documentation](https://www.kcl-lang.io)
8+
* [KCL Tour](https://www.kcl-lang.io/docs/reference/lang/tour)
89
* [KCL extension](https://marketplace.visualstudio.com/items?itemName=kcl.kcl-vscode-extension) for Visual Studio Code
910

1011
```sh
@@ -15,6 +16,8 @@ brew install kcl-lang/tap/kcl
1516
## Examples
1617

1718
```sh
18-
# execute program
19+
# execute program and output yaml
1920
kcl kcl/hello.k
21+
kcl kcl/server-1.k
22+
kcl kcl/server-2.k
2023
```

kcl/server-1.k

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This is a KCL document
2+
3+
# attribute
4+
title = "KCL Example"
5+
6+
# dictionary
7+
owner = {
8+
name = "The KCL Authors"
9+
data = "2020-01-02T03:04:05"
10+
}
11+
12+
database = {
13+
enabled = True
14+
ports = [8000, 8001, 8002]
15+
data = [["delta", "phi"], [3.14]]
16+
temp_targets = {cpu = 79.5, case = 72.0}
17+
}
18+
19+
# list with dictionaries
20+
servers = [
21+
{ip = "10.0.0.1", role = "frontend"}
22+
{ip = "10.0.0.2", role = "backend"}
23+
]

kcl/server-2.k

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# default configuration
2+
schema DatabaseConfig:
3+
enable: bool = True
4+
ports: [int] = [8000, 8001, 8002]
5+
data: [[str|float]] = [["delta", "phi"], [3.14]]
6+
temp_targets: {str: float} = {cpu = 79.5, case = 72.0}
7+
8+
schema ServerConfig:
9+
# required when no default value
10+
ip: str
11+
# enumeration
12+
role: "frontend" | "backend"
13+
14+
# unique name
15+
databaseNew = DatabaseConfig {
16+
ports = [2020, 2021]
17+
}
18+
19+
serversNew = [
20+
ServerConfig {ip = "10.0.0.1", role = "frontend"}
21+
ServerConfig {ip = "10.0.0.2", role = "backend"}
22+
]

0 commit comments

Comments
 (0)