Skip to content

Commit

Permalink
Add Jai language (#7202)
Browse files Browse the repository at this point in the history
* Add Jai language

* Update Jai language with up-to-date grammar
  • Loading branch information
funkkiy authored Jan 21, 2025
1 parent be39d09 commit 8e7ffb3
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
[submodule "vendor/grammars/JSyntax"]
path = vendor/grammars/JSyntax
url = https://github.com/tikkanz/JSyntax
[submodule "vendor/grammars/Jails"]
path = vendor/grammars/Jails
url = https://github.com/SogoCZE/Jails.git
[submodule "vendor/grammars/LOLCODE-grammar-vscode"]
path = vendor/grammars/LOLCODE-grammar-vscode
url = https://github.com/KrazIvan/LOLCODE-grammar-vscode.git
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ vendor/grammars/Isabelle.tmbundle:
- source.isabelle.theory
vendor/grammars/JSyntax:
- source.j
vendor/grammars/Jails:
- source.jai
vendor/grammars/LOLCODE-grammar-vscode:
- source.lolcode
vendor/grammars/Ligo-grammar:
Expand Down
8 changes: 8 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3396,6 +3396,14 @@ JSONiq:
- ".jq"
tm_scope: source.jsoniq
language_id: 177
Jai:
type: programming
color: "#ab8b4b"
ace_mode: text
tm_scope: source.jai
extensions:
- ".jai"
language_id: 70127133
Janet:
type: programming
color: "#0886a5"
Expand Down
14 changes: 14 additions & 0 deletions samples/Jai/cte.jai
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import "Basic";

do_some_work :: (a: int, b: int) -> int {
#asm {
add a, b;
}
return a;
}

A :: #run do_some_work(10, 13);

main :: () {
print("A: %\n", A); // => A: 23
}
60 changes: 60 additions & 0 deletions samples/Jai/ifx.jai
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#import "Basic";

Thing :: struct {
name: string;
value: int;
}

get_default_name :: () -> string { return "Alice"; }

factorial :: (x: int) -> int {
return ifx x <= 1 then 1 else x*factorial(x-1); // (1)
}

is_even :: (value: int) -> bool {
return !cast(bool)(value & 1);
}

main :: () {
a := 0;
b := 100;
c := ifx a > b 10 else 1000; // (2)
print("c is %\n", c); // => c is 1000

thing := *Thing.{"Liz", 42};
// name: string;
// if thing {
// name = thing.name;
// } else {
// name = get_default_name();
// }

// one-liner with ifx:
name := ifx thing then thing.name else get_default_name(); // (3)

// with code blocks:
// name := ifx thing { // (4)
// print("This is the true block.\n");
// factorial(5);
// thing.name;
// } else {
// print("We are about to get the default name.\n");
// x := 3;
// print("Really, it is going to happen.\n");
// get_default_name();
// }
// => This is the true block.
print("Your name is %\n", name); // => Your name is Liz

x := 7;
y := ifx x then x else 1;
// can be shortened to:
y2 := ifx x else 1; // (5)
print("y2 is %\n", y2); // => y2 is 7
y3 := ifx x > 5 else 0; // (6)
print("y3 is %\n", y3); // => y3 is 7
y4 := ifx is_even(x);
print("y4 is %\n", y4); // => y4 is 0
y5 := ifx !is_even(x);
print("y5 is %\n", y5); // => y4 is 7
}
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **JSON5:** [atom/language-javascript](https://github.com/atom/language-javascript)
- **JSONLD:** [atom/language-javascript](https://github.com/atom/language-javascript)
- **JSONiq:** [wcandillon/language-jsoniq](https://github.com/wcandillon/language-jsoniq)
- **Jai:** [SogoCZE/Jails](https://github.com/SogoCZE/Jails)
- **Janet:** [janet-lang/vscode-janet](https://github.com/janet-lang/vscode-janet)
- **Jasmin:** [atmarksharp/jasmin-sublime](https://github.com/atmarksharp/jasmin-sublime)
- **Java:** [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java) 🐌
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/Jails
Submodule Jails added at 96da59
31 changes: 31 additions & 0 deletions vendor/licenses/git_submodule/Jails.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Jails
version: 96da59f6160087d1514e97c7d95959a877b06612
type: git_submodule
homepage: https://github.com/SogoCZE/Jails.git
license: mit
licenses:
- sources: LICENSE
text: |
MIT License
Copyright (c) 2023 Patrik Smělý
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
notices: []

0 comments on commit 8e7ffb3

Please sign in to comment.