~repos /plum

#treesitter#compiler#wasm

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

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


e9b4405d pyrossh

11 months ago
more stuff
.gitignore CHANGED
@@ -10,4 +10,8 @@ static/monaco-editor-workers/
10
10
  static/worker/
11
11
  node_modules
12
12
  *.vsix
13
- codegen
13
+ codegen
14
+
15
+ # Added by cargo
16
+
17
+ /target
Cargo.lock ADDED
@@ -0,0 +1,115 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.3"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "baz-tree-sitter-traversal"
16
+ version = "0.1.4"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "b2ae77a4ce9f364f49c87fdaf55d1ed79fb301003788acd26b64a46bda8f2a62"
19
+ dependencies = [
20
+ "tree-sitter",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "cc"
25
+ version = "1.2.5"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e"
28
+ dependencies = [
29
+ "shlex",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "memchr"
34
+ version = "2.7.4"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
37
+
38
+ [[package]]
39
+ name = "plum"
40
+ version = "0.1.0"
41
+ dependencies = [
42
+ "baz-tree-sitter-traversal",
43
+ "tree-sitter",
44
+ "tree-sitter-plum",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "regex"
49
+ version = "1.11.1"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
52
+ dependencies = [
53
+ "aho-corasick",
54
+ "memchr",
55
+ "regex-automata",
56
+ "regex-syntax",
57
+ ]
58
+
59
+ [[package]]
60
+ name = "regex-automata"
61
+ version = "0.4.9"
62
+ source = "registry+https://github.com/rust-lang/crates.io-index"
63
+ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
64
+ dependencies = [
65
+ "aho-corasick",
66
+ "memchr",
67
+ "regex-syntax",
68
+ ]
69
+
70
+ [[package]]
71
+ name = "regex-syntax"
72
+ version = "0.8.5"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
75
+
76
+ [[package]]
77
+ name = "shlex"
78
+ version = "1.3.0"
79
+ source = "registry+https://github.com/rust-lang/crates.io-index"
80
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
81
+
82
+ [[package]]
83
+ name = "streaming-iterator"
84
+ version = "0.1.9"
85
+ source = "registry+https://github.com/rust-lang/crates.io-index"
86
+ checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520"
87
+
88
+ [[package]]
89
+ name = "tree-sitter"
90
+ version = "0.24.5"
91
+ source = "registry+https://github.com/rust-lang/crates.io-index"
92
+ checksum = "8ac95b18f0f727aaaa012bd5179a1916706ee3ed071920fdbda738750b0c0bf5"
93
+ dependencies = [
94
+ "cc",
95
+ "regex",
96
+ "regex-syntax",
97
+ "streaming-iterator",
98
+ "tree-sitter-language",
99
+ ]
100
+
101
+ [[package]]
102
+ name = "tree-sitter-language"
103
+ version = "0.1.3"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "c199356c799a8945965bb5f2c55b2ad9d9aa7c4b4f6e587fe9dea0bc715e5f9c"
106
+
107
+ [[package]]
108
+ name = "tree-sitter-plum"
109
+ version = "0.1.0"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "09aba615e0c63f018b1e09436d442ddbad3d69417fbeb1e369108445e6456682"
112
+ dependencies = [
113
+ "cc",
114
+ "tree-sitter-language",
115
+ ]
Cargo.toml ADDED
@@ -0,0 +1,9 @@
1
+ [package]
2
+ name = "plum"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ baz-tree-sitter-traversal = "0.1.4"
8
+ tree-sitter = "0.24.5"
9
+ tree-sitter-plum = "0.1.0"
libs/std/bool.plum CHANGED
@@ -2,39 +2,36 @@ module std
2
2
 
3
3
  type Int
4
4
 
5
- add<Int>(b: Int) -> Int =
5
+ add<Int>(b: Int) -> Int = this + b
6
- return this + b
7
-
8
- sub<Int>(b: Int) -> Int =
6
+ sub<Int>(b: Int) -> Int = this - b
9
- return this - b
10
7
 
11
8
  enum Bool =
12
9
  | True
13
10
  | False
14
11
 
15
- fromStr(s: Str) -> Result[Bool, Err] =>
12
+ parseBool<Str>() -> Result(Bool, Err) =
16
- if s == "true"
13
+ if s == "true"
17
- True
14
+ True
18
- else if s == "false"
15
+ else if s == "false"
19
- False
16
+ False
20
- else
17
+ else
21
- Err("could not parse bool from '{s}'")
18
+ Err("could not parse bool from '{s}'")
22
-
19
+
23
- and(self, o: Bool) -> Bool =>
20
+ and<Bool>(o: Bool) -> Bool =
24
- match this, o
21
+ match this, o
25
- True, True => True
22
+ True, True => True
26
- True, False => False
23
+ True, False => False
27
- False, True => False
24
+ False, True => False
28
- False, False => False
25
+ False, False => False
29
-
26
+
30
- or(self, o: Bool) -> Bool =>
27
+ or<Bool>(o: Bool) -> Bool =
31
- match this, o
28
+ match this, o
32
- True, True => True
29
+ True, True => True
33
- True, False => True
30
+ True, False => True
34
- False, True => True
31
+ False, True => True
35
- False, False => False
32
+ False, False => False
36
-
33
+
37
- toStr(self) -> Str =>
34
+ toStr<Bool>() -> Str =
38
- match this
35
+ match this
39
- True => "True"
36
+ True => "True"
40
- False => "False"
37
+ False => "False"
src/compiler.rs DELETED
File without changes
src/main.rs ADDED
@@ -0,0 +1,58 @@
1
+ use tree_sitter;
2
+ use tree_sitter_plum;
3
+
4
+ fn main() {
5
+ let code = r#"
6
+ module std
7
+
8
+ import std/int
9
+ import std/str
10
+
11
+ PI = 3.14
12
+ MSG = "Hello World"
13
+ SUM = 1 + {{2 * 3} / 4}
14
+ ENABLED = !False
15
+
16
+ # Animal is a set of behavior of every animal species
17
+ trait Animal =
18
+ speak() -> Str
19
+
20
+ # Cat is an animal that meows always
21
+ type Cat(Animal, IToStr) =
22
+ name: Str
23
+ age: Int
24
+
25
+ withName<Cat>(name: Str) -> Cat =
26
+ Cat(name: name, age: self.age)
27
+
28
+ withAge<Cat>(age: Int) -> Cat =
29
+ Cat(name: self.name, age: age)
30
+
31
+ speak<Cat>() -> Str =
32
+ "meow"
33
+
34
+ toStr<Cat>() -> Str =
35
+ for i in 0..10
36
+ printLn("delta")
37
+ if dog > 1
38
+ printLn("Hellow")
39
+ else
40
+ printLn("New")
41
+ "Cat({self.name}, {self.age})"
42
+
43
+ main() =
44
+ printLn("Hello world")
45
+
46
+ "#;
47
+ let mut parser = tree_sitter::Parser::new();
48
+ let language = tree_sitter_plum::LANGUAGE;
49
+ parser
50
+ .set_language(&language.into())
51
+ .expect("Error loading plum parser");
52
+ let tree = parser.parse(code, None).unwrap();
53
+ assert!(!tree.root_node().has_error());
54
+ let mut cursor = tree.root_node().walk();
55
+ for item in tree.root_node().children(&mut cursor) {
56
+ println!("kind:{} {}", item.kind(), item.to_sexp());
57
+ }
58
+ }
test/sample.plum CHANGED
@@ -256,4 +256,19 @@ main() =
256
256
  names.append("Jess")
257
257
  names
258
258
  .filter({ it == "Sam" })
259
- .map({ it * 2 })
259
+ .map({ it * 2 })
260
+
261
+ main() =
262
+ sum = 1 + {{2 * 3} / 4}
263
+ enabled = !False
264
+ open = {count > 10} && {enabled == True} || {debug == False}
265
+ countries_list = listOf("US", "INDIA", "CANADA")
266
+ list_ints = listOf(1, 2, 3)
267
+ nested_list_ints = listOf(listOf(1), listOf(2), listOf(3))
268
+ country_codes = mapOf(
269
+ "in" => "INDIA",
270
+ "us" => "United States",
271
+ "ca" => "Canada"
272
+ )
273
+ map_ints = mapOf("a" => 1, "b" => 2)
274
+ nested_map_ints = mapOf("a" => 1, "b" => mapOf("c" => 3, "d" => 4))
tooling/tree-sitter-plum/grammar.js CHANGED
@@ -170,16 +170,16 @@ module.exports = grammar({
170
170
 
171
171
  const: ($) =>
172
172
  seq(
173
- field("left", commaSep1($.const_identifier)),
173
+ $.const_identifier,
174
174
  "=",
175
- field("right", commaSep1($.expression)),
175
+ $.expression,
176
176
  ),
177
177
 
178
178
  assign: ($) =>
179
179
  seq(
180
- field("left", commaSep1($.var_identifier)),
180
+ commaSep1($.var_identifier),
181
181
  "=",
182
- field("right", commaSep1($.expression)),
182
+ commaSep1($.expression),
183
183
  ),
184
184
  try: ($) => prec.right(seq("try", optional($.fn_call))),
185
185
  assert: ($) => seq("assert", $.expression),
tooling/tree-sitter-plum/src/grammar.json CHANGED
Binary file
tooling/tree-sitter-plum/src/node-types.json CHANGED
Binary file
tooling/tree-sitter-plum/src/parser.c CHANGED
Binary file
tooling/tree-sitter-plum/test/aa.plum CHANGED
@@ -9,11 +9,11 @@ SUM = 1 + {{2 * 3} / 4}
9
9
  ENABLED = !False
10
10
 
11
11
  # Animal is a set of behavior of every animal species
12
- trait Animal =
12
+ trait IAnimal =
13
13
  speak() -> Str
14
14
 
15
15
  # Cat is an animal that meows always
16
- type Cat(Animal, ToStr) =
16
+ type Cat(IAnimal, IToStr) =
17
17
  name: Str
18
18
  age: Int
19
19
 
tooling/tree-sitter-plum/test/corpus/type.txt CHANGED
@@ -10,6 +10,9 @@ type Cat(Stringable) =
10
10
  name: Str
11
11
  age: Int
12
12
 
13
+ init<Cat>(name: Str) -> Cat =
14
+ Cat(name: name, age: 0)
15
+
13
16
  withName<Cat>(name: Str) -> Cat =
14
17
  Cat(name: name, age: 0)
15
18