Skip to content

Commit 05fa138

Browse files
mihaigaloslildude
andauthored
Add KCL, KFramework Languages (#7490)
* feat: KCL - Setup Signed-off-by: Mihai Galos <[email protected]> feat: KCL - Setup Signed-off-by: Mihai Galos <[email protected]> feat: KCL - Setup * feat: KCL - Setup Signed-off-by: Mihai Galos <[email protected]> feat: KCL - Setup Signed-off-by: Mihai Galos <[email protected]> feat: KCL - Setup * feat: KCL - Setup Signed-off-by: Mihai Galos <[email protected]> feat: KCL - Setup Signed-off-by: Mihai Galos <[email protected]> feat: KCL - Setup * chore: Address review comments * chore: Address review findings * chore: Address review findings Signed-off-by: Mihai Galos <[email protected]> * feat: KFRamework - Add * chore: Fix tests * chore: Address review findings * chore: Address review findings * chore: Address review findings * feat: Add heuristics for disambiguation * Update vendor/licenses/git_submodule/K-VSCode.dep.yml --------- Signed-off-by: Mihai Galos <[email protected]> Signed-off-by: Mihai Galos <[email protected]> Co-authored-by: Colin Seymour <[email protected]>
1 parent 84902b0 commit 05fa138

File tree

14 files changed

+481
-0
lines changed

14 files changed

+481
-0
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
[submodule "vendor/grammars/Jails"]
7171
path = vendor/grammars/Jails
7272
url = https://github.com/SogoCZE/Jails.git
73+
[submodule "vendor/grammars/K-VSCode"]
74+
path = vendor/grammars/K-VSCode
75+
url = https://github.com/LucianCumpata/K-VSCode.git
7376
[submodule "vendor/grammars/LOLCODE-grammar-vscode"]
7477
path = vendor/grammars/LOLCODE-grammar-vscode
7578
url = https://github.com/KrazIvan/LOLCODE-grammar-vscode.git
@@ -1413,6 +1416,9 @@
14131416
[submodule "vendor/grammars/vscode-just"]
14141417
path = vendor/grammars/vscode-just
14151418
url = https://github.com/nefrob/vscode-just.git
1419+
[submodule "vendor/grammars/vscode-kcl"]
1420+
path = vendor/grammars/vscode-kcl
1421+
url = https://github.com/kcl-lang/vscode-kcl.git
14161422
[submodule "vendor/grammars/vscode-kdl"]
14171423
path = vendor/grammars/vscode-kdl
14181424
url = https://github.com/kdl-org/vscode-kdl.git

grammars.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ vendor/grammars/JSyntax:
5454
- source.j
5555
vendor/grammars/Jails:
5656
- source.jai
57+
vendor/grammars/K-VSCode:
58+
- text.k
5759
vendor/grammars/LOLCODE-grammar-vscode:
5860
- source.lolcode
5961
vendor/grammars/Ligo-grammar:
@@ -1264,6 +1266,8 @@ vendor/grammars/vscode-jsonc-syntax-highlighting:
12641266
- source.json.comments
12651267
vendor/grammars/vscode-just:
12661268
- source.just
1269+
vendor/grammars/vscode-kcl:
1270+
- source.kcl
12671271
vendor/grammars/vscode-kdl:
12681272
- source.kdl
12691273
vendor/grammars/vscode-kolmafia-ash:

lib/linguist/heuristics.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ disambiguations:
427427
- language: OASv3-json
428428
pattern: '"openapi":\s?"3.[0-9.]+"'
429429
- language: JSON
430+
- extensions: ['.k']
431+
rules:
432+
- language: KCL
433+
pattern:
434+
- '^schema [A-Za-z0-9_-]+'
435+
- '^\}$'
436+
- '\s*\}\s*'
437+
- language: KFramework
438+
pattern:
439+
- '^requires\s+"[^"]+"$'
440+
- '^syntax\s+\w+\s+::=.*'
441+
- '^endmodule$'
430442
- extensions: ['.l']
431443
rules:
432444
- language: Common Lisp

lib/linguist/languages.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,17 @@ Just:
38293829
- ".just"
38303830
ace_mode: text
38313831
language_id: 128447695
3832+
KCL:
3833+
type: programming
3834+
color: "#7ABABF"
3835+
tm_scope: source.kcl
3836+
extensions:
3837+
- ".k"
3838+
filenames:
3839+
- kcl.mod
3840+
- kcl.mod.lock
3841+
ace_mode: text
3842+
language_id: 1052003890
38323843
KDL:
38333844
type: data
38343845
color: "#ffb3b3"
@@ -3839,6 +3850,14 @@ KDL:
38393850
codemirror_mode: yacas
38403851
codemirror_mime_type: text/x-yacas
38413852
language_id: 931123626
3853+
KFramework:
3854+
type: programming
3855+
color: "#4195c5"
3856+
tm_scope: text.k
3857+
extensions:
3858+
- ".k"
3859+
ace_mode: text
3860+
language_id: 9479532
38423861
KRL:
38433862
type: programming
38443863
color: "#28430A"

samples/KCL/complex.k

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
schema App:
2+
"""The application model."""
3+
name: str
4+
replicas: int = 1
5+
labels?: {str:str} = {app = name}
6+
service?: Service
7+
containers?: {str: Container}
8+
9+
schema Service:
10+
"""The service model."""
11+
$type?: str
12+
ports: [Port]
13+
14+
schema Port:
15+
"""The port model."""
16+
port: int
17+
protocol: "TCP" | "UDP" | "SCTP" = "TCP"
18+
targetPort?: int | str
19+
20+
schema Container:
21+
"""The container model."""
22+
image: str
23+
command?: [str]
24+
args?: [str]
25+
env?: [Env]
26+
volumes?: [Volume]
27+
resources?: Resource
28+
ports: [ContainerPort]
29+
30+
schema ContainerPort:
31+
"""The container port model."""
32+
name?: str
33+
protocol: "TCP" | "UDP" | "SCTP" = "TCP"
34+
containerPort: int
35+
36+
check:
37+
1 <= containerPort <= 65535, "containerPort must be between 1 and 65535, inclusive"
38+
39+
schema Env:
40+
name: str
41+
value: str
42+
43+
schema Volume:
44+
source: str
45+
path: str
46+
target: str
47+
readOnly?: bool = False
48+
49+
schema Resource:
50+
limits?: {str:}
51+
requests?: {str:}
52+
53+
import manifests
54+
55+
# Convert the `App` model into Kubernetes Deployment and Service Manifests
56+
kubernetesRender = lambda a: App {
57+
# Construct the deployment manifest.
58+
deployment = {
59+
apiVersion = "apps/v1"
60+
kind = "Deployment"
61+
metadata.name = a.name
62+
metadata.labels = a.labels
63+
spec = {
64+
replicas = a.replicas
65+
selector.matchLabels = a.labels
66+
template.metadata.labels = a.labels
67+
template.spec.containers = [
68+
{
69+
name = name
70+
image = c.image
71+
command = c.command
72+
args = c.args
73+
env = c.env
74+
volumeMounts = c.volumes
75+
resources: c.resources
76+
ports = c.ports
77+
} for name, c in a.containers
78+
]
79+
}
80+
}
81+
# Construct the service manifest.
82+
service = {
83+
apiVersion = "v1"
84+
kind = "Service"
85+
metadata.name = a.name
86+
metadata.labels = a.labels
87+
spec = {
88+
type = a.service?.$type
89+
selector = a.labels
90+
ports = a.service?.ports
91+
}
92+
}
93+
# Returns Kubernetes manifests
94+
[deployment, if a.service: service]
95+
}
96+
97+
98+
App {
99+
name = "app"
100+
containers.nginx = {
101+
image = "nginx"
102+
ports = [{containerPort = 80}]
103+
}
104+
service.ports = [{ port = 80 }]
105+
}
106+
107+
manifests.yaml_stream(sum([kubernetesRender(a) for a in App.instances()], []))

samples/KCL/simple.k

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
schema App:
2+
"""The application model."""
3+
name: str
4+
replicas: int
5+
labels?: {str:str} = {app = name}
6+
7+
app: App {
8+
name = "app"
9+
replicas = 1
10+
labels.key = "value"
11+
}

samples/KFramework/sample1.k

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Runtime Verification, Inc. All Rights Reserved.
2+
3+
module RAND-SYNTAX
4+
imports DOMAINS-SYNTAX
5+
6+
syntax Pgm ::= ".Pgm" | Int ";" Pgm | runRand ( )
7+
endmodule
8+
9+
10+
module RAND
11+
imports RAND-SYNTAX
12+
imports DOMAINS
13+
14+
configuration <k> /home/mihai/git/linguist/samples/KFrameworkgm </k>
15+
<rands> .List </rands>
16+
17+
rule <k> I ; P => srandInt(I) ~> runRand() ~> P ... </k>
18+
19+
rule <k> runRand() => .K ... </k>
20+
<rands> ... .List => ListItem(randInt(1000)) </rands>
21+
endmodule

samples/KFramework/sample2.k

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Runtime Verification, Inc. All Rights Reserved.
2+
module IMP-SYNTAX
3+
imports DOMAINS-SYNTAX
4+
5+
syntax Pgm ::= Int
6+
endmodule
7+
8+
9+
module IMP
10+
imports IMP-SYNTAX
11+
imports DOMAINS
12+
syntax KResult ::= Int | Bool
13+
14+
configuration <T color="yellow">
15+
<k color="green"> /home/mihai/git/linguist/samples/KFrameworkgm </k>
16+
<cpp-enums>
17+
<cppenum multiplicity="*" type="Map">
18+
<enum-id> .K </enum-id>
19+
<enum-type> .K </enum-type>
20+
<scoped> false </scoped>
21+
</cppenum>
22+
</cpp-enums>
23+
</T>
24+
25+
syntax Enum
26+
27+
syntax CppenumCell
28+
syntax IncompleteInfo ::= "#incomplete"
29+
syntax EnumInfo ::= CppenumCell | IncompleteInfo
30+
syntax EnumInfo ::= #getEnumInfo(Enum) [function]
31+
32+
rule [[ #getEnumInfo(X::Enum) => <cppenum> <enum-id> X </enum-id> B </cppenum> ]]
33+
<cppenum> <enum-id> X </enum-id> B::Bag </cppenum>
34+
35+
rule #getEnumInfo(_) => #incomplete [owise]
36+
37+
endmodule

test/test_heuristics.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,13 @@ def test_json_by_heuristics
605605
})
606606
end
607607

608+
def test_k_by_heuristics
609+
assert_heuristics({
610+
"KCL" => all_fixtures("KCL", "*.k"),
611+
"KFramework" => all_fixtures("KFramework", "*.k")
612+
})
613+
end
614+
608615
def test_l_by_heuristics
609616
assert_heuristics({
610617
"Common Lisp" => all_fixtures("Common Lisp", "*.l"),

vendor/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
313313
- **Julia REPL:** [JuliaEditorSupport/atom-language-julia](https://github.com/JuliaEditorSupport/atom-language-julia)
314314
- **Jupyter Notebook:** [Nixinova/NovaGrammars](https://github.com/Nixinova/NovaGrammars)
315315
- **Just:** [nefrob/vscode-just](https://github.com/nefrob/vscode-just)
316+
- **KCL:** [kcl-lang/vscode-kcl](https://github.com/kcl-lang/vscode-kcl)
316317
- **KDL:** [kdl-org/vscode-kdl](https://github.com/kdl-org/vscode-kdl)
318+
- **KFramework:** [LucianCumpata/K-VSCode](https://github.com/LucianCumpata/K-VSCode)
317319
- **Kaitai Struct:** [atom/language-yaml](https://github.com/atom/language-yaml)
318320
- **KakouneScript:** [kakoune-editor/language-kak](https://github.com/kakoune-editor/language-kak)
319321
- **KerboScript:** [KSP-KOS/language-kerboscript](https://github.com/KSP-KOS/language-kerboscript)

0 commit comments

Comments
 (0)