Skip to content

Commit a56f4b3

Browse files
Add Jule language
Co-authored-by: mertcandav <[email protected]> Signed-off-by: adam <[email protected]>
1 parent 63cfd70 commit a56f4b3

File tree

10 files changed

+254
-0
lines changed

10 files changed

+254
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,9 @@
13381338
[submodule "vendor/grammars/vscode-jest"]
13391339
path = vendor/grammars/vscode-jest
13401340
url = https://github.com/jest-community/vscode-jest
1341+
[submodule "vendor/grammars/vscode-jule"]
1342+
path = vendor/grammars/vscode-jule
1343+
url = https://github.com/julelang/vscode-jule.git
13411344
[submodule "vendor/grammars/vscode-just"]
13421345
path = vendor/grammars/vscode-just
13431346
url = https://github.com/nefrob/vscode-just.git

grammars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,8 @@ vendor/grammars/vscode-janet:
12011201
- source.janet
12021202
vendor/grammars/vscode-jest:
12031203
- source.jest.snap
1204+
vendor/grammars/vscode-jule:
1205+
- source.jule
12041206
vendor/grammars/vscode-just:
12051207
- source.just
12061208
vendor/grammars/vscode-lean:

lib/linguist/languages.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,16 @@ Jsonnet:
35923592
- ".libsonnet"
35933593
tm_scope: source.jsonnet
35943594
language_id: 664885656
3595+
Jule:
3596+
type: programming
3597+
color: "#5f7489"
3598+
aliases:
3599+
- julelang
3600+
extensions:
3601+
- ".jule"
3602+
tm_scope: source.jule
3603+
ace_mode: text
3604+
language_id: 90868683
35953605
Julia:
35963606
type: programming
35973607
extensions:

samples/Jule/caesar.jule

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This work is marked with CC0 1.0 Universal
2+
// https://creativecommons.org/publicdomain/zero/1.0
3+
4+
// A command-line tool that provides Caesar cipher.
5+
6+
use "std/conv"
7+
use "std/os"
8+
use "std/strings"
9+
use "std/unicode/utf8"
10+
11+
fn caesar(text: str, mut shift: int): str {
12+
let mut sb: strings::Builder
13+
shift = shift % 26
14+
if shift < 0 {
15+
shift += 26
16+
}
17+
for _, r in text {
18+
match {
19+
| 'a' <= r && r <= 'z':
20+
newRune := 'a' + (r-'a'+rune(shift))%26
21+
sb.WriteRune(newRune)!
22+
| 'A' <= r && r < '>':
23+
newRune := 'A' + (r-'A'+rune(shift))%26
24+
sb.WriteRune(newRune)!
25+
|:
26+
sb.WriteRune(r)!
27+
}
28+
}
29+
ret sb.Str()
30+
}
31+
32+
fn main() {
33+
args := os::Args()
34+
if len(args) == 1 {
35+
println(`Simple Caesar cipher.
36+
Encrypt: ec [SHIFT] [TEXT]
37+
Decrypt: dc [SHIFT] [TEXT]`)
38+
ret
39+
}
40+
cmd := args[1]
41+
ec := cmd == "ec"
42+
dc := cmd == "dc"
43+
if !ec && !dc {
44+
println("error: invalid command: " + cmd)
45+
ret
46+
}
47+
if len(args) < 4 {
48+
println("error: arguments are missing for ec/dc")
49+
ret
50+
}
51+
if len(args) > 4 {
52+
println("error: passed more arguments than expected")
53+
ret
54+
}
55+
shiftArg := args[2]
56+
mut shift := conv::ParseInt(shiftArg, 10, 64) else {
57+
println("error: shift parameter is not a valid number")
58+
ret
59+
}
60+
if dc {
61+
shift = -shift
62+
}
63+
data := args[3]
64+
println(caesar(data, int(shift)))
65+
}

