From 8e7ffb338d49c5c26808728844bf5e7243b334c2 Mon Sep 17 00:00:00 2001 From: davi Date: Tue, 21 Jan 2025 04:10:25 -0300 Subject: [PATCH] Add Jai language (#7202) * Add Jai language * Update Jai language with up-to-date grammar --- .gitmodules | 3 ++ grammars.yml | 2 + lib/linguist/languages.yml | 8 +++ samples/Jai/cte.jai | 14 +++++ samples/Jai/ifx.jai | 60 +++++++++++++++++++++ vendor/README.md | 1 + vendor/grammars/Jails | 1 + vendor/licenses/git_submodule/Jails.dep.yml | 31 +++++++++++ 8 files changed, 120 insertions(+) create mode 100644 samples/Jai/cte.jai create mode 100644 samples/Jai/ifx.jai create mode 160000 vendor/grammars/Jails create mode 100644 vendor/licenses/git_submodule/Jails.dep.yml diff --git a/.gitmodules b/.gitmodules index ae3766341..428721179 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/grammars.yml b/grammars.yml index aaea7a180..1f26a6bfb 100644 --- a/grammars.yml +++ b/grammars.yml @@ -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: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index bcba5cc18..bf6112f38 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -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" diff --git a/samples/Jai/cte.jai b/samples/Jai/cte.jai new file mode 100644 index 000000000..e561da92c --- /dev/null +++ b/samples/Jai/cte.jai @@ -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 +} \ No newline at end of file diff --git a/samples/Jai/ifx.jai b/samples/Jai/ifx.jai new file mode 100644 index 000000000..404befdfe --- /dev/null +++ b/samples/Jai/ifx.jai @@ -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 +} \ No newline at end of file diff --git a/vendor/README.md b/vendor/README.md index 9abe3a704..51f9eb5f7 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -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) 🐌 diff --git a/vendor/grammars/Jails b/vendor/grammars/Jails new file mode 160000 index 000000000..96da59f61 --- /dev/null +++ b/vendor/grammars/Jails @@ -0,0 +1 @@ +Subproject commit 96da59f6160087d1514e97c7d95959a877b06612 diff --git a/vendor/licenses/git_submodule/Jails.dep.yml b/vendor/licenses/git_submodule/Jails.dep.yml new file mode 100644 index 000000000..3c1ce626e --- /dev/null +++ b/vendor/licenses/git_submodule/Jails.dep.yml @@ -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: []