~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
59e3de68
—
pyrossh 11 months ago
fix traits
- tooling/tree-sitter-plum/grammar.js +5 -4
- tooling/tree-sitter-plum/queries/plum/highlights.scm +6 -5
- tooling/tree-sitter-plum/src/grammar.json +0 -0
- tooling/tree-sitter-plum/src/node-types.json +0 -0
- tooling/tree-sitter-plum/src/parser.c +0 -0
- tooling/tree-sitter-plum/test/aa.plum +12 -2
- tooling/tree-sitter-plum/test/corpus/trait.txt +42 -0
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -103,16 +103,17 @@ module.exports = grammar({
|
|
|
103
103
|
"trait",
|
|
104
104
|
field("name", $.type_identifier),
|
|
105
105
|
field("generics", optional($.generics)),
|
|
106
|
+
"=",
|
|
107
|
+
$._indent,
|
|
106
|
-
field("fields",
|
|
108
|
+
field("fields", optional(repeat(alias($.trait_field, $.field)))),
|
|
109
|
+
$._dedent,
|
|
107
110
|
),
|
|
108
111
|
|
|
109
112
|
trait_field: ($) =>
|
|
110
113
|
seq(
|
|
111
|
-
"fn",
|
|
112
114
|
field("name", $.fn_identifier),
|
|
113
115
|
field("params", seq("(", optional(commaSep1($.param)), ")")),
|
|
114
|
-
":",
|
|
115
|
-
field("returns", optional($.return_type)),
|
|
116
|
+
field("returns", optional(seq("->", $.return_type))),
|
|
116
117
|
),
|
|
117
118
|
|
|
118
119
|
param: ($) =>
|
tooling/tree-sitter-plum/queries/plum/highlights.scm
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
(type_identifier) @type
|
|
2
|
+
(fn_identifier) @function
|
|
2
3
|
|
|
3
4
|
(fn
|
|
4
|
-
(
|
|
5
|
+
(fn_identifier) @function)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
(fn_call
|
|
7
|
-
|
|
8
|
+
(fn_identifier) @function)
|
|
8
9
|
|
|
9
10
|
(var_identifier) @variable
|
|
11
|
+
(self) @variable.builtin
|
|
10
12
|
(integer) @constant.numeric.integer
|
|
11
13
|
(float) @constant.numeric.float
|
|
12
14
|
(comment) @comment
|
|
13
15
|
(string) @string
|
|
14
16
|
(escape_sequence) @constant.character.escape
|
|
15
|
-
(self) @variable.builtin
|
|
16
17
|
|
|
17
18
|
[
|
|
18
19
|
"("
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
] @operator
|
|
56
57
|
|
|
57
58
|
[
|
|
59
|
+
"import"
|
|
58
60
|
"module"
|
|
59
61
|
"type"
|
|
60
62
|
"enum"
|
|
@@ -81,7 +83,6 @@
|
|
|
81
83
|
; "panic"
|
|
82
84
|
] @keyword.control.return
|
|
83
85
|
|
|
84
|
-
; "import" @keyword
|
|
85
86
|
; "match" @keyword
|
|
86
87
|
; "as" @keyword
|
|
87
88
|
; "is" @keyword
|
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
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
module std
|
|
2
2
|
|
|
3
|
+
import std/int
|
|
4
|
+
import std/str
|
|
5
|
+
|
|
6
|
+
# Animal is a behavior of every animal
|
|
7
|
+
trait Animal =
|
|
8
|
+
speak() -> Str
|
|
9
|
+
|
|
3
10
|
# Cat is an animal that meows always
|
|
4
|
-
type Cat(ToStr) =
|
|
11
|
+
type Cat(Animal, ToStr) =
|
|
5
12
|
name: Str
|
|
6
13
|
age: Int
|
|
7
14
|
|
|
@@ -11,6 +18,9 @@ withName<Cat>(name: Str) -> Cat =
|
|
|
11
18
|
withAge<Cat>(age: Int) -> Cat =
|
|
12
19
|
Cat(name: self.name, age: age)
|
|
13
20
|
|
|
21
|
+
speak<Cat>() -> Str =
|
|
22
|
+
"meow"
|
|
23
|
+
|
|
14
24
|
toStr<Cat>() -> Str =
|
|
15
25
|
for i in 0..10
|
|
16
26
|
printLn("delta")
|
|
@@ -18,7 +28,7 @@ toStr<Cat>() -> Str =
|
|
|
18
28
|
printLn("Hellow")
|
|
19
29
|
else
|
|
20
30
|
printLn("New")
|
|
21
|
-
|
|
31
|
+
"Cat({self.name}, {self.age})"
|
|
22
32
|
|
|
23
33
|
main() =
|
|
24
34
|
printLn("Hello world")
|
tooling/tree-sitter-plum/test/corpus/trait.txt
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
trait
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
trait ToStr =
|
|
6
|
+
toStr() -> Str
|
|
7
|
+
|
|
8
|
+
trait Animal =
|
|
9
|
+
speak() -> Str
|
|
10
|
+
legs() -> Int
|
|
11
|
+
walk()
|
|
12
|
+
eat(food: FoodType) -> Unit
|
|
13
|
+
|
|
14
|
+
--------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
(source
|
|
17
|
+
(trait
|
|
18
|
+
(type_identifier)
|
|
19
|
+
(field
|
|
20
|
+
(fn_identifier)
|
|
21
|
+
(return_type
|
|
22
|
+
(type_identifier))))
|
|
23
|
+
(trait
|
|
24
|
+
(type_identifier)
|
|
25
|
+
(field
|
|
26
|
+
(fn_identifier)
|
|
27
|
+
(return_type
|
|
28
|
+
(type_identifier)))
|
|
29
|
+
(field
|
|
30
|
+
(fn_identifier)
|
|
31
|
+
(return_type
|
|
32
|
+
(type_identifier)))
|
|
33
|
+
(field
|
|
34
|
+
(fn_identifier))
|
|
35
|
+
(field
|
|
36
|
+
(fn_identifier)
|
|
37
|
+
(param
|
|
38
|
+
(var_identifier)
|
|
39
|
+
(type
|
|
40
|
+
(type_identifier)))
|
|
41
|
+
(return_type
|
|
42
|
+
(type_identifier)))))
|