~repos /plum

#treesitter#compiler#wasm

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

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


1910cfc3 pyrossh

11 months ago
fix tests
tooling/tree-sitter-plum/grammar.js CHANGED
@@ -64,7 +64,7 @@ module.exports = grammar({
64
64
  seq(
65
65
  optional(seq("module", $.module)),
66
66
  repeat($.import),
67
- repeat(choice($.class, $.trait, $.enum, $.fn, $.assign)),
67
+ repeat(choice($.class, $.trait, $.enum, $.fn)),
68
68
  ),
69
69
 
70
70
  module: ($) => $.var_identifier,
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/corpus/assign.txt CHANGED
@@ -1,77 +1,82 @@
1
1
  ================================================================================
2
- assign - Expression
2
+ assign
3
3
  ================================================================================
4
4
 
5
+ main() =
5
- sum = 1 + {{2 * 3} / 4}
6
+ sum = 1 + {{2 * 3} / 4}
7
+ enabled = !False
8
+ open = {count > 10} && {enabled == True} || {debug == False}
9
+ countries_list = listOf("US", "INDIA", "CANADA")
10
+ list_ints = listOf(1, 2, 3)
11
+ nested_list_ints = listOf(listOf(1), listOf(2), listOf(3))
12
+ country_codes = mapOf(
13
+ "in" => "INDIA",
14
+ "us" => "United States",
15
+ "ca" => "Canada"
16
+ )
17
+ map_ints = mapOf("a" => 1, "b" => 2)
18
+ nested_map_ints = mapOf("a" => 1, "b" => mapOf("c" => 3, "d" => 4))
6
19
 
7
20
  --------------------------------------------------------------------------------
8
21
 
9
22
  (source
23
+ (fn
24
+ (fn_identifier)
25
+ (body
10
- (assign
26
+ (assign
11
- (var_identifier)
27
+ (var_identifier)
12
- (expression
28
+ (expression
13
- (primary_expression
14
- (binary_operator
15
- (primary_expression
16
- (integer))
17
29
  (primary_expression
30
+ (binary_operator
31
+ (primary_expression
32
+ (integer))
33
+ (primary_expression
18
- (parenthesized_expression
34
+ (parenthesized_expression
19
- (expression
35
+ (expression
20
- (primary_expression
21
- (binary_operator
22
36
  (primary_expression
37
+ (binary_operator
38
+ (primary_expression
23
- (parenthesized_expression
39
+ (parenthesized_expression
24
- (expression
40
+ (expression
25
- (primary_expression
26
- (binary_operator
27
- (primary_expression
28
- (integer))
29
41
  (primary_expression
42
+ (binary_operator
43
+ (primary_expression
44
+ (integer))
45
+ (primary_expression
30
- (integer)))))))
46
+ (integer)))))))
31
- (primary_expression
47
+ (primary_expression
32
- (integer))))))))))))
48
+ (integer)))))))))))
33
-
34
- ================================================================================
35
- assign - Not
36
- ================================================================================
37
-
38
- enabled = !False
39
-
40
- --------------------------------------------------------------------------------
41
-
42
- (source
43
- (assign
49
+ (assign
44
- (var_identifier)
50
+ (var_identifier)
45
- (expression
46
- (not_operator
47
51
  (expression
52
+ (not_operator
53
+ (expression
48
- (primary_expression
54
+ (primary_expression
49
- (type_identifier)))))))
55
+ (type_identifier))))))
50
-
51
- ================================================================================
52
- assign - Boolean expression
53
- ================================================================================
54
-
55
- open = {count > 10} && {enabled == True} || {debug == False}
56
-
57
- --------------------------------------------------------------------------------
58
-
59
- (source
60
- (assign
56
+ (assign
61
- (var_identifier)
57
+ (var_identifier)
62
- (expression
63
- (boolean_operator
64
58
  (expression
65
59
  (boolean_operator
66
60
  (expression
61
+ (boolean_operator
62
+ (expression
67
- (primary_expression
63
+ (primary_expression
68
- (parenthesized_expression
64
+ (parenthesized_expression
69
- (expression
65
+ (expression
70
- (comparison_operator
66
+ (comparison_operator
71
- (primary_expression
67
+ (primary_expression
72
- (var_identifier))
68
+ (var_identifier))
73
- (primary_expression
69
+ (primary_expression
74
- (integer)))))))
70
+ (integer)))))))
71
+ (expression
72
+ (primary_expression
73
+ (parenthesized_expression
74
+ (expression
75
+ (comparison_operator
76
+ (primary_expression
77
+ (var_identifier))
78
+ (primary_expression
79
+ (type_identifier)))))))))
75
80
  (expression
76
81
  (primary_expression
77
82
  (parenthesized_expression
@@ -80,217 +85,180 @@ open = {count > 10} && {enabled == True} || {debug == False}
80
85
  (primary_expression
81
86
  (var_identifier))
82
87
  (primary_expression
83
- (type_identifier)))))))))
88
+ (type_identifier))))))))))
89
+ (assign
90
+ (var_identifier)
84
91
  (expression
85
92
  (primary_expression
93
+ (fn_call
94
+ (fn_identifier)
86
- (parenthesized_expression
95
+ (argument_list
87
- (expression
96
+ (expression
88
- (comparison_operator
89
97
  (primary_expression
98
+ (string
90
- (var_identifier))
99
+ (string_start)
100
+ (string_content)
101
+ (string_end))))
102
+ (expression
91
103
  (primary_expression
92
- (type_identifier)))))))))))
93
-
94
- ================================================================================
95
- assign - listOf
96
- ================================================================================
97
-
98
- countries_list = listOf("US", "INDIA", "CANADA")
99
- list_ints = listOf(1, 2, 3)
100
- nested_list_ints = listOf(listOf(1), listOf(2), listOf(3))
101
-
102
- --------------------------------------------------------------------------------
103
-
104
- (source
105
- (assign
106
- (var_identifier)
107
- (expression
108
- (primary_expression
109
- (fn_call
110
- (fn_identifier)
111
- (argument_list
112
- (expression
113
- (primary_expression
114
- (string
115
- (string_start)
116
- (string_content)
117
- (string_end))))
118
- (expression
119
- (primary_expression
120
- (string
121
- (string_start)
122
- (string_content)
123
- (string_end))))
124
- (expression
125
- (primary_expression
126
- (string
127
- (string_start)
128
- (string_content)
129
- (string_end)))))))))
130
- (assign
131
- (var_identifier)
132
- (expression
133
- (primary_expression
134
- (fn_call
135
- (fn_identifier)
136
- (argument_list
137
- (expression
138
- (primary_expression
139
- (integer)))
140
- (expression
141
- (primary_expression
142
- (integer)))
143
- (expression
144
- (primary_expression
145
- (integer))))))))
146
- (assign
147
- (var_identifier)
148
- (expression
149
- (primary_expression
150
- (fn_call
151
- (fn_identifier)
152
- (argument_list
153
- (expression
154
- (primary_expression
155
- (fn_call
156
- (fn_identifier)
157
- (argument_list
158
- (expression
159
- (primary_expression
160
- (integer)))))))
161
- (expression
162
- (primary_expression
163
- (fn_call
164
- (fn_identifier)
165
- (argument_list
166
- (expression
167
- (primary_expression
168
- (integer)))))))
169
- (expression
170
- (primary_expression
171
- (fn_call
172
- (fn_identifier)
173
- (argument_list
174
- (expression
175
- (primary_expression
176
- (integer)))))))))))))
177
-
178
- ================================================================================
179
- assign - mapOf
180
- ================================================================================
181
-
182
- country_codes = mapOf(
183
- "in" => "INDIA",
184
- "us" => "United States",
185
- "ca" => "Canada"
186
- )
187
- map_ints = mapOf("a" => 1, "b" => 2)
188
- nested_map_ints = mapOf("a" => 1, "b" => mapOf("c" => 3, "d" => 4))
189
-
190
- --------------------------------------------------------------------------------
191
-
192
- (source
193
- (assign
194
- (var_identifier)
195
- (expression
196
- (primary_expression
197
- (fn_call
198
- (fn_identifier)
199
- (argument_list
200
- (pair_argument
201
- (string
202
- (string_start)
203
- (string_content)
204
- (string_end))
205
- (expression
206
- (primary_expression
104
+ (string
105
+ (string_start)
106
+ (string_content)
107
+ (string_end))))
108
+ (expression
109
+ (primary_expression
110
+ (string
111
+ (string_start)
112
+ (string_content)
113
+ (string_end)))))))))
114
+ (assign
115
+ (var_identifier)
116
+ (expression
117
+ (primary_expression
118
+ (fn_call
119
+ (fn_identifier)
120
+ (argument_list
121
+ (expression
122
+ (primary_expression
123
+ (integer)))
124
+ (expression
125
+ (primary_expression
126
+ (integer)))
127
+ (expression
128
+ (primary_expression
129
+ (integer))))))))
130
+ (assign
131
+ (var_identifier)
132
+ (expression
133
+ (primary_expression
134
+ (fn_call
135
+ (fn_identifier)
136
+ (argument_list
137
+ (expression
138
+ (primary_expression
139
+ (fn_call
140
+ (fn_identifier)
141
+ (argument_list
142
+ (expression
143
+ (primary_expression
144
+ (integer)))))))
145
+ (expression
146
+ (primary_expression
147
+ (fn_call
148
+ (fn_identifier)
149
+ (argument_list
150
+ (expression
151
+ (primary_expression
152
+ (integer)))))))
153
+ (expression
154
+ (primary_expression
155
+ (fn_call
156
+ (fn_identifier)
157
+ (argument_list
158
+ (expression
159
+ (primary_expression
160
+ (integer))))))))))))
161
+ (assign
162
+ (var_identifier)
163
+ (expression
164
+ (primary_expression
165
+ (fn_call
166
+ (fn_identifier)
167
+ (argument_list
168
+ (pair_argument
207
169
  (string
208
170
  (string_start)
209
171
  (string_content)
172
+ (string_end))
173
+ (expression
174
+ (primary_expression
175
+ (string
176
+ (string_start)
177
+ (string_content)
210
- (string_end)))))
178
+ (string_end)))))
211
- (pair_argument
179
+ (pair_argument
212
- (string
213
- (string_start)
214
- (string_content)
215
- (string_end))
216
- (expression
217
- (primary_expression
218
180
  (string
219
181
  (string_start)
220
182
  (string_content)
183
+ (string_end))
184
+ (expression
185
+ (primary_expression
186
+ (string
187
+ (string_start)
188
+ (string_content)
221
- (string_end)))))
189
+ (string_end)))))
222
- (pair_argument
190
+ (pair_argument
223
- (string
224
- (string_start)
225
- (string_content)
226
- (string_end))
227
- (expression
228
- (primary_expression
229
191
  (string
230
192
  (string_start)
231
193
  (string_content)
232
- (string_end))))))))))
233
- (assign
234
- (var_identifier)
235
- (expression
236
- (primary_expression
237
- (fn_call
238
- (fn_identifier)
239
- (argument_list
240
- (pair_argument
241
- (string
242
- (string_start)
243
- (string_content)
244
- (string_end))
245
- (expression
246
- (primary_expression
247
- (integer))))
248
- (pair_argument
249
- (string
250
- (string_start)
251
- (string_content)
252
- (string_end))
253
- (expression
254
- (primary_expression
255
- (integer)))))))))
256
- (assign
257
- (var_identifier)
258
- (expression
259
- (primary_expression
260
- (fn_call
261
- (fn_identifier)
262
- (argument_list
263
- (pair_argument
264
- (string
265
- (string_start)
266
- (string_content)
267
- (string_end))
268
- (expression
269
- (primary_expression
270
- (integer))))
271
- (pair_argument
272
- (string
273
- (string_start)
274
- (string_content)
275
- (string_end))
276
- (expression
277
- (primary_expression
278
- (fn_call
279
- (fn_identifier)
280
- (argument_list
281
- (pair_argument
282
- (string
283
- (string_start)
284
- (string_content)
285
- (string_end))
286
- (expression
287
- (primary_expression
288
- (integer))))
289
- (pair_argument
290
- (string
291
- (string_start)
292
- (string_content)
293
- (string_end))
294
- (expression
295
- (primary_expression
296
- (integer)))))))))))))))
194
+ (string_end))
195
+ (expression
196
+ (primary_expression
197
+ (string
198
+ (string_start)
199
+ (string_content)
200
+ (string_end))))))))))
201
+ (assign
202
+ (var_identifier)
203
+ (expression
204
+ (primary_expression
205
+ (fn_call
206
+ (fn_identifier)
207
+ (argument_list
208
+ (pair_argument
209
+ (string
210
+ (string_start)
211
+ (string_content)
212
+ (string_end))
213
+ (expression
214
+ (primary_expression
215
+ (integer))))
216
+ (pair_argument
217
+ (string
218
+ (string_start)
219
+ (string_content)
220
+ (string_end))
221
+ (expression
222
+ (primary_expression
223
+ (integer)))))))))
224
+ (assign
225
+ (var_identifier)
226
+ (expression
227
+ (primary_expression
228
+ (fn_call
229
+ (fn_identifier)
230
+ (argument_list
231
+ (pair_argument
232
+ (string
233
+ (string_start)
234
+ (string_content)
235
+ (string_end))
236
+ (expression
237
+ (primary_expression
238
+ (integer))))
239
+ (pair_argument
240
+ (string
241
+ (string_start)
242
+ (string_content)
243
+ (string_end))
244
+ (expression
245
+ (primary_expression
246
+ (fn_call
247
+ (fn_identifier)
248
+ (argument_list
249
+ (pair_argument
250
+ (string
251
+ (string_start)
252
+ (string_content)
253
+ (string_end))
254
+ (expression
255
+ (primary_expression
256
+ (integer))))
257
+ (pair_argument
258
+ (string
259
+ (string_start)
260
+ (string_content)
261
+ (string_end))
262
+ (expression
263
+ (primary_expression
264
+ (integer)))))))))))))))))
tooling/tree-sitter-plum/test/corpus/for.txt CHANGED
@@ -13,7 +13,7 @@ main() =
13
13
  (fn_identifier)