samples/Jule/calculator.jule

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// This work is marked with CC0 1.0 Universal
2+
// https://creativecommons.org/publicdomain/zero/1.0
3+
4+
// Basic integer calculator.
5+
// Takes expressions as arguments and prints the results.
6+
// Supports only addition and subtraction.
7+
8+
use "std/conv"
9+
use "std/os"
10+
use "std/strings"
11+
12+
fn findOperator(expr: str): int {
13+
mut ranges := 0
14+
mut i := len(expr) - 1
15+
for i > 0; i-- {
16+
b := expr[i]
17+
match b {
18+
| '(':
19+
ranges++
20+
| ')':
21+
ranges--
22+
| '+' | '-':
23+
if ranges == 0 {
24+
ret i
25+
}
26+
}
27+
}
28+
ret -1
29+
}
30+
31+
fn unary(v: str, op: byte): int {
32+
x := eval(v)
33+
match op {
34+
| '+':
35+
ret +x
36+
| '-':
37+
ret -x
38+
|:
39+
println("error: invalid expression")
40+
os::Exit(1)
41+
ret 0 // To avoid error.
42+
}
43+
}
44+
45+
fn plain(expr: str): int {
46+
if len(expr) == 0 {
47+
println("error: invalid expression")
48+
os::Exit(1)
49+
}
50+
match expr[0] {
51+
| '(':
52+
if expr[len(expr)-1] != ')' {
53+
println("error: invalid expression")
54+
os::Exit(1)
55+
ret 0 // To avoid error.
56+
}
57+
ret eval(expr[1 : len(expr)-1])
58+
| '+' | '-':
59+
ret unary(expr[1:], expr[0])
60+
|:
61+
i := conv::ParseInt(expr, 10, 64) else {
62+
println("error: invalid expression")
63+
os::Exit(1)
64+
use 0 // To avoid error.
65+
}
66+
ret int(i)
67+
}
68+
}
69+
70+
fn eval(expr: str): int {
71+
i := findOperator(expr)
72+
if i == -1 {
73+
ret plain(expr)
74+
}
75+
op := expr[i]
76+
l := eval(expr[:i])
77+
r := eval(expr[i+1:])
78+
match op {
79+
| '+':
80+
ret l + r
81+
| '-':
82+
ret l - r
83+
|:
84+
println("error: invalid expression")
85+
os::Exit(1)
86+
ret 0 // To avoid error.
87+
}
88+
}
89+
90+
fn main() {
91+
args := os::Args()
92+
if len(args) < 2 {
93+
println(`Basic integer calculator.
94+
Takes expressions as arguments and prints the results.
95+
Supports only addition and subtraction.`)
96+
ret
97+
}
98+
for (_, mut expr) in args[1:] {
99+
expr = strings::Replace(expr, " ", "", -1)
100+
result := eval(expr)
101+
println(result)
102+
}
103+
}

samples/Jule/cat.jule

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This work is marked with CC0 1.0 Universal
2+
// https://creativecommons.org/publicdomain/zero/1.0
3+
4+
// Simple "cat" command.
5+
6+
use "std/fmt"
7+
use "std/os"
8+
9+
fn main() {
10+
args := os::Args()
11+
if len(args) == 1 {
12+
ret
13+
}
14+
for _, path in args[1:] {
15+
data := os::ReadFile(path) else {
16+
fmt::Println("cat: ", path, " error: ", error)
17+
continue
18+
}
19+
print(str(data))
20+
}
21+
}

samples/Jule/hello.jule

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This work is marked with CC0 1.0 Universal
2+
// https://creativecommons.org/publicdomain/zero/1.0
3+
4+
fn main() {
5+
println("hello world")
6+
}

vendor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
291291
- **Jison Lex:** [cdibbs/language-jison](https://github.com/cdibbs/language-jison)
292292
- **Jolie:** [fmontesi/language-jolie](https://github.com/fmontesi/language-jolie)
293293
- **Jsonnet:** [google/language-jsonnet](https://github.com/google/language-jsonnet)
294+
- **Jule:** [julelang/vscode-jule](https://github.com/julelang/vscode-jule)
294295
- **Julia:** [JuliaEditorSupport/atom-language-julia](https://github.com/JuliaEditorSupport/atom-language-julia)
295296
- **Julia REPL:** [JuliaEditorSupport/atom-language-julia](https://github.com/JuliaEditorSupport/atom-language-julia)
296297
- **Jupyter Notebook:** [Nixinova/NovaGrammars](https://github.com/Nixinova/NovaGrammars)

vendor/grammars/vscode-jule

Submodule vscode-jule added at e21443d
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: vscode-jule
3+
version: e21443d04d25327c0f511542687861367cf4daaa
4+
type: git_submodule
5+
homepage: https://github.com/julelang/vscode-jule.git
6+
license: bsd-3-clause
7+
licenses:
8+
- sources: LICENSE
9+
text: |
10+
BSD 3-Clause License
11+
12+
Copyright (c) 2022-2025, Mertcan DAVULCU
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are met:
16+
17+
1. Redistributions of source code must retain the above copyright notice, this
18+
list of conditions and the following disclaimer.
19+
20+
2. Redistributions in binary form must reproduce the above copyright notice,
21+
this list of conditions and the following disclaimer in the documentation
22+
and/or other materials provided with the distribution.
23+
24+
3. Neither the name of the copyright holder nor the names of its
25+
contributors may be used to endorse or promote products derived from
26+
this software without specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
- sources: README.md
39+
text: |-
40+
The extension is distributed under the terms of the BSD 3-Clause license. <br>
41+
[See License Details](LICENSE)
42+
notices: []

0 commit comments

Comments
 (0)