plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
0d22fe3
— Peter John
2023-04-21T00:00:46+05:30
update grammar
Generated files not shown: src/parser.c
- grammar.js +49 -91
- package.json +4 -2
- src/grammar.json +125 -98
- src/node-types.json +137 -164
- test/corpus/{functions.txt → function.txt} +22 -3
- test/corpus/record.txt +0 -65
- test/corpus/type.txt +47 -9
grammar.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
const DEC_DIGITS = token(sep1(/[0-9]+/, /_+/));
|
|
2
|
-
const HEX_DIGITS = token(sep1(/[0-9a-fA-F]+/, /_+/));
|
|
3
|
-
const BIN_DIGITS = token(sep1(/[01]/, /_+/));
|
|
4
1
|
const NEWLINE = /\r?\n/;
|
|
5
2
|
|
|
6
3
|
module.exports = grammar({
|
|
7
|
-
name:
|
|
4
|
+
name: "palm",
|
|
8
5
|
// extras: $ => [
|
|
9
6
|
// $.comment,
|
|
10
7
|
// /\s+/ // Whitespace
|
|
11
8
|
// ],
|
|
12
9
|
externals: ($) => [$.quoted_content],
|
|
13
|
-
conflicts: $ => [
|
|
14
|
-
[$.proc],
|
|
15
|
-
[$.record],
|
|
16
|
-
],
|
|
17
10
|
rules: {
|
|
18
|
-
source_file: $ =>
|
|
11
|
+
source_file: ($) =>
|
|
19
|
-
$.module,
|
|
20
|
-
repeat($.import),
|
|
12
|
+
seq($.module, repeat($.import), repeat(choice($.type, $.function))),
|
|
21
|
-
|
|
13
|
+
|
|
22
|
-
$.record,
|
|
23
|
-
$.type,
|
|
24
|
-
$.proc,
|
|
25
|
-
)),
|
|
26
|
-
),
|
|
27
|
-
|
|
28
|
-
module: $ => seq(
|
|
14
|
+
module: ($) => seq("module", field("module", $.module_name)),
|
|
29
15
|
|
|
30
16
|
/* Import statements */
|
|
31
17
|
import: ($) =>
|
|
@@ -55,34 +41,25 @@ module.exports = grammar({
|
|
|
55
41
|
|
|
56
42
|
/* Declarations */
|
|
57
43
|
|
|
58
|
-
|
|
44
|
+
type: ($) =>
|
|
45
|
+
seq(
|
|
59
|
-
|
|
46
|
+
"type",
|
|
60
|
-
|
|
47
|
+
field("name", $.type_identifier),
|
|
61
|
-
|
|
48
|
+
field("generics", optional($.generic_list)),
|
|
49
|
+
choice(
|
|
62
|
-
|
|
50
|
+
field("record", $.record),
|
|
51
|
+
field("union", seq("=", optional("|"), sep1($.union, "|")))
|
|
52
|
+
)
|
|
63
|
-
|
|
53
|
+
),
|
|
64
|
-
|
|
54
|
+
|
|
65
|
-
|
|
55
|
+
function: ($) =>
|
|
66
|
-
'type',
|
|
67
|
-
field('name', $.type_identifier),
|
|
68
|
-
field('generics', optional($.generic_list)),
|
|
69
|
-
"=",
|
|
70
|
-
field('types', pipeSep1($.type_name)),
|
|
71
|
-
),
|
|
72
|
-
|
|
73
|
-
proc: $ => seq(
|
|
74
|
-
// 'proc',
|
|
75
|
-
field('name', $.identifier),
|
|
76
|
-
field('params', seq('(', optional(commaSep1($.type_field)), ')')),
|
|
77
|
-
optional(
|
|
78
|
-
|
|
56
|
+
seq(
|
|
79
|
-
|
|
57
|
+
"fn",
|
|
58
|
+
field("name", $.identifier),
|
|
59
|
+
field("params", seq("(", optional(commaSep1($.type_field)), ")")),
|
|
80
|
-
|
|
60
|
+
optional(seq("->", field("return_type", optional($.return_type)))),
|
|
81
|
-
|
|
61
|
+
field("body", seq("{", $._statement_seq, "}"))
|
|
82
62
|
),
|
|
83
|
-
'=',
|
|
84
|
-
field('body', $._statement_seq),
|
|
85
|
-
),
|
|
86
63
|
|
|
87
64
|
/* Shared AST nodes */
|
|
88
65
|
|
|
@@ -120,14 +97,13 @@ module.exports = grammar({
|
|
|
120
97
|
$.string,
|
|
121
98
|
$.integer,
|
|
122
99
|
$.float,
|
|
123
|
-
$.record,
|
|
124
100
|
$.identifier,
|
|
125
101
|
$.todo,
|
|
126
102
|
$.panic,
|
|
127
103
|
// $.anonymous_function,
|
|
128
104
|
$.expression_group,
|
|
129
105
|
// $.case,
|
|
130
|
-
$.negation
|
|
106
|
+
$.negation
|
|
131
107
|
// $.record_update,
|
|
132
108
|
// $.field_access,
|
|
133
109
|
// $.function_call
|
|
@@ -160,45 +136,29 @@ module.exports = grammar({
|
|
|
160
136
|
_pattern_binary_expression: ($) =>
|
|
161
137
|
binaryExpr(prec.left, 1, "<>", $._pattern_expression),
|
|
162
138
|
|
|
163
|
-
|
|
164
139
|
todo: ($) =>
|
|
165
140
|
seq("todo", optional(seq("(", field("message", $.string), ")"))),
|
|
166
141
|
panic: (_$) => seq("panic"),
|
|
167
142
|
|
|
168
143
|
/* Types */
|
|
169
|
-
return_type: $ =>
|
|
144
|
+
return_type: ($) =>
|
|
145
|
+
seq(
|
|
170
|
-
|
|
146
|
+
field("name", $.type_identifier),
|
|
171
|
-
|
|
147
|
+
field("generics", optional(seq("(", commaSep1($.identifier), ")")))
|
|
172
|
-
"(",
|
|
173
|
-
commaSep1($.identifier),
|
|
174
|
-
")",
|
|
175
|
-
)))
|
|
176
|
-
|
|
148
|
+
),
|
|
149
|
+
|
|
177
|
-
|
|
150
|
+
record: ($) => seq(seq("(", commaSep1($.type_field), ")")),
|
|
178
|
-
|
|
151
|
+
|
|
179
|
-
|
|
152
|
+
union: ($) =>
|
|
153
|
+
seq(
|
|
180
|
-
|
|
154
|
+
field("name", $.type_identifier),
|
|
181
|
-
optional(seq(
|
|
182
|
-
"(",
|
|
183
|
-
choice(
|
|
184
|
-
$.identifier,
|
|
185
|
-
|
|
155
|
+
optional(seq("(", choice($.identifier, commaSep1($.type_field)), ")"))
|
|
186
|
-
|
|
156
|
+
),
|
|
187
|
-
|
|
157
|
+
|
|
188
|
-
))
|
|
189
|
-
),
|
|
190
|
-
|
|
191
|
-
type_field: $ =>
|
|
158
|
+
type_field: ($) =>
|
|
192
|
-
field(
|
|
159
|
+
seq(field("name", $.identifier), ":", field("type", $.identifier)),
|
|
193
|
-
|
|
160
|
+
|
|
194
|
-
|
|
161
|
+
generic_list: ($) => seq("(", commaSep1($.identifier), ")"),
|
|
195
|
-
),
|
|
196
|
-
|
|
197
|
-
generic_list: $ => seq(
|
|
198
|
-
'(',
|
|
199
|
-
commaSep1($.identifier),
|
|
200
|
-
')'
|
|
201
|
-
),
|
|
202
162
|
|
|
203
163
|
/* Literals */
|
|
204
164
|
float: ($) => /-?[0-9_]+\.[0-9_]*(e-?[0-9_]+)?/,
|
|
@@ -214,30 +174,28 @@ module.exports = grammar({
|
|
|
214
174
|
_decimal: ($) => /[0-9][0-9_]*/,
|
|
215
175
|
_octal: ($) => /0[oO][0-7_]+/,
|
|
216
176
|
_binary: ($) => /0[bB][0-1_]+/,
|
|
217
|
-
_interpolation: $ => choice(
|
|
218
|
-
|
|
177
|
+
_interpolation: ($) => choice(seq("{", $.identifier, "}")),
|
|
219
|
-
),
|
|
220
178
|
escape_sequence: ($) => token.immediate(/\\[efnrt\"\\]/),
|
|
221
179
|
// identifier: ($) => $._name,
|
|
222
|
-
identifier: $ => /[a-zA-Z_][a-zA-Z_0-9]*/,
|
|
180
|
+
identifier: ($) => /[a-zA-Z_][a-zA-Z_0-9]*/,
|
|
223
181
|
type_identifier: ($) => $._upname,
|
|
224
182
|
_type_annotation: ($) => seq(":", field("type", $.identifier)),
|
|
225
183
|
_discard_name: ($) => /_[_0-9a-z]*/,
|
|
226
184
|
_name: ($) => /[_a-z][_0-9a-z]*/,
|
|
227
185
|
_upname: ($) => /[A-Z][0-9a-zA-Z]*/,
|
|
228
|
-
}
|
|
186
|
+
},
|
|
229
187
|
});
|
|
230
188
|
|
|
231
189
|
function commaSep1(rule) {
|
|
232
|
-
return sep1(rule,
|
|
190
|
+
return sep1(rule, ",");
|
|
233
191
|
}
|
|
234
192
|
|
|
235
193
|
function pipeSep1(rule) {
|
|
236
|
-
return sep1(rule,
|
|
194
|
+
return sep1(rule, "|");
|
|
237
195
|
}
|
|
238
196
|
|
|
239
197
|
function sep1(rule, separator) {
|
|
240
|
-
return seq(rule, repeat(seq(separator, rule)))
|
|
198
|
+
return seq(rule, repeat(seq(separator, rule)));
|
|
241
199
|
}
|
|
242
200
|
|
|
243
201
|
function series_of(rule, separator) {
|
|
@@ -251,4 +209,4 @@ function binaryExpr(assoc, precedence, operator, expr) {
|
|
|
251
209
|
precedence,
|
|
252
210
|
seq(field("left", expr), field("operator", operator), field("right", expr))
|
|
253
211
|
);
|
|
254
|
-
}
|
|
212
|
+
}
|
package.json
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"generate": "tree-sitter generate",
|
|
10
10
|
"parse": "tree-sitter parse",
|
|
11
11
|
"build-wasm": "tree-sitter build-wasm",
|
|
12
|
-
"playground": "tree-sitter playground"
|
|
12
|
+
"playground": "tree-sitter playground",
|
|
13
|
+
"format": "prettier --write grammar.js"
|
|
13
14
|
},
|
|
14
15
|
"author": "pyrossh",
|
|
15
16
|
"license": "MIT",
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
"nan": "^2.17.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
28
|
+
"prettier": "^2.8.7",
|
|
27
29
|
"tree-sitter-cli": "^0.20.7"
|
|
28
30
|
},
|
|
29
31
|
"repository": {
|
|
@@ -39,4 +41,4 @@
|
|
|
39
41
|
"injection-regex": "^palm$"
|
|
40
42
|
}
|
|
41
43
|
]
|
|
42
|
-
}
|
|
44
|
+
}
|
src/grammar.json
CHANGED
|
@@ -20,17 +20,13 @@
|
|
|
20
20
|
"content": {
|
|
21
21
|
"type": "CHOICE",
|
|
22
22
|
"members": [
|
|
23
|
-
{
|
|
24
|
-
"type": "SYMBOL",
|
|
25
|
-
"name": "record"
|
|
26
|
-
},
|
|
27
23
|
{
|
|
28
24
|
"type": "SYMBOL",
|
|
29
25
|
"name": "type"
|
|
30
26
|
},
|
|
31
27
|
{
|
|
32
28
|
"type": "SYMBOL",
|
|
33
|
-
"name": "
|
|
29
|
+
"name": "function"
|
|
34
30
|
}
|
|
35
31
|
]
|
|
36
32
|
}
|
|
@@ -285,50 +281,6 @@
|
|
|
285
281
|
}
|
|
286
282
|
]
|
|
287
283
|
},
|
|
288
|
-
"record": {
|
|
289
|
-
"type": "SEQ",
|
|
290
|
-
"members": [
|
|
291
|
-
{
|
|
292
|
-
"type": "STRING",
|
|
293
|
-
"value": "record"
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
"type": "FIELD",
|
|
297
|
-
"name": "name",
|
|
298
|
-
"content": {
|
|
299
|
-
"type": "SYMBOL",
|
|
300
|
-
"name": "type_identifier"
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
"type": "FIELD",
|
|
305
|
-
"name": "generics",
|
|
306
|
-
"content": {
|
|
307
|
-
"type": "CHOICE",
|
|
308
|
-
"members": [
|
|
309
|
-
{
|
|
310
|
-
"type": "SYMBOL",
|
|
311
|
-
"name": "generic_list"
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
"type": "BLANK"
|
|
315
|
-
}
|
|
316
|
-
]
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
"type": "FIELD",
|
|
321
|
-
"name": "fields",
|
|
322
|
-
"content": {
|
|
323
|
-
"type": "REPEAT",
|
|
324
|
-
"content": {
|
|
325
|
-
"type": "SYMBOL",
|
|
326
|
-
"name": "type_field"
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
]
|
|
331
|
-
},
|
|
332
284
|
"type": {
|
|
333
285
|
"type": "SEQ",
|
|
334
286
|
"members": [
|
|
@@ -361,43 +313,77 @@
|
|
|
361
313
|
}
|
|
362
314
|
},
|
|
363
315
|
{
|
|
364
|
-
"type": "
|
|
316
|
+
"type": "CHOICE",
|
|
365
|
-
"
|
|
317
|
+
"members": [
|
|
366
|
-
},
|
|
367
|
-
|
|
318
|
+
{
|
|
368
|
-
|
|
319
|
+
"type": "FIELD",
|
|
369
|
-
|
|
320
|
+
"name": "record",
|
|
370
|
-
|
|
321
|
+
"content": {
|
|
371
|
-
"type": "SEQ",
|
|
372
|
-
"members": [
|
|
373
|
-
{
|
|
374
322
|
"type": "SYMBOL",
|
|
375
|
-
"name": "
|
|
323
|
+
"name": "record"
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
"type": "REPEAT",
|
|
379
|
-
"content": {
|
|
380
|
-
"type": "SEQ",
|
|
381
|
-
"members": [
|
|
382
|
-
{
|
|
383
|
-
"type": "STRING",
|
|
384
|
-
"value": "|"
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
"type": "SYMBOL",
|
|
388
|
-
"name": "type_name"
|
|
389
|
-
}
|
|
390
|
-
]
|
|
391
|
-
}
|
|
392
324
|
}
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
"type": "FIELD",
|
|
328
|
+
"name": "union",
|
|
329
|
+
"content": {
|
|
330
|
+
"type": "SEQ",
|
|
331
|
+
"members": [
|
|
332
|
+
{
|
|
333
|
+
"type": "STRING",
|
|
334
|
+
"value": "="
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
"type": "CHOICE",
|
|
338
|
+
"members": [
|
|
339
|
+
{
|
|
340
|
+
"type": "STRING",
|
|
341
|
+
"value": "|"
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"type": "BLANK"
|
|
345
|
+
}
|
|
393
|
-
|
|
346
|
+
]
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
"type": "SEQ",
|
|
350
|
+
"members": [
|
|
351
|
+
{
|
|
352
|
+
"type": "SYMBOL",
|
|
353
|
+
"name": "union"
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
"type": "REPEAT",
|
|
357
|
+
"content": {
|
|
358
|
+
"type": "SEQ",
|
|
359
|
+
"members": [
|
|
360
|
+
{
|
|
361
|
+
"type": "STRING",
|
|
362
|
+
"value": "|"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"type": "SYMBOL",
|
|
366
|
+
"name": "union"
|
|
394
|
-
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
]
|
|
395
377
|
}
|
|
396
378
|
]
|
|
397
379
|
},
|
|
398
|
-
"
|
|
380
|
+
"function": {
|
|
399
381
|
"type": "SEQ",
|
|
400
382
|
"members": [
|
|
383
|
+
{
|
|
384
|
+
"type": "STRING",
|
|
385
|
+
"value": "fn"
|
|
386
|
+
},
|
|
401
387
|
{
|
|
402
388
|
"type": "FIELD",
|
|
403
389
|
"name": "name",
|
|
@@ -489,16 +475,25 @@
|
|
|
489
475
|
}
|
|
490
476
|
]
|
|
491
477
|
},
|
|
492
|
-
{
|
|
493
|
-
"type": "STRING",
|
|
494
|
-
"value": "="
|
|
495
|
-
},
|
|
496
478
|
{
|
|
497
479
|
"type": "FIELD",
|
|
498
480
|
"name": "body",
|
|
499
481
|
"content": {
|
|
482
|
+
"type": "SEQ",
|
|
483
|
+
"members": [
|
|
484
|
+
{
|
|
485
|
+
"type": "STRING",
|
|
486
|
+
"value": "{"
|
|
487
|
+
},
|
|
488
|
+
{
|
|
500
|
-
|
|
489
|
+
"type": "SYMBOL",
|
|
501
|
-
|
|
490
|
+
"name": "_statement_seq"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
"type": "STRING",
|
|
494
|
+
"value": "}"
|
|
495
|
+
}
|
|
496
|
+
]
|
|
502
497
|
}
|
|
503
498
|
}
|
|
504
499
|
]
|
|
@@ -1051,10 +1046,6 @@
|
|
|
1051
1046
|
"type": "SYMBOL",
|
|
1052
1047
|
"name": "float"
|
|
1053
1048
|
},
|
|
1054
|
-
{
|
|
1055
|
-
"type": "SYMBOL",
|
|
1056
|
-
"name": "record"
|
|
1057
|
-
},
|
|
1058
1049
|
{
|
|
1059
1050
|
"type": "SYMBOL",
|
|
1060
1051
|
"name": "identifier"
|
|
@@ -1360,7 +1351,50 @@
|
|
|
1360
1351
|
}
|
|
1361
1352
|
]
|
|
1362
1353
|
},
|
|
1354
|
+
"record": {
|
|
1355
|
+
"type": "SEQ",
|
|
1356
|
+
"members": [
|
|
1357
|
+
{
|
|
1358
|
+
"type": "SEQ",
|
|
1359
|
+
"members": [
|
|
1360
|
+
{
|
|
1361
|
+
"type": "STRING",
|
|
1362
|
+
"value": "("
|
|
1363
|
+
},
|
|
1364
|
+
{
|
|
1365
|
+
"type": "SEQ",
|
|
1366
|
+
"members": [
|
|
1367
|
+
{
|
|
1368
|
+
"type": "SYMBOL",
|
|
1369
|
+
"name": "type_field"
|
|
1370
|
+
},
|
|
1371
|
+
{
|
|
1372
|
+
"type": "REPEAT",
|
|
1363
|
-
|
|
1373
|
+
"content": {
|
|
1374
|
+
"type": "SEQ",
|
|
1375
|
+
"members": [
|
|
1376
|
+
{
|
|
1377
|
+
"type": "STRING",
|
|
1378
|
+
"value": ","
|
|
1379
|
+
},
|
|
1380
|
+
{
|
|
1381
|
+
"type": "SYMBOL",
|
|
1382
|
+
"name": "type_field"
|
|
1383
|
+
}
|
|
1384
|
+
]
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
]
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
"type": "STRING",
|
|
1391
|
+
"value": ")"
|
|
1392
|
+
}
|
|
1393
|
+
]
|
|
1394
|
+
}
|
|
1395
|
+
]
|
|
1396
|
+
},
|
|
1397
|
+
"union": {
|
|
1364
1398
|
"type": "SEQ",
|
|
1365
1399
|
"members": [
|
|
1366
1400
|
{
|
|
@@ -1654,14 +1688,7 @@
|
|
|
1654
1688
|
"value": "\\s"
|
|
1655
1689
|
}
|
|
1656
1690
|
],
|
|
1657
|
-
"conflicts": [
|
|
1691
|
+
"conflicts": [],
|
|
1658
|
-
[
|
|
1659
|
-
"proc"
|
|
1660
|
-
],
|
|
1661
|
-
[
|
|
1662
|
-
"record"
|
|
1663
|
-
]
|
|
1664
|
-
],
|
|
1665
1692
|
"precedences": [],
|
|
1666
1693
|
"externals": [
|
|
1667
1694
|
{
|
src/node-types.json
CHANGED
|
@@ -35,10 +35,6 @@
|
|
|
35
35
|
"type": "panic",
|
|
36
36
|
"named": true
|
|
37
37
|
},
|
|
38
|
-
{
|
|
39
|
-
"type": "record",
|
|
40
|
-
"named": true
|
|
41
|
-
},
|
|
42
38
|
{
|
|
43
39
|
"type": "string",
|
|
44
40
|
"named": true
|
|
@@ -147,10 +143,6 @@
|
|
|
147
143
|
"type": "panic",
|
|
148
144
|
"named": true
|
|
149
145
|
},
|
|
150
|
-
{
|
|
151
|
-
"type": "record",
|
|
152
|
-
"named": true
|
|
153
|
-
},
|
|
154
146
|
{
|
|
155
147
|
"type": "string",
|
|
156
148
|
"named": true
|
|
@@ -203,10 +195,6 @@
|
|
|
203
195
|
"type": "panic",
|
|
204
196
|
"named": true
|
|
205
197
|
},
|
|
206
|
-
{
|
|
207
|
-
"type": "record",
|
|
208
|
-
"named": true
|
|
209
|
-
},
|
|
210
198
|
{
|
|
211
199
|
"type": "string",
|
|
212
200
|
"named": true
|
|
@@ -218,6 +206,108 @@
|
|
|
218
206
|
]
|
|
219
207
|
}
|
|
220
208
|
},
|
|
209
|
+
{
|
|
210
|
+
"type": "function",
|
|
211
|
+
"named": true,
|
|
212
|
+
"fields": {
|
|
213
|
+
"body": {
|
|
214
|
+
"multiple": true,
|
|
215
|
+
"required": true,
|
|
216
|
+
"types": [
|
|
217
|
+
{
|
|
218
|
+
"type": "binary_expression",
|
|
219
|
+
"named": true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"type": "expression_group",
|
|
223
|
+
"named": true
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"type": "float",
|
|
227
|
+
"named": true
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"type": "identifier",
|
|
231
|
+
"named": true
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"type": "integer",
|
|
235
|
+
"named": true
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"type": "let",
|
|
239
|
+
"named": true
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"type": "negation",
|
|
243
|
+
"named": true
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"type": "panic",
|
|
247
|
+
"named": true
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"type": "string",
|
|
251
|
+
"named": true
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"type": "todo",
|
|
255
|
+
"named": true
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"type": "{",
|
|
259
|
+
"named": false
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"type": "}",
|
|
263
|
+
"named": false
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
},
|
|
267
|
+
"name": {
|
|
268
|
+
"multiple": false,
|
|
269
|
+
"required": true,
|
|
270
|
+
"types": [
|
|
271
|
+
{
|
|
272
|
+
"type": "identifier",
|
|
273
|
+
"named": true
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
},
|
|
277
|
+
"params": {
|
|
278
|
+
"multiple": true,
|
|
279
|
+
"required": true,
|
|
280
|
+
"types": [
|
|
281
|
+
{
|
|
282
|
+
"type": "(",
|
|
283
|
+
"named": false
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"type": ")",
|
|
287
|
+
"named": false
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"type": ",",
|
|
291
|
+
"named": false
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"type": "type_field",
|
|
295
|
+
"named": true
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
},
|
|
299
|
+
"return_type": {
|
|
300
|
+
"multiple": false,
|
|
301
|
+
"required": false,
|
|
302
|
+
"types": [
|
|
303
|
+
{
|
|
304
|
+
"type": "return_type",
|
|
305
|
+
"named": true
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
},
|
|
221
311
|
{
|
|
222
312
|
"type": "generic_list",
|
|
223
313
|
"named": true,
|
|
@@ -360,10 +450,6 @@
|
|
|
360
450
|
"type": "panic",
|
|
361
451
|
"named": true
|
|
362
452
|
},
|
|
363
|
-
{
|
|
364
|
-
"type": "record",
|
|
365
|
-
"named": true
|
|
366
|
-
},
|
|
367
453
|
{
|
|
368
454
|
"type": "string",
|
|
369
455
|
"named": true
|
|
@@ -429,10 +515,6 @@
|
|
|
429
515
|
"type": "panic",
|
|
430
516
|
"named": true
|
|
431
517
|
},
|
|
432
|
-
{
|
|
433
|
-
"type": "record",
|
|
434
|
-
"named": true
|
|
435
|
-
},
|
|
436
518
|
{
|
|
437
519
|
"type": "string",
|
|
438
520
|
"named": true
|
|
@@ -449,138 +531,19 @@
|
|
|
449
531
|
"named": true,
|
|
450
532
|
"fields": {}
|
|
451
533
|
},
|
|
452
|
-
{
|
|
453
|
-
"type": "proc",
|
|
454
|
-
"named": true,
|
|
455
|
-
"fields": {
|
|
456
|
-
"body": {
|
|
457
|
-
"multiple": true,
|
|
458
|
-
"required": true,
|
|
459
|
-
"types": [
|
|
460
|
-
{
|
|
461
|
-
"type": "binary_expression",
|
|
462
|
-
"named": true
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
"type": "expression_group",
|
|
466
|
-
"named": true
|
|
467
|
-
},
|
|
468
|
-
{
|
|
469
|
-
"type": "float",
|
|
470
|
-
"named": true
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
"type": "identifier",
|
|
474
|
-
"named": true
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
"type": "integer",
|
|
478
|
-
"named": true
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
"type": "let",
|
|
482
|
-
"named": true
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
"type": "negation",
|
|
486
|
-
"named": true
|
|
487
|
-
},
|
|
488
|
-
{
|
|
489
|
-
"type": "panic",
|
|
490
|
-
"named": true
|
|
491
|
-
},
|
|
492
|
-
{
|
|
493
|
-
"type": "record",
|
|
494
|
-
"named": true
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
"type": "string",
|
|
498
|
-
"named": true
|
|
499
|
-
},
|
|
500
|
-
{
|
|
501
|
-
"type": "todo",
|
|
502
|
-
"named": true
|
|
503
|
-
}
|
|
504
|
-
]
|
|
505
|
-
},
|
|
506
|
-
"name": {
|
|
507
|
-
"multiple": false,
|
|
508
|
-
"required": true,
|
|
509
|
-
"types": [
|
|
510
|
-
{
|
|
511
|
-
"type": "identifier",
|
|
512
|
-
"named": true
|
|
513
|
-
}
|
|
514
|
-
]
|
|
515
|
-
},
|
|
516
|
-
"params": {
|
|
517
|
-
"multiple": true,
|
|
518
|
-
"required": true,
|
|
519
|
-
"types": [
|
|
520
|
-
{
|
|
521
|
-
"type": "(",
|
|
522
|
-
"named": false
|
|
523
|
-
},
|
|
524
|
-
{
|
|
525
|
-
"type": ")",
|
|
526
|
-
"named": false
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
"type": ",",
|
|
530
|
-
"named": false
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
"type": "type_field",
|
|
534
|
-
"named": true
|
|
535
|
-
}
|
|
536
|
-
]
|
|
537
|
-
},
|
|
538
|
-
"return_type": {
|
|
539
|
-
"multiple": false,
|
|
540
|
-
"required": false,
|
|
541
|
-
"types": [
|
|
542
|
-
{
|
|
543
|
-
"type": "return_type",
|
|
544
|
-
"named": true
|
|
545
|
-
}
|
|
546
|
-
]
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
534
|
{
|
|
551
535
|
"type": "record",
|
|
552
536
|
"named": true,
|
|
553
|
-
"fields": {
|
|
537
|
+
"fields": {},
|
|
554
|
-
|
|
538
|
+
"children": {
|
|
555
|
-
|
|
539
|
+
"multiple": true,
|
|
556
|
-
|
|
540
|
+
"required": true,
|
|
557
|
-
|
|
541
|
+
"types": [
|
|
558
|
-
|
|
542
|
+
{
|
|
559
|
-
|
|
543
|
+
"type": "type_field",
|
|
560
|
-
|
|
544
|
+
"named": true
|
|
561
|
-
|
|
545
|
+
}
|
|
562
|
-
|
|
546
|
+
]
|
|
563
|
-
},
|
|
564
|
-
"generics": {
|
|
565
|
-
"multiple": false,
|
|
566
|
-
"required": false,
|
|
567
|
-
"types": [
|
|
568
|
-
{
|
|
569
|
-
"type": "generic_list",
|
|
570
|
-
"named": true
|
|
571
|
-
}
|
|
572
|
-
]
|
|
573
|
-
},
|
|
574
|
-
"name": {
|
|
575
|
-
"multiple": false,
|
|
576
|
-
"required": true,
|
|
577
|
-
"types": [
|
|
578
|
-
{
|
|
579
|
-
"type": "type_identifier",
|
|
580
|
-
"named": true
|
|
581
|
-
}
|
|
582
|
-
]
|
|
583
|
-
}
|
|
584
547
|
}
|
|
585
548
|
},
|
|
586
549
|
{
|
|
@@ -630,19 +593,15 @@
|
|
|
630
593
|
"required": true,
|
|
631
594
|
"types": [
|
|
632
595
|
{
|
|
633
|
-
"type": "
|
|
596
|
+
"type": "function",
|
|
634
|
-
"named": true
|
|
635
|
-
},
|
|
636
|
-
{
|
|
637
|
-
"type": "module",
|
|
638
597
|
"named": true
|
|
639
598
|
},
|
|
640
599
|
{
|
|
641
|
-
"type": "
|
|
600
|
+
"type": "import",
|
|
642
601
|
"named": true
|
|
643
602
|
},
|
|
644
603
|
{
|
|
645
|
-
"type": "
|
|
604
|
+
"type": "module",
|
|
646
605
|
"named": true
|
|
647
606
|
},
|
|
648
607
|
{
|
|
@@ -711,12 +670,26 @@
|
|
|
711
670
|
}
|
|
712
671
|
]
|
|
713
672
|
},
|
|
673
|
+
"record": {
|
|
674
|
+
"multiple": false,
|
|
675
|
+
"required": false,
|
|
714
|
-
|
|
676
|
+
"types": [
|
|
677
|
+
{
|
|
678
|
+
"type": "record",
|
|
679
|
+
"named": true
|
|
680
|
+
}
|
|
681
|
+
]
|
|
682
|
+
},
|
|
683
|
+
"union": {
|
|
715
684
|
"multiple": true,
|
|
716
|
-
"required":
|
|
685
|
+
"required": false,
|
|
717
686
|
"types": [
|
|
718
687
|
{
|
|
688
|
+
"type": "=",
|
|
689
|
+
"named": false
|
|
690
|
+
},
|
|
691
|
+
{
|
|
719
|
-
"type": "
|
|
692
|
+
"type": "union",
|
|
720
693
|
"named": true
|
|
721
694
|
},
|
|
722
695
|
{
|
|
@@ -759,7 +732,7 @@
|
|
|
759
732
|
"fields": {}
|
|
760
733
|
},
|
|
761
734
|
{
|
|
762
|
-
"type": "
|
|
735
|
+
"type": "union",
|
|
763
736
|
"named": true,
|
|
764
737
|
"fields": {
|
|
765
738
|
"name": {
|
|
@@ -937,6 +910,10 @@
|
|
|
937
910
|
"type": "float",
|
|
938
911
|
"named": true
|
|
939
912
|
},
|
|
913
|
+
{
|
|
914
|
+
"type": "fn",
|
|
915
|
+
"named": false
|
|
916
|
+
},
|
|
940
917
|
{
|
|
941
918
|
"type": "identifier",
|
|
942
919
|
"named": true
|
|
@@ -961,10 +938,6 @@
|
|
|
961
938
|
"type": "quoted_content",
|
|
962
939
|
"named": true
|
|
963
940
|
},
|
|
964
|
-
{
|
|
965
|
-
"type": "record",
|
|
966
|
-
"named": false
|
|
967
|
-
},
|
|
968
941
|
{
|
|
969
942
|
"type": "todo",
|
|
970
943
|
"named": false
|
test/corpus/{functions.txt → function.txt}
RENAMED
|
@@ -4,17 +4,36 @@ Function - Simple
|
|
|
4
4
|
|
|
5
5
|
module palm
|
|
6
6
|
|
|
7
|
-
main()
|
|
7
|
+
fn main() {
|
|
8
8
|
let a = "123"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
fn add(a: Int, b: Int) -> Int {
|
|
12
|
+
let a = "123"
|
|
13
|
+
}
|
|
9
14
|
|
|
10
15
|
--------------------------------------------------------------------------------
|
|
11
16
|
|
|
12
17
|
(source_file
|
|
13
18
|
(module
|
|
14
19
|
(module_name))
|
|
20
|
+
(function
|
|
21
|
+
(identifier)
|
|
22
|
+
(let
|
|
23
|
+
(identifier)
|
|
15
|
-
|
|
24
|
+
(string
|
|
25
|
+
(quoted_content))))
|
|
26
|
+
(function
|
|
16
27
|
(identifier)
|
|
28
|
+
(type_field
|
|
29
|
+
(identifier)
|
|
30
|
+
(identifier))
|
|
31
|
+
(type_field
|
|
32
|
+
(identifier)
|
|
33
|
+
(identifier))
|
|
34
|
+
(return_type
|
|
35
|
+
(type_identifier))
|
|
17
36
|
(let
|
|
18
37
|
(identifier)
|
|
19
38
|
(string
|
|
20
|
-
(quoted_content)))))
|
|
39
|
+
(quoted_content)))))
|
test/corpus/record.txt
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
================================================================================
|
|
2
|
-
Record - Simple
|
|
3
|
-
================================================================================
|
|
4
|
-
|
|
5
|
-
module std
|
|
6
|
-
|
|
7
|
-
record Cat
|
|
8
|
-
firstName: String
|
|
9
|
-
middleName: String
|
|
10
|
-
lastName: String
|
|
11
|
-
age : Int
|
|
12
|
-
|
|
13
|
-
record Dog
|
|
14
|
-
name: String
|
|
15
|
-
|
|
16
|
-
--------------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
(source_file
|
|
19
|
-
(module
|
|
20
|
-
(module_name))
|
|
21
|
-
(record
|
|
22
|
-
(type_identifier)
|
|
23
|
-
(type_field
|
|
24
|
-
(identifier)
|
|
25
|
-
(identifier))
|
|
26
|
-
(type_field
|
|
27
|
-
(identifier)
|
|
28
|
-
(identifier))
|
|
29
|
-
(type_field
|
|
30
|
-
(identifier)
|
|
31
|
-
(identifier))
|
|
32
|
-
(type_field
|
|
33
|
-
(identifier)
|
|
34
|
-
(identifier)))
|
|
35
|
-
(record
|
|
36
|
-
(type_identifier)
|
|
37
|
-
(type_field
|
|
38
|
-
(identifier)
|
|
39
|
-
(identifier))))
|
|
40
|
-
|
|
41
|
-
================================================================================
|
|
42
|
-
Record - Generic
|
|
43
|
-
================================================================================
|
|
44
|
-
|
|
45
|
-
module std
|
|
46
|
-
|
|
47
|
-
record Shape(a)
|
|
48
|
-
name: String
|
|
49
|
-
area: a
|
|
50
|
-
|
|
51
|
-
--------------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
(source_file
|
|
54
|
-
(module
|
|
55
|
-
(module_name))
|
|
56
|
-
(record
|
|
57
|
-
(type_identifier)
|
|
58
|
-
(generic_list
|
|
59
|
-
(identifier))
|
|
60
|
-
(type_field
|
|
61
|
-
(identifier)
|
|
62
|
-
(identifier))
|
|
63
|
-
(type_field
|
|
64
|
-
(identifier)
|
|
65
|
-
(identifier))))
|
test/corpus/type.txt
CHANGED
|
@@ -6,6 +6,13 @@ module palm
|
|
|
6
6
|
|
|
7
7
|
type User = Guest | LoggedIn(name: String, session_id: String)
|
|
8
8
|
|
|
9
|
+
type Cat(
|
|
10
|
+
firstName: String,
|
|
11
|
+
middleName: String,
|
|
12
|
+
lastName: String,
|
|
13
|
+
age: Int
|
|
14
|
+
)
|
|
15
|
+
|
|
9
16
|
--------------------------------------------------------------------------------
|
|
10
17
|
|
|
11
18
|
(source_file
|
|
@@ -13,10 +20,25 @@ type User = Guest | LoggedIn(name: String, session_id: String)
|
|
|
13
20
|
(module_name))
|
|
14
21
|
(type
|
|
15
22
|
(type_identifier)
|
|
16
|
-
(
|
|
23
|
+
(union
|
|
17
24
|
(type_identifier))
|
|
18
|
-
(
|
|
25
|
+
(union
|
|
19
26
|
(type_identifier)
|
|
27
|
+
(type_field
|
|
28
|
+
(identifier)
|
|
29
|
+
(identifier))
|
|
30
|
+
(type_field
|
|
31
|
+
(identifier)
|
|
32
|
+
(identifier))))
|
|
33
|
+
(type
|
|
34
|
+
(type_identifier)
|
|
35
|
+
(record
|
|
36
|
+
(type_field
|
|
37
|
+
(identifier)
|
|
38
|
+
(identifier))
|
|
39
|
+
(type_field
|
|
40
|
+
(identifier)
|
|
41
|
+
(identifier))
|
|
20
42
|
(type_field
|
|
21
43
|
(identifier)
|
|
22
44
|
(identifier))
|
|
@@ -36,6 +58,11 @@ type Option(a) = Some(a) | None
|
|
|
36
58
|
|
|
37
59
|
type Result(a, b) = Ok(a) | Error(b)
|
|
38
60
|
|
|
61
|
+
type Cat(a)(
|
|
62
|
+
name: a,
|
|
63
|
+
age: Int
|
|
64
|
+
)
|
|
65
|
+
|
|
39
66
|
--------------------------------------------------------------------------------
|
|
40
67
|
|
|
41
68
|
(source_file
|
|
@@ -45,9 +72,9 @@ type Result(a, b) = Ok(a) | Error(b)
|
|
|
45
72
|
(type_identifier)
|
|
46
73
|
(generic_list
|
|
47
74
|
(identifier))
|
|
48
|
-
(
|
|
75
|
+
(union
|
|
49
76
|
(type_identifier))
|
|
50
|
-
(
|
|
77
|
+
(union
|
|
51
78
|
(type_identifier)
|
|
52
79
|
(type_field
|
|
53
80
|
(identifier)
|
|
@@ -59,19 +86,30 @@ type Result(a, b) = Ok(a) | Error(b)
|
|
|
59
86
|
(type_identifier)
|
|
60
87
|
(generic_list
|
|
61
88
|
(identifier))
|
|
62
|
-
(
|
|
89
|
+
(union
|
|
63
90
|
(type_identifier)
|
|
64
91
|
(identifier))
|
|
65
|
-
(
|
|
92
|
+
(union
|
|
66
93
|
(type_identifier)))
|
|
67
94
|
(type
|
|
68
95
|
(type_identifier)
|
|
69
96
|
(generic_list
|
|
70
97
|
(identifier)
|
|
71
98
|
(identifier))
|
|
72
|
-
(
|
|
99
|
+
(union
|
|
73
100
|
(type_identifier)
|
|
74
101
|
(identifier))
|
|
75
|
-
(
|
|
102
|
+
(union
|
|
76
103
|
(type_identifier)
|
|
104
|
+
(identifier)))
|
|
105
|
+
(type
|
|
106
|
+
(type_identifier)
|
|
107
|
+
(generic_list
|
|
108
|
+
(identifier))
|
|
109
|
+
(record
|
|
110
|
+
(type_field
|
|
111
|
+
(identifier)
|
|
112
|
+
(identifier))
|
|
113
|
+
(type_field
|
|
114
|
+
(identifier)
|
|
77
|
-
|
|
115
|
+
(identifier)))))
|