14
14
  (body
15
15
  (for
16
- (identifier)
16
+ (var_identifier)
17
17
  (primary_expression
18
18
  (binary_operator
19
19
  (primary_expression
@@ -23,7 +23,7 @@ main() =
23
23
  (body
24
24
  (primary_expression
25
25
  (fn_call
26
- (identifier)
26
+ (fn_identifier)
27
27
  (argument_list
28
28
  (expression
29
29
  (primary_expression
tooling/tree-sitter-plum/test/corpus/literals.txt CHANGED
@@ -3,7 +3,7 @@ literals
3
3
  ================================================================================
4
4
 
5
5
  main() =
6
- startYear = 2101
6
+ start_year = 2101
7
7
  a = +123
8
8
  b = -111
9
9
  c = 456
@@ -18,9 +18,9 @@ main() =
18
18
  a = True
19
19
  b = False
20
20
  c = Nil
21
- count = counter(10)
22
21
  sum = 1 + {{2 * 3} / 4}
22
+ # count = counter(10)
23
- "e = {1 + 2}.mod(3).pow(2).sqrt()"
23
+ # e = {1 + 2}.mod(3).pow(2).sqrt()
24
24
 
25
25
  --------------------------------------------------------------------------------
26
26
 
@@ -29,72 +29,72 @@ main() =
29
29
  (fn_identifier)
30
30
  (body
31
31
  (assign
32
- (identifier)
32
+ (var_identifier)
33
33
  (expression
34
34
  (primary_expression
35
35
  (integer))))
36
36
  (assign
37
- (identifier)
37
+ (var_identifier)
38
38
  (expression
39
39
  (primary_expression
40
40
  (unary_operator
41
41
  (primary_expression
42
42
  (integer))))))
43
43
  (assign
44
- (identifier)
44
+ (var_identifier)
45
45
  (expression
46
46
  (primary_expression
47
47
  (unary_operator
48
48
  (primary_expression
49
49
  (integer))))))
50
50
  (assign
51
- (identifier)
51
+ (var_identifier)
52
52
  (expression
53
53
  (primary_expression
54
54
  (integer))))
55
55
  (assign
56
- (identifier)
56
+ (var_identifier)
57
57
  (expression
58
58
  (primary_expression
59
59
  (integer))))
60
60
  (assign
61
- (identifier)
61
+ (var_identifier)
62
62
  (expression
63
63
  (primary_expression
64
64
  (integer))))
65
65
  (primary_expression
66
66
  (integer))
67
67
  (assign
68
- (identifier)
68
+ (var_identifier)
69
69
  (expression
70
70
  (primary_expression
71
71
  (float))))
72
72
  (assign
73
- (identifier)
73
+ (var_identifier)
74
74
  (expression
75
75
  (primary_expression
76
76
  (unary_operator
77
77
  (primary_expression
78
78
  (float))))))
79
79
  (assign
80
- (identifier)
80
+ (var_identifier)
81
81
  (expression
82
82
  (primary_expression
83
83
  (unary_operator
84
84
  (primary_expression
85
85
  (float))))))
86
86
  (assign
87
- (identifier)
87
+ (var_identifier)
88
88
  (expression
89
89
  (primary_expression
90
90
  (float))))
91
91
  (assign
92
- (identifier)
92
+ (var_identifier)
93
93
  (expression
94
94
  (primary_expression
95
95
  (float))))
96
96
  (assign
97
- (identifier)
97
+ (var_identifier)
98
98
  (expression
99
99
  (primary_expression
100
100
  (string
@@ -102,32 +102,22 @@ main() =
102
102
  (string_content)
103
103
  (string_end)))))
104
104
  (assign
105
- (identifier)
105
+ (var_identifier)
106
106
  (expression
107
107
  (primary_expression
108
108
  (type_identifier))))
109
109
  (assign
110
- (identifier)
110
+ (var_identifier)
111
111
  (expression
112
112
  (primary_expression
113
113
  (type_identifier))))
114
114
  (assign
115
- (identifier)
115
+ (var_identifier)
116
116
  (expression
117
117
  (primary_expression
118
118
  (type_identifier))))
119
119
  (assign
120
- (identifier)
120
+ (var_identifier)
121
- (expression
122
- (primary_expression
123
- (fn_call
124
- (identifier)
125
- (argument_list
126
- (expression
127
- (primary_expression
128
- (integer))))))))
129
- (assign
130
- (identifier)
131
121
  (expression
132
122
  (primary_expression
133
123
  (binary_operator
@@ -149,8 +139,5 @@ main() =
149
139
  (integer)))))))
150
140
  (primary_expression
151
141
  (integer)))))))))))
152
- (primary_expression
153
- (string
154
- (string_start)
155
- (string_content)
142
+ (comment)
156
- (string_end))))))
143
+ (comment))))
tooling/tree-sitter-plum/test/corpus/while.txt ADDED
@@ -0,0 +1,50 @@
1
+ ================================================================================
2
+ while
3
+ ================================================================================
4
+
5
+ main() =
6
+ i = 0
7
+ while i < 10
8
+ i = i + 1
9
+ printLn("{i}")
10
+
11
+ --------------------------------------------------------------------------------
12
+
13
+ (source
14
+ (fn
15
+ (fn_identifier)
16
+ (body
17
+ (assign
18
+ (var_identifier)
19
+ (expression
20
+ (primary_expression
21
+ (integer))))
22
+ (while
23
+ (expression
24
+ (comparison_operator
25
+ (primary_expression
26
+ (var_identifier))
27
+ (primary_expression
28
+ (integer))))
29
+ (body
30
+ (assign
31
+ (var_identifier)
32
+ (expression
33
+ (primary_expression
34
+ (binary_operator
35
+ (primary_expression
36
+ (var_identifier))
37
+ (primary_expression
38
+ (integer))))))
39
+ (primary_expression
40
+ (fn_call
41
+ (fn_identifier)
42
+ (argument_list
43
+ (expression
44
+ (primary_expression
45
+ (string
46
+ (string_start)
47
+ (interpolation
48
+ (primary_expression
49
+ (var_identifier)))
50
+ (string_end))))))))))))