Skip to content

Commit 8e7ffb3

Browse files
authored
Add Jai language (#7202)
* Add Jai language * Update Jai language with up-to-date grammar
1 parent be39d09 commit 8e7ffb3

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
[submodule "vendor/grammars/JSyntax"]
5959
path = vendor/grammars/JSyntax
6060
url = https://github.com/tikkanz/JSyntax
61+
[submodule "vendor/grammars/Jails"]
62+
path = vendor/grammars/Jails
63+
url = https://github.com/SogoCZE/Jails.git
6164
[submodule "vendor/grammars/LOLCODE-grammar-vscode"]
6265
path = vendor/grammars/LOLCODE-grammar-vscode
6366
url = https://github.com/KrazIvan/LOLCODE-grammar-vscode.git

grammars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ vendor/grammars/Isabelle.tmbundle:
4646
- source.isabelle.theory
4747
vendor/grammars/JSyntax:
4848
- source.j
49+
vendor/grammars/Jails:
50+
- source.jai
4951
vendor/grammars/LOLCODE-grammar-vscode:
5052
- source.lolcode
5153
vendor/grammars/Ligo-grammar:

lib/linguist/languages.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,14 @@ JSONiq:
33963396
- ".jq"
33973397
tm_scope: source.jsoniq
33983398
language_id: 177
3399+
Jai:
3400+
type: programming
3401+
color: "#ab8b4b"
3402+
ace_mode: text
3403+
tm_scope: source.jai
3404+
extensions:
3405+
- ".jai"
3406+
language_id: 70127133
33993407
Janet:
34003408
type: programming
34013409
color: "#0886a5"

samples/Jai/cte.jai

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import "Basic";
2+
3+
do_some_work :: (a: int, b: int) -> int {
4+
#asm {
5+
add a, b;
6+
}
7+
return a;
8+
}
9+
10+
A :: #run do_some_work(10, 13);
11+
12+
main :: () {
13+
print("A: %\n", A); // => A: 23
14+
}

samples/Jai/ifx.jai

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#import "Basic";
2+
3+
Thing :: struct {
4+
name: string;
5+
value: int;
6+
}
7+
8+
get_default_name :: () -> string { return "Alice"; }
9+
10+
factorial :: (x: int) -> int {
11+
return ifx x <= 1 then 1 else x*factorial(x-1); // (1)
12+
}
13+
14+
is_even :: (value: int) -> bool {
15+
return !cast(bool)(value & 1);
16+
}
17+
18+
main :: () {
19+
a := 0;
20+
b := 100;
21+
c := ifx a > b 10 else 1000; // (2)
22+
print("c is %\n", c); // => c is 1000
23+
24+
thing := *Thing.{"Liz", 42};
25+
// name: string;
26+
// if thing {
27+
// name = thing.name;
28+
// } else {
29+
// name = get_default_name();
30+
// }
31+
32+
// one-liner with ifx:
33+
name := ifx thing then thing.name else get_default_name(); // (3)
34+
35+
// with code blocks:
36+
// name := ifx thing { // (4)
37+
// print("This is the true block.\n");
38+
// factorial(5);
39+
// thing.name;
40+
// } else {
41+
// print("We are about to get the default name.\n");
42+
// x := 3;
43+
// print("Really, it is going to happen.\n");
44+
// get_default_name();
45+
// }
46+
// => This is the true block.
47+
print("Your name is %\n", name); // => Your name is Liz
48+
49+
x := 7;
50+
y := ifx x then x else 1;
51+
// can be shortened to:
52+
y2 := ifx x else 1; // (5)
53+
print("y2 is %\n", y2); // => y2 is 7
54+
y3 := ifx x > 5 else 0; // (6)
55+
print("y3 is %\n", y3); // => y3 is 7
56+
y4 := ifx is_even(x);
57+
print("y4 is %\n", y4); // => y4 is 0
58+
y5 := ifx !is_even(x);
59+
print("y5 is %\n", y5); // => y4 is 7
60+
}

vendor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
278278
- **JSON5:** [atom/language-javascript](https://github.com/atom/language-javascript)
279279
- **JSONLD:** [atom/language-javascript](https://github.com/atom/language-javascript)
280280
- **JSONiq:** [wcandillon/language-jsoniq](https://github.com/wcandillon/language-jsoniq)
281+
- **Jai:** [SogoCZE/Jails](https://github.com/SogoCZE/Jails)
281282
- **Janet:** [janet-lang/vscode-janet](https://github.com/janet-lang/vscode-janet)
282283
- **Jasmin:** [atmarksharp/jasmin-sublime](https://github.com/atmarksharp/jasmin-sublime)
283284
- **Java:** [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java) 🐌

vendor/grammars/Jails

Submodule Jails added at 96da59f
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Jails
3+
version: 96da59f6160087d1514e97c7d95959a877b06612
4+
type: git_submodule
5+
homepage: https://github.com/SogoCZE/Jails.git
6+
license: mit
7+
licenses:
8+
- sources: LICENSE
9+
text: |
10+
MIT License
11+
12+
Copyright (c) 2023 Patrik Smělý
13+
14+
Permission is hereby granted, free of charge, to any person obtaining a copy
15+
of this software and associated documentation files (the "Software"), to deal
16+
in the Software without restriction, including without limitation the rights
17+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
copies of the Software, and to permit persons to whom the Software is
19+
furnished to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in all
22+
copies or substantial portions of the Software.
23+
24+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
SOFTWARE.
31+
notices: []

0 commit comments

Comments
 (0)