~repos /plum

#treesitter#compiler#wasm

git clone https://pyrossh.dev/repos/plum.git

A statically typed, imperative programming language inspired by rust, python


1675049b Peter John

1 year ago
new syntax
Files changed (82) hide show
  1. ab.rs +0 -26
  2. {std → libs/std}/bool.ks +0 -0
  3. {std → libs/std}/float.ks +0 -0
  4. {std → libs/std}/html.mi +0 -0
  5. {std → libs/std}/http.mi +0 -0
  6. {std → libs/std}/int.ks +0 -0
  7. {std → libs/std}/json.mi +0 -0
  8. {std → libs/std}/list.mi +0 -0
  9. {std → libs/std}/map.mi +0 -0
  10. {std → libs/std}/option.ks +0 -0
  11. {std → libs/std}/os.mi +0 -0
  12. {std → libs/std}/regex.mi +0 -0
  13. {std → libs/std}/result.ks +0 -0
  14. {std → libs/std}/str.mi +0 -0
  15. {std → libs/std}/time.mi +0 -0
  16. {std → libs/std}/uuid.mi +0 -0
  17. scratch.hs +0 -18
  18. test/add.plum +87 -0
  19. test/aoc_2020_1.plum +25 -0
  20. test/aoc_2020_2.plum +56 -0
  21. test/aoc_2020_3.plum +62 -0
  22. test/aoc_2020_4.plum +41 -0
  23. sample.ks → test/sample.plum +184 -105
  24. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.editorconfig +0 -0
  25. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.gitattributes +0 -0
  26. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/ci.yml +0 -0
  27. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/fuzz.yml +0 -0
  28. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/lint.yml +0 -0
  29. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/release.yml +0 -0
  30. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.gitignore +0 -0
  31. {tree-sitter-kestrel → tooling/tree-sitter-plum}/.npmignore +0 -0
  32. {tree-sitter-kestrel → tooling/tree-sitter-plum}/Cargo.toml +0 -0
  33. {tree-sitter-kestrel → tooling/tree-sitter-plum}/LICENSE +0 -0
  34. {tree-sitter-kestrel → tooling/tree-sitter-plum}/Makefile +0 -0
  35. {tree-sitter-kestrel → tooling/tree-sitter-plum}/Package.swift +0 -0
  36. {tree-sitter-kestrel → tooling/tree-sitter-plum}/_queries/highlights.scm +0 -0
  37. {tree-sitter-kestrel → tooling/tree-sitter-plum}/_queries/tags.scm +0 -0
  38. {tree-sitter-kestrel → tooling/tree-sitter-plum}/binding.gyp +0 -0
  39. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/c/tree-sitter-kestrel.h +0 -0
  40. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/c/tree-sitter-kestrel.pc.in +0 -0
  41. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/go/binding.go +0 -0
  42. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/go/binding_test.go +0 -0
  43. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/go/go.mod +0 -0
  44. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/node/binding.cc +0 -0
  45. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/node/index.d.ts +0 -0
  46. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/node/index.js +0 -0
  47. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/__init__.py +0 -0
  48. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/__init__.pyi +0 -0
  49. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/binding.c +0 -0
  50. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/py.typed +0 -0
  51. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/rust/build.rs +0 -0
  52. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/rust/lib.rs +0 -0
  53. {tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/swift/TreeSitterKestrel/kestrel.h +0 -0
  54. {tree-sitter-kestrel → tooling/tree-sitter-plum}/grammar.js +0 -0
  55. {tree-sitter-kestrel → tooling/tree-sitter-plum}/package.json +0 -0
  56. {tree-sitter-kestrel → tooling/tree-sitter-plum}/prebuilds/darwin-arm64/tree-sitter-kestrel.node +0 -0
  57. {tree-sitter-kestrel → tooling/tree-sitter-plum}/pyproject.toml +0 -0
  58. {tree-sitter-kestrel → tooling/tree-sitter-plum}/readme.md +0 -0
  59. {tree-sitter-kestrel → tooling/tree-sitter-plum}/setup.py +0 -0
  60. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/grammar.json +0 -0
  61. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/node-types.json +0 -0
  62. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/parser.c +0 -0
  63. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/scanner.c +0 -0
  64. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/tree_sitter/alloc.h +0 -0
  65. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/tree_sitter/array.h +0 -0
  66. {tree-sitter-kestrel → tooling/tree-sitter-plum}/src/tree_sitter/parser.h +0 -0
  67. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/assign.txt +0 -0
  68. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/fn.txt +0 -0
  69. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/if.txt +0 -0
  70. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/match.txt +0 -0
  71. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/object.txt +0 -0
  72. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/record.txt +0 -0
  73. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/trait.txt +0 -0
  74. {tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/tuple.txt +0 -0
  75. {vscode-kestrel → tooling/vscode-plum}/.vscodeignore +0 -0
  76. {vscode-kestrel → tooling/vscode-plum}/CHANGELOG.md +0 -0
  77. tooling/vscode-plum/language-configuration.json +67 -0
  78. {vscode-kestrel → tooling/vscode-plum}/package-lock.json +0 -0
  79. {vscode-kestrel → tooling/vscode-plum}/package.json +9 -9
  80. {vscode-kestrel → tooling/vscode-plum}/readme.md +0 -0
  81. {vscode-kestrel → tooling/vscode-plum}/vsc-extension-quickstart.md +0 -0
  82. vscode-kestrel/language-configuration.json +0 -28
ab.rs DELETED
@@ -1,26 +0,0 @@
1
- use std::ops::Add;
2
-
3
- #[derive(Clone, Copy, Debug, PartialEq)]
4
- struct Point<T> {
5
- val: T,
6
- }
7
-
8
- impl<T: Add<Output = T>> Add for Point<T> {
9
- type Output = Self;
10
-
11
- fn add(self, b: Self) -> Self::Output {
12
- Self {
13
- val: self.val + b.val,
14
- }
15
- }
16
- }
17
-
18
- fn main() {
19
- let a = Point::<i32> { val: 1 };
20
- let b = Point::<i32> { val: 2 };
21
-
22
- let c = Point::<f32> { val: 1.0 };
23
-
24
- println!("{:?}", a + b);
25
- println!("{:?}", c == c);
26
- }
{std → libs/std}/bool.ks RENAMED
File without changes
{std → libs/std}/float.ks RENAMED
File without changes
{std → libs/std}/html.mi RENAMED
File without changes
{std → libs/std}/http.mi RENAMED
File without changes
{std → libs/std}/int.ks RENAMED
File without changes
{std → libs/std}/json.mi RENAMED
File without changes
{std → libs/std}/list.mi RENAMED
File without changes
{std → libs/std}/map.mi RENAMED
File without changes
{std → libs/std}/option.ks RENAMED
File without changes
{std → libs/std}/os.mi RENAMED
File without changes
{std → libs/std}/regex.mi RENAMED
File without changes
{std → libs/std}/result.ks RENAMED
File without changes
{std → libs/std}/str.mi RENAMED
File without changes
{std → libs/std}/time.mi RENAMED
File without changes
{std → libs/std}/uuid.mi RENAMED
File without changes
scratch.hs DELETED
@@ -1,18 +0,0 @@
1
- data.price?.take_if(|a| a != "")
2
- math.sqrt(math.pow(math.mod(1 + 2, 3), 2))
3
-
4
- if v == None
5
- error.Error
6
- else
7
- c * 20
8
-
9
- if v == None then
10
- error.Error
11
- else
12
- Some(c) := v
13
- c * 20
14
-
15
- match v is
16
- None -> return error.Error
17
- Some(c) ->
18
- return c * 20
test/add.plum ADDED
@@ -0,0 +1,87 @@
1
+ module test
2
+
3
+ import fs
4
+
5
+ add(a: Int, b: Int) -> Int =
6
+ a + b
7
+
8
+ give_42() -> Int =
9
+ 42
10
+
11
+ main() -> Int =
12
+ x1 = 2 * branch(4)
13
+ x2 = 3 * branch(9)
14
+ x3 = 5 * branch(11)
15
+ x1 + x2 + x3
16
+
17
+ branch(x: Int) -> Int
18
+ if x < 5
19
+ 0
20
+ else if x < 10
21
+ 1
22
+ else
23
+ 2
24
+
25
+ main() -> Int =
26
+ result = 0
27
+ for i in 0..10
28
+ result += i
29
+ if i == 4
30
+ continue
31
+ else i == 7
32
+ break
33
+
34
+ # Recursive
35
+ factorial(x: Int) -> Int =
36
+ if x < 2 then
37
+ x
38
+ else
39
+ x * factorial(x - 1)
40
+
41
+ # While
42
+ factorial(x: Int) -> Int =
43
+ result = 1
44
+ i = n
45
+ while i == 0
46
+ result *= i
47
+ i -= 1
48
+ result
49
+
50
+ # For
51
+ factorial(num: Int): Int =
52
+ result = 1
53
+ for i in 2..num
54
+ result *= i
55
+ result
56
+
57
+ # Reduce
58
+ factorial(num: Int) -> Int =
59
+ (1..num).reduce(\a, b -> a * b)
60
+
61
+ main() -> Bool
62
+ 5.squared() == 25
63
+
64
+ Int\squared(): Int =
65
+ self * self
66
+
67
+ main() -> Unit =
68
+ input = fs::readFile("./examples/test/demos/aoc2023/1.txt")
69
+ calibration_sum = 0
70
+ first_digit = 0
71
+ last_digit = 0
72
+ for i in 0..input.len()
73
+ c = input.charAt(i)
74
+ if c >= '0' && c <= '9'
75
+ if first_digit == 0
76
+ first_digit = (c - '0') as Int;
77
+ last_digit = (c - '0') as Int;
78
+ else
79
+ last_digit = (c - '0') as Int;
80
+ continue
81
+ if c == '\n'
82
+ calibration_value = first_digit * 10 + last_digit
83
+ calibration_sum += calibration_value
84
+ first_digit = 0
85
+ last_digit = 0
86
+ continue
87
+ printLn(calibration_sum)
test/aoc_2020_1.plum ADDED
@@ -0,0 +1,25 @@
1
+ module aoc2020_1
2
+
3
+ main() -> Unit =
4
+ input = fs::readFile!("./examples/test/demos/aoc2020/1.txt")
5
+ numbers = parseNumbers(input)
6
+ for i in 0..numbers.size
7
+ a = numbers.get!<u32>(i)
8
+ for j in 0..numbers.size
9
+ b = numbers.get!<u32>(j)
10
+ if a + b == 2020
11
+ printLn(a * b)
12
+ return
13
+
14
+ fn parseNumbers(input: Str) -> List<Int> =
15
+ numbers = listOf<Int>()
16
+ current_number = 0
17
+ for i in 0..input.len()
18
+ c = input.charAt(i)
19
+ if c >= '0' && c <= '9'
20
+ current_number *= 10
21
+ current_number += (c - '0') as Int
22
+ if c == '\n'
23
+ numbers.push!<u32>(current_number)
24
+ current_number = 0
25
+ numbers
test/aoc_2020_2.plum ADDED
@@ -0,0 +1,56 @@
1
+ Step =
2
+ | READ_MIN_OCCURANCES = 0
3
+ | READ_MAX_OCCURANCES = 1
4
+ | READ_CHAR_TO_COUNT = 2
5
+ | COUNT_OCCURANCES = 3
6
+
7
+ PasswordCheckState = {
8
+ step: Step
9
+ min_occurances: Int
10
+ max_occurances: Int
11
+ current_occurances: Int
12
+ char_to_counst: Int
13
+ }
14
+
15
+ initialCheckState() -> PasswordCheckState =
16
+ PasswordCheckState(
17
+ step: READ_MIN_OCCURANCES,
18
+ min_occurances: 0,
19
+ max_occurances: 0,
20
+ current_occurances: 0,
21
+ char_to_count: '\0',
22
+ )
23
+
24
+ main() -> Unit =
25
+ input = fs::readFile!("./examples/test/demos/aoc2020/2.txt")
26
+ valid_passwords_count = 0
27
+ state = initialCheckState()
28
+ for i in 0..input.len()
29
+ c = input.charAt(i)
30
+ if state.step == READ_MIN_OCCURANCES
31
+ if c == '-'
32
+ state.step = READ_MAX_OCCURANCES
33
+ continue
34
+ state.min_occurances *= 10
35
+ state.min_occurances += (c - '0') as Int
36
+ else if state.step == READ_MAX_OCCURANCES
37
+ if c == ' '
38
+ state.step = READ_CHAR_TO_COUNT
39
+ continue
40
+ state.max_occurances *= 10
41
+ state.max_occurances += (c - '0') as Int
42
+ else if state.step == READ_CHAR_TO_COUNT
43
+ state.char_to_count = c
44
+ # skip `${c}: `, (+1 will be skipped by loop)
45
+ i += 2
46
+ state.step = COUNT_OCCURANCES
47
+ continue
48
+ else if state.step == COUNT_OCCURANCES
49
+ if c == '\n'
50
+ if state.current_occurances >= state.min_occurances && state.current_occurances <= state.max_occurances
51
+ valid_passwords_count += 1
52
+ state = initialCheckState()
53
+ continue
54
+ if c == state.char_to_count
55
+ state.current_occurances += 1
56
+ writeLn(valid_passwords_count)
test/aoc_2020_3.plum ADDED
@@ -0,0 +1,62 @@
1
+ module aoc_2020_3
2
+
3
+ import cli
4
+ import fs
5
+
6
+ Tile =
7
+ | TREE = True
8
+ | EMPTY = False
9
+
10
+ slopeI() = 1
11
+ slopeJ() = 3
12
+
13
+ main() -> Unit =
14
+ let input = fs::read_file!("./examples/test/demos/aoc2020/3.txt");
15
+ defer input.free();
16
+ let map = Map::parse(input);
17
+ defer map.free();
18
+ let tree_count = 0;
19
+ let i = 0;
20
+ let j = 0;
21
+ loop {
22
+ i += slopeI();
23
+ j += slopeJ();
24
+ if i == map.rows.size {
25
+ break;
26
+ };
27
+ if map.get(i, j) == Tile::TREE {
28
+ tree_count += 1;
29
+ };
30
+ };
31
+ print_u32(tree_count);
32
+ puts("\n");
33
+
34
+ Map = (
35
+ rows: List(List(Tile))
36
+ )
37
+
38
+ Map\parse(input: String) -> Map =
39
+ rows = listOf(List<Tile>())
40
+ current_row = listOf<Tile>()
41
+ for i in 0..input.len()
42
+ c = input.char_at(i);
43
+ if c == '#'
44
+ current_row.push!(TREE)
45
+ if c == '.'
46
+ current_row.push!(EMPTY)
47
+ if c == '\n'
48
+ rows.push!(current_row)
49
+ current_row = listOf<Tile>()
50
+ Map(
51
+ rows: rows,
52
+ )
53
+
54
+ Map\get(i: u32, j: u32) -> Tile =
55
+ row = rows.get!(i);
56
+ *(row.at(j % row.size));
57
+
58
+ Map\free() -> Unit =
59
+ for i in 0..rows.size
60
+ row = rows.get!(i);
61
+ row.free();
62
+ rows.free();
test/aoc_2020_4.plum ADDED
@@ -0,0 +1,41 @@
1
+ module aoc2020_4
2
+
3
+ main() -> Result =
4
+ input = fs::readFile!("./examples/test/demos/aoc2020/4.txt")
5
+ valid_passwords = 0
6
+ passwords = StrCutter(input.toStr())
7
+ while passwords.rest.size > 0
8
+ has_byr = False
9
+ has_iyr = False
10
+ has_eyr = False
11
+ has_hgt = False
12
+ has_hcl = False
13
+ has_ecl = False
14
+ has_pid = False
15
+ passwords = passwords.cut_at("\n\n")
16
+ lines = StrCutter(passwords.piece)
17
+ while lines.rest.size > 0
18
+ lines = lines.cut_at("\n")
19
+ fields = StrCutter(lines.piece)
20
+ while fields.rest.size > 0
21
+ fields = fields.cut_at(" ")
22
+ field_parts = StrCutter(fields.piece).cut_at(":")
23
+ field_name = field_parts.piece;
24
+ field_value = field_parts.rest;
25
+ if field_name.equals("byr")
26
+ has_byr = True
27
+ else if field_name.equals("iyr")
28
+ has_iyr = True
29
+ else if field_name.equals("eyr")
30
+ has_eyr = True
31
+ else if field_name.equals("hgt")
32
+ has_hgt = True
33
+ else if field_name.equals("hcl")
34
+ has_hcl = True
35
+ else if field_name.equals("ecl")
36
+ has_ecl = true
37
+ else if field_name.equals("pid")
38
+ has_pid = True
39
+ if has_byr && has_iyr && has_eyr && has_hgt && has_hcl && has_ecl && has_pid
40
+ valid_passwords += 1
41
+ printLn(valid_passwords)
sample.ks → test/sample.plum RENAMED
@@ -6,31 +6,6 @@ Int.random()
6
6
  Float.random()
7
7
  Float.PI
8
8
 
9
- trait BinaryOp<T> {
10
- fn add(rhs: T) -> T
11
- fn sub(rhs: T) -> T
12
- fn mul(rhs: T) -> T
13
- fn div(rhs: T) -> T
14
- fn rem(rhs: T) -> T
15
- fn mod(rhs: T) -> T
16
- fn neg(rhs: T) -> T
17
- }
18
-
19
- trait BooleanOp<T> {
20
- fn not() -> T
21
- fn and(rhs: T) -> T
22
- fn or(rhs: T) -> T
23
- fn xor(rhs: T) -> T
24
- }
25
-
26
- trait Bitwise<T> {
27
- fn bitOr(rhs: T) -> T
28
- fn bitAnd(rhs: T) -> T
29
- fn bitXor(rhs: T) -> T
30
- fn shl(rhs: T) -> T
31
- fn shr(rhs: T) -> T
32
- }
33
-
34
9
  trait Comparable {
35
10
  fn compareTo(other: T) -> Compare
36
11
  }
@@ -92,31 +67,6 @@ record Cat(
92
67
  }
93
68
  }
94
69
 
95
- trait Error {}
96
- trait IOError: Error {}
97
- record FileReadError(file: File): IOError() {}
98
- record DatabaseError(source: DataSource): IOError() {}
99
-
100
- val lazyValue: Str by lazy {
101
- printLn("computed!")
102
- "Hello"
103
- }
104
-
105
- var name: Str by Delegates.observable("<no name>") {
106
- prop, old, new ->
107
- printLn("$old -> $new")
108
- }
109
-
110
- trait ClosedShape {
111
- fn area(): Int
112
- }
113
-
114
- record Rectangle(width: Int, height: Int) : ClosedShape {
115
- override fn area() = width * height
116
- }
117
-
118
- record Window(bounds: Rectangle) : ClosedShape by bounds
119
-
120
70
  record Response(
121
71
  body: Buffer = emptyBuffer(),
122
72
  headers: Map[Str, Str] = emptyMap(),
@@ -247,28 +197,6 @@ fn main() {
247
197
  }
248
198
  }
249
199
 
250
-
251
-
252
- birds = 3
253
- iguanas = 2
254
- total = addAndStringify birds iguanas
255
-
256
- main() =
257
- Stdout.line! "There are $(total) animals."
258
-
259
- addAndStringify(num1: Int, num2: Int) -> Str =
260
- (num1 + num2) |> Int.toStr()
261
-
262
- addAndStringify = \num1: Int, num2: Int -> Str
263
- Num.toStr (num1 + num2)
264
-
265
- val user = User(1, 2, 3)
266
-
267
- params = {"one" => 1, "two" => 2, "three" => 3}
268
- params.each do |k,v|
269
- puts("#{k}=#{v}")
270
- end
271
-
272
200
  lib LibM
273
201
  fun sqrt(x: LibC::Double) -> LibC::Double
274
202
  fun pow(x: LibC::Double, y: LibC::Double) -> LibC::Double
@@ -298,15 +226,12 @@ end
298
226
  primitive Str : Comparable, ToStr
299
227
  val data: Buffer
300
228
 
301
- fun get(i: Int) -> Char
229
+ get(i: Int) -> Char =
302
- return data.get(i)
230
+ data.get(i)
303
- end
304
231
 
305
- fun contains(search: Str) -> Bool
232
+ contains(search: Str) -> Bool
306
- end
307
233
 
308
- fun indexOf(sub: Str) -> Int
234
+ indexOf(sub: Str) -> Int
309
- end
310
235
 
311
236
  fun test(pattern: Regex) -> Bool
312
237
  end
@@ -386,25 +311,38 @@ record Response(a): Option(a, _)
386
311
 
387
312
  fun body(buf: Buffer) -> Response
388
313
  body = buf
314
+ if something > 0 then
315
+ Red
316
+ else if something == 0 then
317
+ Yellow
318
+ else
319
+ Green
320
+ end
389
321
  end
390
322
 
391
323
  fun status(v: Int) -> Response
392
324
  status = v
393
325
  end
326
+
327
+ fun delat()
328
+ User::create()
329
+ .name("John Doe")
330
+ .email("john@example.com")
331
+ .todo(Todo::create().title("Make pizza"))
332
+ .todo(Todo::create().title("Finish Toasty"))
333
+ .todo(Todo::create().title("Sleep"))
334
+ end
394
335
  end
395
336
 
396
- User::create()
337
+
397
- .name("John Doe")
338
+
398
- .email("john@example.com")
399
- .todo(Todo::create().title("Make pizza"))
400
- .todo(Todo::create().title("Finish Toasty"))
401
- .todo(Todo::create().title("Sleep"))
402
339
 
403
340
  trait Result(a, b) permits Ok(a), Err(b)
404
341
  fn ok() -> a
405
342
  fn err() -> b
406
343
  fn okOrElse(default: a) -> a
407
- end
344
+ fn isOk() -> Bool
345
+ fn isErr() -> Bool
408
346
 
409
347
  tuple Ok(a): Result(a, _)
410
348
  fn ok() -> a = self.0
@@ -438,39 +376,180 @@ tuple None(a): Option(_)
438
376
  Yellow
439
377
  else
440
378
  Green
379
+ fn stoplightStr(stoplightColor: Color) -> Str
380
+ match stoplightColor
381
+ Red -> "red"
382
+ Green -> "green"
383
+ Yellow -> "yellow"
384
+
385
+ fun stoplightStr(stoplightColor: Color) -> Str
386
+ when stoplightColor is
387
+ Red -> "red"
388
+ Green -> "green"
389
+ Yellow -> "yellow"
390
+ end
391
+ end
441
392
 
393
+ record Response(a): Option(a, _)
394
+ val body: Buffer = emptyBuffer()
395
+ val headers: Map(Str, Str) = emptyMap()
396
+ val status: Int = 0
397
+
398
+ fn header(k: Str, v: Str) -> Response =
399
+ headers.add(kv)
400
+ self
401
+
402
+ fn body(buf: Buffer) -> Response =
403
+ body = buf
404
+ self
405
+
406
+ fn status(v: Int) -> Response =
407
+ status = v
408
+ self
409
+
410
+ record Response(
411
+ body: Buffer = emptyBuffer()
412
+ headers: Map(Str, Str) = emptyMap()
413
+ status: Int = 0
414
+ ): Option(a, _)
415
+
416
+ fn header(k: Str, v: Str) -> Response =
417
+ headers.add(kv)
418
+ self
419
+
420
+ fn body(buf: Buffer) -> Response =
421
+ body = buf
422
+ self
423
+
424
+ fn status(v: Int) -> Response =
425
+ status = v
426
+ self
427
+
428
+
429
+ Response = {
430
+ body: Buffer = emptyBuffer()
431
+ headers: Map(Str, Str) = emptyMap()
432
+ status: Int = 0
433
+ }
434
+
442
- fn stoplightStr(stoplightColor: Color) -> Str =
435
+ Response\header(k: Str, v: Str) -> Response =
436
+ headers.add(kv)
437
+ self
438
+
439
+ Response\body(buf: Buffer) -> Response =
440
+ body = buf
441
+ self
442
+
443
+ Response\status(v: Int) -> Response =
444
+ status = v
445
+ self
446
+
443
- when stoplightColor is
447
+ main() -> Unit =
444
- Red -> "red"
448
+ printLn("123")
449
+
450
+ main() -> Int, Err =
451
+ Stdout.line! "There are $(total) animals."
452
+
453
+ Int\toStr() -> Str =
454
+ todo
455
+ # calculate to str
456
+
457
+ Int::random() -> Int =
458
+ 24
459
+
460
+ sub(arg1: Int, arg2: Int) -> Int =
461
+ local1 = arg1
462
+ local2 = arg2
463
+ local1 - local2
464
+
465
+ addAndStringify(num1: Int, num2: Int) -> Str =
466
+ (num1 + num2).toStr()
467
+
468
+ factorial(x: Int) -> Int =
469
+ if x < 2 then
470
+ x
471
+ else
472
+ x * factorial(x - 1)
473
+
474
+ Result(a, b) =
475
+ | Ok(a)
476
+ | Err(b)
477
+
478
+ ```
479
+ Checks whether the result is an `Ok` value
480
+
481
+ isOk(Ok(1)) # => True
482
+ isOk(Err(Nil)) # => False
483
+ ```
484
+ Result\isOk() -> Bool =
485
+ r! # will bubble back the result similar to try catch
486
+ o! # will bubble back the option/result
487
+ if self == Ok(v) then
488
+ True
489
+ else if self == Err(_) then
490
+ False
491
+
492
+ birds = 3
493
+ iguanas = 2
494
+ total = addAndStringify(birds, iguanas)
495
+
496
+ pluralize(singular: Str, plural: Str, count: Int) -> Str =
497
+ countstr = Num.toStr(count)
498
+ if count == 1 then
499
+ "$(countstr) $(singular)"
500
+ else
445
- Green -> "green"
501
+ "$(countstr) $(plural)"
446
- Yellow -> "yellow"
447
- end
448
502
 
503
+ pluralize_test(t: Test) -> Unit =
504
+ assert pluralize("cactus", "cacti", 1) == "1 cactus"
505
+ assert pluralize("cactus", "cacti", 2) == "2 cacti"
506
+
507
+ User = {
508
+ name: String
509
+ age: String
510
+ }
511
+
512
+ user = User(1, 2, 3)
513
+ params = {"one" => 1, "two" => 2, "three" => 3}
514
+
515
+ User\isAuthorized() -> Bool =
516
+ False
517
+
518
+ User\map(cb: (a: User) -> b) -> b =
519
+ cb(u)
520
+
449
- fn dddd(data: Option(Str)) -> Str =
521
+ name(data: Option(Str)) -> Str =
450
- if Some(v) = data then
522
+ if data == Some(v) then
451
523
  v.subString(0, 3)
452
524
  else if a == b then
453
525
  "123"
454
526
  else
455
527
  "1231"
456
528
 
457
- fn dddd(data: Option(Str)) -> Str =
529
+ delta(data: Option(Str)) -> Str =
458
- if Some(v) = data then
530
+ if data == Some(v)
459
531
  v.subString(0, 3)
460
- else if a == b then
532
+ else if a == b
461
533
  "123"
462
534
  else
463
- if a < 100 then
535
+ if a < 100
464
536
  printLn("Data")
465
537
  else
466
538
  println("No Data")
467
539
 
468
540
 
469
- names = ["Sam", "Lee", "Ari"]
541
+ data.price?.takeIf(\a -> a != "")
470
- names |> List.append("Jess")
542
+ (1 + 2).mod(3).pow(2).sqrt()
471
- names |> List.map(\num -> num * 2)
472
- List.map([1, 2, 3], \num -> num * 2)
473
543
 
544
+ if v == None
545
+ error.Error
474
- range data, 1, 2, do k,v
546
+ else if v == Some(c)
547
+ c * 20
548
+
475
- puts(k, v)
549
+ match v
550
+ None -> error.Error
551
+ Some(c) -> c * 20
552
+
553
+ names = ["Sam", "Lee", "Ari"]
476
- end
554
+ names.append("Jess")
555
+ names.map(\num -> num * 2)
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.editorconfig RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.gitattributes RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/ci.yml RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/fuzz.yml RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/lint.yml RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.github/workflows/release.yml RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.gitignore RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/.npmignore RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/Cargo.toml RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/LICENSE RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/Makefile RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/Package.swift RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/_queries/highlights.scm RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/_queries/tags.scm RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/binding.gyp RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/c/tree-sitter-kestrel.h RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/c/tree-sitter-kestrel.pc.in RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/go/binding.go RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/go/binding_test.go RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/go/go.mod RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/node/binding.cc RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/node/index.d.ts RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/node/index.js RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/__init__.py RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/__init__.pyi RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/binding.c RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/python/tree_sitter_kestrel/py.typed RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/rust/build.rs RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/rust/lib.rs RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/bindings/swift/TreeSitterKestrel/kestrel.h RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/grammar.js RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/package.json RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/prebuilds/darwin-arm64/tree-sitter-kestrel.node RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/pyproject.toml RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/readme.md RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/setup.py RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/grammar.json RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/node-types.json RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/parser.c RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/scanner.c RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/tree_sitter/alloc.h RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/tree_sitter/array.h RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/src/tree_sitter/parser.h RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/assign.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/fn.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/if.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/match.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/object.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/record.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/trait.txt RENAMED
File without changes
{tree-sitter-kestrel → tooling/tree-sitter-plum}/test/corpus/tuple.txt RENAMED
File without changes
{vscode-kestrel → tooling/vscode-plum}/.vscodeignore RENAMED
File without changes
{vscode-kestrel → tooling/vscode-plum}/CHANGELOG.md RENAMED
File without changes
tooling/vscode-plum/language-configuration.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "comments": {
3
+ // symbol used for single line comment. Remove this entry if your language does not support line comments
4
+ "lineComment": "//",
5
+ },
6
+ // symbols used as brackets
7
+ "brackets": [
8
+ [
9
+ "{",
10
+ "}"
11
+ ],
12
+ [
13
+ "[",
14
+ "]"
15
+ ],
16
+ [
17
+ "(",
18
+ ")"
19
+ ]
20
+ ],
21
+ // symbols that are auto closed when typing
22
+ "autoClosingPairs": [
23
+ [
24
+ "{",
25
+ "}"
26
+ ],
27
+ [
28
+ "[",
29
+ "]"
30
+ ],
31
+ [
32
+ "(",
33
+ ")"
34
+ ],
35
+ [
36
+ "\"",
37
+ "\""
38
+ ],
39
+ [
40
+ "'",
41
+ "'"
42
+ ]
43
+ ],
44
+ // symbols that can be used to surround a selection
45
+ "surroundingPairs": [
46
+ [
47
+ "{",
48
+ "}"
49
+ ],
50
+ [
51
+ "[",
52
+ "]"
53
+ ],
54
+ [
55
+ "(",
56
+ ")"
57
+ ],
58
+ [
59
+ "\"",
60
+ "\""
61
+ ],
62
+ [
63
+ "'",
64
+ "'"
65
+ ]
66
+ ]
67
+ }
{vscode-kestrel → tooling/vscode-plum}/package-lock.json RENAMED
File without changes
{vscode-kestrel → tooling/vscode-plum}/package.json RENAMED
@@ -1,7 +1,7 @@
1
1
  {
2
- "name": "kestrel",
2
+ "name": "plum",
3
- "displayName": "kestrel",
3
+ "displayName": "plum",
4
- "description": "Textmate grammar for kestrel",
4
+ "description": "Textmate grammar for plum",
5
5
  "version": "0.0.1",
6
6
  "engines": {
7
7
  "vscode": "^1.87.0"
@@ -12,21 +12,21 @@
12
12
  "contributes": {
13
13
  "languages": [
14
14
  {
15
- "id": "kestrel",
15
+ "id": "plum",
16
16
  "aliases": [
17
- "kestrel"
17
+ "plum"
18
18
  ],
19
19
  "extensions": [
20
- ".ks"
20
+ ".plum"
21
21
  ],
22
22
  "configuration": "./language-configuration.json"
23
23
  }
24
24
  ],
25
25
  "grammars": [
26
26
  {
27
- "language": "kestrel",
27
+ "language": "plum",
28
- "scopeName": "source.ks",
28
+ "scopeName": "source.plum",
29
- "path": "./syntaxes/kestrel.tmLanguage.json"
29
+ "path": "./syntaxes/plum.tmLanguage.json"
30
30
  }
31
31
  ]
32
32
  }
{vscode-kestrel → tooling/vscode-plum}/readme.md RENAMED
File without changes
{vscode-kestrel → tooling/vscode-plum}/vsc-extension-quickstart.md RENAMED
File without changes
vscode-kestrel/language-configuration.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "comments": {
3
- // symbol used for single line comment. Remove this entry if your language does not support line comments
4
- "lineComment": "//",
5
- },
6
- // symbols used as brackets
7
- "brackets": [
8
- ["{", "}"],
9
- ["[", "]"],
10
- ["(", ")"]
11
- ],
12
- // symbols that are auto closed when typing
13
- "autoClosingPairs": [
14
- ["{", "}"],
15
- ["[", "]"],
16
- ["(", ")"],
17
- ["\"", "\""],
18
- ["'", "'"]
19
- ],
20
- // symbols that can be used to surround a selection
21
- "surroundingPairs": [
22
- ["{", "}"],
23
- ["[", "]"],
24
- ["(", ")"],
25
- ["\"", "\""],
26
- ["'", "'"]
27
- ]
28
- }