plum

#treesitter#compiler#wasm

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

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


694b4a5 — Peter John 2023-04-28T22:28:33+05:30
Add functions

Generated files not shown: src/parser.c

Files changed (4) hide show
  1. grammar.js +166 -11
  2. src/grammar.json +1006 -51
  3. src/node-types.json +950 -80
  4. test/corpus/function.txt +37 -12
grammar.js CHANGED
@@ -43,6 +43,7 @@ module.exports = grammar({
43
43
 
44
44
  struct: ($) =>
45
45
  seq(
46
+ optional($.visibility_modifier),
46
47
  "type",
47
48
  field("name", $.type_identifier),
48
49
  field("generics", optional($.generics)),
@@ -51,6 +52,7 @@ module.exports = grammar({
51
52
 
52
53
  enum: ($) =>
53
54
  seq(
55
+ optional($.visibility_modifier),
54
56
  "type",
55
57
  field("name", $.type_identifier),
56
58
  field("generics", optional($.generics)),
@@ -75,15 +77,17 @@ module.exports = grammar({
75
77
 
76
78
  function: ($) =>
77
79
  seq(
80
+ optional($.visibility_modifier),
78
81
  "fn",
79
82
  field("name", $.identifier),
80
83
  field("params", seq("(", optional(series_of($.field, ",")), ")")),
81
- field("return", $.return_type),
84
+ field("return", optional($.return_type)),
82
85
  field("body", seq("{", $._statement_seq, "}"))
83
86
  ),
84
87
 
85
88
  /* Expressions */
86
89
 
90
+ _name_param: ($) => field("name", $.identifier),
87
91
  _statement_seq: ($) => repeat1($._statement),
88
92
  _statement: ($) => choice($._expression, $.let),
89
93
  _expression: ($) => choice($._expression_unit, $.binary_expression),
@@ -111,15 +115,124 @@ module.exports = grammar({
111
115
  $.integer,
112
116
  $.float,
113
117
  $.identifier,
114
- // $.anonymous_function,
118
+ $.anonymous_function,
115
119
  $.expression_group,
116
- // $.case,
120
+ $.when,
117
- $.negation
121
+ $.negation,
118
122
  // $.record_update,
119
- // $.field_access,
123
+ $.field_access,
120
- // $.function_call
124
+ $.function_call
125
+ ),
126
+ record: ($) =>
127
+ seq(
128
+ field("name", $.constructor_name),
129
+ optional(field("arguments", $.arguments))
130
+ ),
131
+ list: ($) =>
132
+ seq(
133
+ "[",
134
+ optional(
135
+ seq(
136
+ $._expression,
137
+ optional(repeat(seq(",", $._expression))),
138
+ optional(","),
139
+ optional(seq("..", field("spread", $._expression)))
140
+ )
141
+ ),
142
+ "]"
143
+ ),
144
+ anonymous_function: ($) =>
145
+ seq(
146
+ "fn",
147
+ field(
148
+ "parameters",
149
+ alias($.anonymous_function_parameters, $.function_parameters)
150
+ ),
151
+ optional(seq("->", field("return_type", $._type))),
152
+ "{",
153
+ field("body", alias($._statement_seq, $.function_body)),
154
+ "}"
155
+ ),
156
+ anonymous_function_parameters: ($) =>
157
+ seq(
158
+ "(",
159
+ optional(
160
+ series_of(
161
+ alias($.anonymous_function_parameter, $.function_parameter),
162
+ ","
163
+ )
164
+ ),
165
+ ")"
166
+ ),
167
+
168
+ _discard_param: ($) => field("name", $.discard),
169
+ anonymous_function_parameter: ($) =>
170
+ seq(
171
+ choice($._discard_param, $._name_param),
172
+ optional($._type_annotation)
121
173
  ),
122
174
  expression_group: ($) => seq("{", $._statement_seq, "}"),
175
+
176
+ when: $ => seq(
177
+ "when",
178
+ optional($._expression),
179
+ "{",
180
+ repeat($.when_entry),
181
+ "}"
182
+ ),
183
+
184
+ when_entry: $ => seq(
185
+ choice(
186
+ seq($._expression, repeat(seq(",", $._expression))),
187
+ "_"
188
+ ),
189
+ "->",
190
+ $._expression,
191
+ ),
192
+
193
+ _maybe_record_expression: ($) =>
194
+ choice(
195
+ $.record,
196
+ $.identifier,
197
+ $.function_call,
198
+ $.expression_group,
199
+ $.when,
200
+ // $.record_update,
201
+ $.field_access,
202
+ ),
203
+ field_access: ($) =>
204
+ prec.left(
205
+ seq(
206
+ field("record", $._maybe_record_expression),
207
+ ".",
208
+ field("field", $.label)
209
+ )
210
+ ),
211
+
212
+ arguments: ($) => seq("(", optional(series_of($.argument, ",")), ")"),
213
+ argument: ($) =>
214
+ seq(
215
+ optional(seq(field("label", $.label), ":")),
216
+ field("value", choice($.hole, $._expression))
217
+ ),
218
+ hole: ($) => $._discard_name,
219
+
220
+ function_call: ($) =>
221
+ seq(
222
+ field("function", $._maybe_function_expression),
223
+ field("arguments", $.arguments)
224
+ ),
225
+
226
+ _maybe_function_expression: ($) =>
227
+ choice(
228
+ $.identifier,
229
+ $.anonymous_function,
230
+ $.expression_group,
231
+ $.when,
232
+ $.field_access,
233
+ $.function_call
234
+ ),
235
+
123
236
  negation: ($) => seq("!", $._expression_unit),
124
237
  let: ($) => seq("let", $._assignment),
125
238
  _assignment: ($) =>
@@ -129,6 +242,23 @@ module.exports = grammar({
129
242
  "=",
130
243
  field("value", $._expression)
131
244
  ),
245
+
246
+ record_update: ($) =>
247
+ seq(
248
+ field(
249
+ "constructor", $.constructor_name
250
+ ),
251
+ "(",
252
+ "..",
253
+ field("spread", $._expression),
254
+ ",",
255
+ field("arguments", $.record_update_arguments),
256
+ ")"
257
+ ),
258
+ record_update_arguments: ($) => series_of($.record_update_argument, ","),
259
+ record_update_argument: ($) =>
260
+ seq(field("label", $.label), ":", field("value", $._expression)),
261
+
132
262
  _pattern: ($) =>
133
263
  seq(
134
264
  $._pattern_expression,
@@ -137,9 +267,9 @@ module.exports = grammar({
137
267
  _pattern_expression: ($) =>
138
268
  choice(
139
269
  $.identifier,
140
- // $.discard,
270
+ $.discard,
141
- // $.record_pattern,
271
+ $.record_pattern,
142
- // $.string,
272
+ $.string,
143
273
  $.integer,
144
274
  $.float,
145
275
  alias($._pattern_binary_expression, $.binary_expression)
@@ -147,6 +277,25 @@ module.exports = grammar({
147
277
  _pattern_binary_expression: ($) =>
148
278
  binaryExpr(prec.left, 1, "<>", $._pattern_expression),
149
279
 
280
+ record_pattern: ($) =>
281
+ seq(
282
+ field("name", $.constructor_name),
283
+ optional(field("arguments", $.record_pattern_arguments))
284
+ ),
285
+ record_pattern_arguments: ($) =>
286
+ seq(
287
+ "(",
288
+ optional(series_of($.record_pattern_argument, ",")),
289
+ optional($.pattern_spread),
290
+ ")"
291
+ ),
292
+ record_pattern_argument: ($) =>
293
+ seq(
294
+ optional(seq(field("label", $.label), ":")),
295
+ field("pattern", $._pattern)
296
+ ),
297
+ pattern_spread: ($) => seq("..", optional(",")),
298
+
150
299
  /* Types */
151
300
  field: ($) =>
152
301
  seq(field("name", $.identifier), ":", field("type", $._type)),
@@ -173,6 +322,7 @@ module.exports = grammar({
173
322
 
174
323
  generics: ($) => seq("(", series_of($.generic, ","), ")"),
175
324
  generic: ($) => /[a-z][a-z]*/,
325
+ visibility_modifier: ($) => "pub",
176
326
 
177
327
  /* Literals */
178
328
  float: ($) => /-?[0-9_]+\.[0-9_]*(e-?[0-9_]+)?/,
@@ -180,9 +330,9 @@ module.exports = grammar({
180
330
  seq(optional("-"), choice($._hex, $._decimal, $._octal, $._binary)),
181
331
  string: ($) =>
182
332
  seq(
183
- '"',
333
+ `"`,
184
334
  repeat(choice($.escape_sequence, $.quoted_content)),
185
- token.immediate('"')
335
+ token.immediate(`"`)
186
336
  ),
187
337
  _hex: ($) => /0[xX][0-9a-fA-F_]+/,
188
338
  _decimal: ($) => /[0-9][0-9_]*/,
@@ -192,12 +342,17 @@ module.exports = grammar({
192
342
  escape_sequence: ($) => token.immediate(/\\[efnrt\"\\]/),
193
343
  // identifier: ($) => $._name,
194
344
  identifier: ($) => /[a-zA-Z_][a-zA-Z_0-9]*/,
345
+ label: ($) => $._name,
346
+ discard: ($) => $._discard_name,
195
347
  type_identifier: ($) => $._upname,
348
+ constructor_name: ($) => $._upname,
196
349
  remote_type_identifier: ($) =>
197
350
  seq(field("module", $.identifier), ".", field("name", $.type_identifier)),
198
351
  _type_annotation: ($) => seq(":", field("type", $._type)),
199
352
  _type: ($) =>
200
353
  choice($.type, $.generic, $.function_type),
354
+
355
+
201
356
  _discard_name: ($) => /_[_0-9a-z]*/,
202
357
  _name: ($) => /[_a-z][_0-9a-z]*/,
203
358
  _upname: ($) => /[A-Z][0-9a-zA-Z]*/,
src/grammar.json CHANGED
@@ -288,6 +288,18 @@
288
288
  "struct": {
289
289
  "type": "SEQ",
290
290
  "members": [
291
+ {
292
+ "type": "CHOICE",
293
+ "members": [
294
+ {
295
+ "type": "SYMBOL",
296
+ "name": "visibility_modifier"
297
+ },
298
+ {
299
+ "type": "BLANK"
300
+ }
301
+ ]
302
+ },
291
303
  {
292
304
  "type": "STRING",
293
305
  "value": "type"
@@ -345,6 +357,18 @@
345
357
  "enum": {
346
358
  "type": "SEQ",
347
359
  "members": [
360
+ {
361
+ "type": "CHOICE",
362
+ "members": [
363
+ {
364
+ "type": "SYMBOL",
365
+ "name": "visibility_modifier"
366
+ },
367
+ {
368
+ "type": "BLANK"
369
+ }
370
+ ]
371
+ },
348
372
  {
349
373
  "type": "STRING",
350
374
  "value": "type"
@@ -511,6 +535,18 @@
511
535
  "function": {
512
536
  "type": "SEQ",
513
537
  "members": [
538
+ {
539
+ "type": "CHOICE",
540
+ "members": [
541
+ {
542
+ "type": "SYMBOL",
543
+ "name": "visibility_modifier"
544
+ },
545
+ {
546
+ "type": "BLANK"
547
+ }
548
+ ]
549
+ },
514
550
  {
515
551
  "type": "STRING",
516
552
  "value": "fn"
@@ -589,8 +625,16 @@
589
625
  "type": "FIELD",
590
626
  "name": "return",
591
627
  "content": {
628
+ "type": "CHOICE",
629
+ "members": [
630
+ {
592
- "type": "SYMBOL",
631
+ "type": "SYMBOL",
593
- "name": "return_type"
632
+ "name": "return_type"
633
+ },
634
+ {
635
+ "type": "BLANK"
636
+ }
637
+ ]
594
638
  }
595
639
  },
596
640
  {
@@ -616,6 +660,14 @@
616
660
  }
617
661
  ]
618
662
  },
663
+ "_name_param": {
664
+ "type": "FIELD",
665
+ "name": "name",
666
+ "content": {
667
+ "type": "SYMBOL",
668
+ "name": "identifier"
669
+ }
670
+ },
619
671
  "_statement_seq": {
620
672
  "type": "REPEAT1",
621
673
  "content": {
@@ -1168,76 +1220,191 @@
1168
1220
  "type": "SYMBOL",
1169
1221
  "name": "identifier"
1170
1222
  },
1223
+ {
1224
+ "type": "SYMBOL",
1225
+ "name": "anonymous_function"
1226
+ },
1171
1227
  {
1172
1228
  "type": "SYMBOL",
1173
1229
  "name": "expression_group"
1174
1230
  },
1175
1231
  {
1176
1232
  "type": "SYMBOL",
1177
- "name": "negation"
1233
+ "name": "when"
1178
- }
1179
- ]
1180
- },
1234
+ },
1181
- "expression_group": {
1182
- "type": "SEQ",
1183
- "members": [
1184
1235
  {
1185
- "type": "STRING",
1236
+ "type": "SYMBOL",
1186
- "value": "{"
1237
+ "name": "negation"
1187
1238
  },
1188
1239
  {
1189
1240
  "type": "SYMBOL",
1190
- "name": "_statement_seq"
1241
+ "name": "field_access"
1191
1242
  },
1192
1243
  {
1193
- "type": "STRING",
1244
+ "type": "SYMBOL",
1194
- "value": "}"
1245
+ "name": "function_call"
1195
1246
  }
1196
1247
  ]
1197
1248
  },
1198
- "negation": {
1249
+ "record": {
1199
1250
  "type": "SEQ",
1200
1251
  "members": [
1201
1252
  {
1253
+ "type": "FIELD",
1254
+ "name": "name",
1255
+ "content": {
1202
- "type": "STRING",
1256
+ "type": "SYMBOL",
1203
- "value": "!"
1257
+ "name": "constructor_name"
1258
+ }
1204
1259
  },
1205
1260
  {
1261
+ "type": "CHOICE",
1262
+ "members": [
1263
+ {
1264
+ "type": "FIELD",
1265
+ "name": "arguments",
1266
+ "content": {
1206
- "type": "SYMBOL",
1267
+ "type": "SYMBOL",
1207
- "name": "_expression_unit"
1268
+ "name": "arguments"
1269
+ }
1270
+ },
1271
+ {
1272
+ "type": "BLANK"
1273
+ }
1274
+ ]
1208
1275
  }
1209
1276
  ]
1210
1277
  },
1211
- "let": {
1278
+ "list": {
1212
1279
  "type": "SEQ",
1213
1280
  "members": [
1214
1281
  {
1215
1282
  "type": "STRING",
1216
- "value": "let"
1283
+ "value": "["
1217
1284
  },
1218
1285
  {
1286
+ "type": "CHOICE",
1287
+ "members": [
1288
+ {
1289
+ "type": "SEQ",
1290
+ "members": [
1291
+ {
1219
- "type": "SYMBOL",
1292
+ "type": "SYMBOL",
1220
- "name": "_assignment"
1293
+ "name": "_expression"
1294
+ },
1295
+ {
1296
+ "type": "CHOICE",
1297
+ "members": [
1298
+ {
1299
+ "type": "REPEAT",
1300
+ "content": {
1301
+ "type": "SEQ",
1302
+ "members": [
1303
+ {
1304
+ "type": "STRING",
1305
+ "value": ","
1306
+ },
1307
+ {
1308
+ "type": "SYMBOL",
1309
+ "name": "_expression"
1310
+ }
1311
+ ]
1312
+ }
1313
+ },
1314
+ {
1315
+ "type": "BLANK"
1316
+ }
1317
+ ]
1318
+ },
1319
+ {
1320
+ "type": "CHOICE",
1321
+ "members": [
1322
+ {
1323
+ "type": "STRING",
1324
+ "value": ","
1325
+ },
1326
+ {
1327
+ "type": "BLANK"
1328
+ }
1329
+ ]
1330
+ },
1331
+ {
1332
+ "type": "CHOICE",
1333
+ "members": [
1334
+ {
1335
+ "type": "SEQ",
1336
+ "members": [
1337
+ {
1338
+ "type": "STRING",
1339
+ "value": ".."
1340
+ },
1341
+ {
1342
+ "type": "FIELD",
1343
+ "name": "spread",
1344
+ "content": {
1345
+ "type": "SYMBOL",
1346
+ "name": "_expression"
1347
+ }
1348
+ }
1349
+ ]
1350
+ },
1351
+ {
1352
+ "type": "BLANK"
1353
+ }
1354
+ ]
1355
+ }
1356
+ ]
1357
+ },
1358
+ {
1359
+ "type": "BLANK"
1360
+ }
1361
+ ]
1362
+ },
1363
+ {
1364
+ "type": "STRING",
1365
+ "value": "]"
1221
1366
  }
1222
1367
  ]
1223
1368
  },
1224
- "_assignment": {
1369
+ "anonymous_function": {
1225
1370
  "type": "SEQ",
1226
1371
  "members": [
1372
+ {
1373
+ "type": "STRING",
1374
+ "value": "fn"
1375
+ },
1227
1376
  {
1228
1377
  "type": "FIELD",
1229
- "name": "pattern",
1378
+ "name": "parameters",
1230
1379
  "content": {
1380
+ "type": "ALIAS",
1381
+ "content": {
1231
- "type": "SYMBOL",
1382
+ "type": "SYMBOL",
1383
+ "name": "anonymous_function_parameters"
1384
+ },
1385
+ "named": true,
1232
- "name": "_pattern"
1386
+ "value": "function_parameters"
1233
1387
  }
1234
1388
  },
1235
1389
  {
1236
1390
  "type": "CHOICE",
1237
1391
  "members": [
1238
1392
  {
1393
+ "type": "SEQ",
1394
+ "members": [
1395
+ {
1396
+ "type": "STRING",
1397
+ "value": "->"
1398
+ },
1399
+ {
1400
+ "type": "FIELD",
1401
+ "name": "return_type",
1402
+ "content": {
1239
- "type": "SYMBOL",
1403
+ "type": "SYMBOL",
1240
- "name": "_type_annotation"
1404
+ "name": "_type"
1405
+ }
1406
+ }
1407
+ ]
1241
1408
  },
1242
1409
  {
1243
1410
  "type": "BLANK"
@@ -1246,59 +1413,673 @@
1246
1413
  },
1247
1414
  {
1248
1415
  "type": "STRING",
1249
- "value": "="
1416
+ "value": "{"
1250
1417
  },
1251
1418
  {
1252
1419
  "type": "FIELD",
1253
- "name": "value",
1420
+ "name": "body",
1254
1421
  "content": {
1422
+ "type": "ALIAS",
1423
+ "content": {
1255
- "type": "SYMBOL",
1424
+ "type": "SYMBOL",
1256
- "name": "_expression"
1425
+ "name": "_statement_seq"
1426
+ },
1427
+ "named": true,
1428
+ "value": "function_body"
1257
1429
  }
1430
+ },
1431
+ {
1432
+ "type": "STRING",
1433
+ "value": "}"
1258
1434
  }
1259
1435
  ]
1260
1436
  },
1261
- "_pattern": {
1437
+ "anonymous_function_parameters": {
1262
1438
  "type": "SEQ",
1263
1439
  "members": [
1264
1440
  {
1265
- "type": "SYMBOL",
1441
+ "type": "STRING",
1266
- "name": "_pattern_expression"
1442
+ "value": "("
1267
1443
  },
1268
1444
  {
1269
1445
  "type": "CHOICE",
1270
1446
  "members": [
1271
1447
  {
1272
- "type": "FIELD",
1448
+ "type": "SEQ",
1449
+ "members": [
1450
+ {
1273
- "name": "assign",
1451
+ "type": "ALIAS",
1274
- "content": {
1452
+ "content": {
1275
- "type": "SEQ",
1276
- "members": [
1277
- {
1278
- "type": "STRING",
1279
- "value": "as"
1280
- },
1281
- {
1282
1453
  "type": "SYMBOL",
1454
+ "name": "anonymous_function_parameter"
1455
+ },
1456
+ "named": true,
1457
+ "value": "function_parameter"
1458
+ },
1459
+ {
1460
+ "type": "REPEAT",
1461
+ "content": {
1462
+ "type": "SEQ",
1463
+ "members": [
1464
+ {
1465
+ "type": "STRING",
1283
- "name": "identifier"
1466
+ "value": ","
1467
+ },
1468
+ {
1469
+ "type": "ALIAS",
1470
+ "content": {
1471
+ "type": "SYMBOL",
1472
+ "name": "anonymous_function_parameter"
1473
+ },
1474
+ "named": true,
1475
+ "value": "function_parameter"
1476
+ }
1477
+ ]
1284
1478
  }
1479
+ },
1480
+ {
1481
+ "type": "CHOICE",
1482
+ "members": [
1483
+ {
1484
+ "type": "STRING",
1485
+ "value": ","
1486
+ },
1487
+ {
1488
+ "type": "BLANK"
1489
+ }
1285
- ]
1490
+ ]
1286
- }
1491
+ }
1492
+ ]
1287
1493
  },
1288
1494
  {
1289
1495
  "type": "BLANK"
1290
1496
  }
1291
1497
  ]
1498
+ },
1499
+ {
1500
+ "type": "STRING",
1501
+ "value": ")"
1292
1502
  }
1293
1503
  ]
1294
1504
  },
1505
+ "_discard_param": {
1506
+ "type": "FIELD",
1507
+ "name": "name",
1508
+ "content": {
1509
+ "type": "SYMBOL",
1510
+ "name": "discard"
1511
+ }
1512
+ },
1513
+ "anonymous_function_parameter": {
1514
+ "type": "SEQ",
1515
+ "members": [
1516
+ {
1517
+ "type": "CHOICE",
1518
+ "members": [
1519
+ {
1520
+ "type": "SYMBOL",
1521
+ "name": "_discard_param"
1522
+ },
1523
+ {
1524
+ "type": "SYMBOL",
1525
+ "name": "_name_param"
1526
+ }
1527
+ ]
1528
+ },
1529
+ {
1530
+ "type": "CHOICE",
1531
+ "members": [
1532
+ {
1533
+ "type": "SYMBOL",
1534
+ "name": "_type_annotation"
1535
+ },
1536
+ {
1537
+ "type": "BLANK"
1538
+ }
1539
+ ]
1540
+ }
1541
+ ]
1542
+ },
1543
+ "expression_group": {
1544
+ "type": "SEQ",
1545
+ "members": [
1546
+ {
1547
+ "type": "STRING",
1548
+ "value": "{"
1549
+ },
1550
+ {
1551
+ "type": "SYMBOL",
1552
+ "name": "_statement_seq"
1553
+ },
1554
+ {
1555
+ "type": "STRING",
1556
+ "value": "}"
1557
+ }
1558
+ ]
1559
+ },
1560
+ "when": {
1561
+ "type": "SEQ",
1562
+ "members": [
1563
+ {
1564
+ "type": "STRING",
1565
+ "value": "when"
1566
+ },
1567
+ {
1568
+ "type": "CHOICE",
1569
+ "members": [
1570
+ {
1571
+ "type": "SYMBOL",
1572
+ "name": "_expression"
1573
+ },
1574
+ {
1575
+ "type": "BLANK"
1576
+ }
1577
+ ]
1578
+ },
1579
+ {
1580
+ "type": "STRING",
1581
+ "value": "{"
1582
+ },
1583
+ {
1584
+ "type": "REPEAT",
1585
+ "content": {
1586
+ "type": "SYMBOL",
1587
+ "name": "when_entry"
1588
+ }
1589
+ },
1590
+ {
1591
+ "type": "STRING",
1592
+ "value": "}"
1593
+ }
1594
+ ]
1595
+ },
1596
+ "when_entry": {
1597
+ "type": "SEQ",
1598
+ "members": [
1599
+ {
1600
+ "type": "CHOICE",
1601
+ "members": [
1602
+ {
1603
+ "type": "SEQ",
1604
+ "members": [
1605
+ {
1606
+ "type": "SYMBOL",
1607
+ "name": "_expression"
1608
+ },
1609
+ {
1610
+ "type": "REPEAT",
1611
+ "content": {
1612
+ "type": "SEQ",
1613
+ "members": [
1614
+ {
1615
+ "type": "STRING",
1616
+ "value": ","
1617
+ },
1618
+ {
1619
+ "type": "SYMBOL",
1620
+ "name": "_expression"
1621
+ }
1622
+ ]
1623
+ }
1624
+ }
1625
+ ]
1626
+ },
1627
+ {
1628
+ "type": "STRING",
1629
+ "value": "_"
1630
+ }
1631
+ ]
1632
+ },
1633
+ {
1634
+ "type": "STRING",
1635
+ "value": "->"
1636
+ },
1637
+ {
1638
+ "type": "SYMBOL",
1639
+ "name": "_expression"
1640
+ }
1641
+ ]
1642
+ },
1643
+ "_maybe_record_expression": {
1644
+ "type": "CHOICE",
1645
+ "members": [
1646
+ {
1647
+ "type": "SYMBOL",
1648
+ "name": "record"
1649
+ },
1650
+ {
1651
+ "type": "SYMBOL",
1652
+ "name": "identifier"
1653
+ },
1654
+ {
1655
+ "type": "SYMBOL",
1656
+ "name": "function_call"
1657
+ },
1658
+ {
1659
+ "type": "SYMBOL",
1660
+ "name": "expression_group"
1661
+ },
1662
+ {
1663
+ "type": "SYMBOL",
1664
+ "name": "when"
1665
+ },
1666
+ {
1667
+ "type": "SYMBOL",
1668
+ "name": "field_access"
1669
+ }
1670
+ ]
1671
+ },
1672
+ "field_access": {
1673
+ "type": "PREC_LEFT",
1674
+ "value": 0,
1675
+ "content": {
1676
+ "type": "SEQ",
1677
+ "members": [
1678
+ {
1679
+ "type": "FIELD",
1680
+ "name": "record",
1681
+ "content": {
1682
+ "type": "SYMBOL",
1683
+ "name": "_maybe_record_expression"
1684
+ }
1685
+ },
1686
+ {
1687
+ "type": "STRING",
1688
+ "value": "."
1689
+ },
1690
+ {
1691
+ "type": "FIELD",
1692
+ "name": "field",
1693
+ "content": {
1694
+ "type": "SYMBOL",
1695
+ "name": "label"
1696
+ }
1697
+ }
1698
+ ]
1699
+ }
1700
+ },
1701
+ "arguments": {
1702
+ "type": "SEQ",
1703
+ "members": [
1704
+ {
1705
+ "type": "STRING",
1706
+ "value": "("
1707
+ },
1708
+ {
1709
+ "type": "CHOICE",
1710
+ "members": [
1711
+ {
1712
+ "type": "SEQ",
1713
+ "members": [
1714
+ {
1715
+ "type": "SYMBOL",
1716
+ "name": "argument"
1717
+ },
1718
+ {
1719
+ "type": "REPEAT",
1720
+ "content": {
1721
+ "type": "SEQ",
1722
+ "members": [
1723
+ {
1724
+ "type": "STRING",
1725
+ "value": ","
1726
+ },
1727
+ {
1728
+ "type": "SYMBOL",
1729
+ "name": "argument"
1730
+ }
1731
+ ]
1732
+ }
1733
+ },
1734
+ {
1735
+ "type": "CHOICE",
1736
+ "members": [
1737
+ {
1738
+ "type": "STRING",
1739
+ "value": ","
1740
+ },
1741
+ {
1742
+ "type": "BLANK"
1743
+ }
1744
+ ]
1745
+ }
1746
+ ]
1747
+ },
1748
+ {
1749
+ "type": "BLANK"
1750
+ }
1751
+ ]
1752
+ },
1753
+ {
1754
+ "type": "STRING",
1755
+ "value": ")"
1756
+ }
1757
+ ]
1758
+ },
1759
+ "argument": {
1760
+ "type": "SEQ",
1761
+ "members": [
1762
+ {
1763
+ "type": "CHOICE",
1764
+ "members": [
1765
+ {
1766
+ "type": "SEQ",
1767
+ "members": [
1768
+ {
1769
+ "type": "FIELD",
1770
+ "name": "label",
1771
+ "content": {
1772
+ "type": "SYMBOL",
1773
+ "name": "label"
1774
+ }
1775
+ },
1776
+ {
1777
+ "type": "STRING",
1778
+ "value": ":"
1779
+ }
1780
+ ]
1781
+ },
1782
+ {
1783
+ "type": "BLANK"
1784
+ }
1785
+ ]
1786
+ },
1787
+ {
1788
+ "type": "FIELD",
1789
+ "name": "value",
1790
+ "content": {
1791
+ "type": "CHOICE",
1792
+ "members": [
1793
+ {
1794
+ "type": "SYMBOL",
1795
+ "name": "hole"
1796
+ },
1797
+ {
1798
+ "type": "SYMBOL",
1799
+ "name": "_expression"
1800
+ }
1801
+ ]
1802
+ }
1803
+ }
1804
+ ]
1805
+ },
1806
+ "hole": {
1807
+ "type": "SYMBOL",
1808
+ "name": "_discard_name"
1809
+ },
1810
+ "function_call": {
1811
+ "type": "SEQ",
1812
+ "members": [
1813
+ {
1814
+ "type": "FIELD",
1815
+ "name": "function",
1816
+ "content": {
1817
+ "type": "SYMBOL",
1818
+ "name": "_maybe_function_expression"
1819
+ }
1820
+ },
1821
+ {
1822
+ "type": "FIELD",
1823
+ "name": "arguments",
1824
+ "content": {
1825
+ "type": "SYMBOL",
1826
+ "name": "arguments"
1827
+ }
1828
+ }
1829
+ ]
1830
+ },
1831
+ "_maybe_function_expression": {
1832
+ "type": "CHOICE",
1833
+ "members": [
1834
+ {
1835
+ "type": "SYMBOL",
1836
+ "name": "identifier"
1837
+ },
1838
+ {
1839
+ "type": "SYMBOL",
1840
+ "name": "anonymous_function"
1841
+ },
1842
+ {
1843
+ "type": "SYMBOL",
1844
+ "name": "expression_group"
1845
+ },
1846
+ {
1847
+ "type": "SYMBOL",
1848
+ "name": "when"
1849
+ },
1850
+ {
1851
+ "type": "SYMBOL",
1852
+ "name": "field_access"
1853
+ },
1854
+ {
1855
+ "type": "SYMBOL",
1856
+ "name": "function_call"
1857
+ }
1858
+ ]
1859
+ },
1860
+ "negation": {
1861
+ "type": "SEQ",
1862
+ "members": [
1863
+ {
1864
+ "type": "STRING",
1865
+ "value": "!"
1866
+ },
1867
+ {
1868
+ "type": "SYMBOL",
1869
+ "name": "_expression_unit"
1870
+ }
1871
+ ]
1872
+ },
1873
+ "let": {
1874
+ "type": "SEQ",
1875
+ "members": [
1876
+ {
1877
+ "type": "STRING",
1878
+ "value": "let"
1879
+ },
1880
+ {
1881
+ "type": "SYMBOL",
1882
+ "name": "_assignment"
1883
+ }
1884
+ ]
1885
+ },
1886
+ "_assignment": {
1887
+ "type": "SEQ",
1888
+ "members": [
1889
+ {
1890
+ "type": "FIELD",
1891
+ "name": "pattern",
1892
+ "content": {
1893
+ "type": "SYMBOL",
1894
+ "name": "_pattern"
1895
+ }
1896
+ },
1897
+ {
1898
+ "type": "CHOICE",
1899
+ "members": [
1900
+ {
1901
+ "type": "SYMBOL",
1902
+ "name": "_type_annotation"
1903
+ },
1904
+ {
1905
+ "type": "BLANK"
1906
+ }
1907
+ ]
1908
+ },
1909
+ {
1910
+ "type": "STRING",
1911
+ "value": "="
1912
+ },
1913
+ {
1914
+ "type": "FIELD",
1915
+ "name": "value",
1916
+ "content": {
1917
+ "type": "SYMBOL",
1918
+ "name": "_expression"
1919
+ }
1920
+ }
1921
+ ]
1922
+ },
1923
+ "record_update": {
1924
+ "type": "SEQ",
1925
+ "members": [
1926
+ {
1927
+ "type": "FIELD",
1928
+ "name": "constructor",
1929
+ "content": {
1930
+ "type": "SYMBOL",
1931
+ "name": "constructor_name"
1932
+ }
1933
+ },
1934
+ {
1935
+ "type": "STRING",
1936
+ "value": "("
1937
+ },
1938
+ {
1939
+ "type": "STRING",
1940
+ "value": ".."
1941
+ },
1942
+ {
1943
+ "type": "FIELD",
1944
+ "name": "spread",
1945
+ "content": {
1946
+ "type": "SYMBOL",
1947
+ "name": "_expression"
1948
+ }
1949
+ },
1950
+ {
1951
+ "type": "STRING",
1952
+ "value": ","
1953
+ },
1954
+ {
1955
+ "type": "FIELD",
1956
+ "name": "arguments",
1957
+ "content": {
1958
+ "type": "SYMBOL",
1959
+ "name": "record_update_arguments"
1960
+ }
1961
+ },
1962
+ {
1963
+ "type": "STRING",
1964
+ "value": ")"
1965
+ }
1966
+ ]
1967
+ },
1968
+ "record_update_arguments": {
1969
+ "type": "SEQ",
1970
+ "members": [
1971
+ {
1972
+ "type": "SYMBOL",
1973
+ "name": "record_update_argument"
1974
+ },
1975
+ {
1976
+ "type": "REPEAT",
1977
+ "content": {
1978
+ "type": "SEQ",
1979
+ "members": [
1980
+ {
1981
+ "type": "STRING",
1982
+ "value": ","
1983
+ },
1984
+ {
1985
+ "type": "SYMBOL",
1986
+ "name": "record_update_argument"
1987
+ }
1988
+ ]
1989
+ }
1990
+ },
1991
+ {
1992
+ "type": "CHOICE",
1993
+ "members": [
1994
+ {
1995
+ "type": "STRING",
1996
+ "value": ","
1997
+ },
1998
+ {
1999
+ "type": "BLANK"
2000
+ }
2001
+ ]
2002
+ }
2003
+ ]
2004
+ },
2005
+ "record_update_argument": {
2006
+ "type": "SEQ",
2007
+ "members": [
2008
+ {
2009
+ "type": "FIELD",
2010
+ "name": "label",
2011
+ "content": {
2012
+ "type": "SYMBOL",
2013
+ "name": "label"
2014
+ }
2015
+ },
2016
+ {
2017
+ "type": "STRING",
2018
+ "value": ":"
2019
+ },
2020
+ {
2021
+ "type": "FIELD",
2022
+ "name": "value",
2023
+ "content": {
2024
+ "type": "SYMBOL",
2025
+ "name": "_expression"
2026
+ }
2027
+ }
2028
+ ]
2029
+ },
2030
+ "_pattern": {
2031
+ "type": "SEQ",
2032
+ "members": [
2033
+ {
2034
+ "type": "SYMBOL",
2035
+ "name": "_pattern_expression"
2036
+ },
2037
+ {
2038
+ "type": "CHOICE",
2039
+ "members": [
2040
+ {
2041
+ "type": "FIELD",
2042
+ "name": "assign",
2043
+ "content": {
2044
+ "type": "SEQ",
2045
+ "members": [
2046
+ {
2047
+ "type": "STRING",
2048
+ "value": "as"
2049
+ },
2050
+ {
2051
+ "type": "SYMBOL",
2052
+ "name": "identifier"
2053
+ }
2054
+ ]
2055
+ }
2056
+ },
2057
+ {
2058
+ "type": "BLANK"
2059
+ }
2060
+ ]
2061
+ }
2062
+ ]
2063
+ },
1295
- "_pattern_expression": {
2064
+ "_pattern_expression": {
1296
- "type": "CHOICE",
2065
+ "type": "CHOICE",
1297
2066
  "members": [
1298
2067
  {
1299
2068
  "type": "SYMBOL",
1300
2069
  "name": "identifier"
1301
2070
  },
2071
+ {
2072
+ "type": "SYMBOL",
2073
+ "name": "discard"
2074
+ },
2075
+ {
2076
+ "type": "SYMBOL",
2077
+ "name": "record_pattern"
2078
+ },
2079
+ {
2080
+ "type": "SYMBOL",
2081
+ "name": "string"
2082
+ },
1302
2083
  {
1303
2084
  "type": "SYMBOL",
1304
2085
  "name": "integer"
@@ -1351,6 +2132,164 @@
1351
2132
  ]
1352
2133
  }
1353
2134
  },
2135
+ "record_pattern": {
2136
+ "type": "SEQ",
2137
+ "members": [
2138
+ {
2139
+ "type": "FIELD",
2140
+ "name": "name",
2141
+ "content": {
2142
+ "type": "SYMBOL",
2143
+ "name": "constructor_name"
2144
+ }
2145
+ },
2146
+ {
2147
+ "type": "CHOICE",
2148
+ "members": [
2149
+ {
2150
+ "type": "FIELD",
2151
+ "name": "arguments",
2152
+ "content": {
2153
+ "type": "SYMBOL",
2154
+ "name": "record_pattern_arguments"
2155
+ }
2156
+ },
2157
+ {
2158
+ "type": "BLANK"
2159
+ }
2160
+ ]
2161
+ }
2162
+ ]
2163
+ },
2164
+ "record_pattern_arguments": {
2165
+ "type": "SEQ",
2166
+ "members": [
2167
+ {
2168
+ "type": "STRING",
2169
+ "value": "("
2170
+ },
2171
+ {
2172
+ "type": "CHOICE",
2173
+ "members": [
2174
+ {
2175
+ "type": "SEQ",
2176
+ "members": [
2177
+ {
2178
+ "type": "SYMBOL",
2179
+ "name": "record_pattern_argument"
2180
+ },
2181
+ {
2182
+ "type": "REPEAT",
2183
+ "content": {
2184
+ "type": "SEQ",
2185
+ "members": [
2186
+ {
2187
+ "type": "STRING",
2188
+ "value": ","
2189
+ },
2190
+ {
2191
+ "type": "SYMBOL",
2192
+ "name": "record_pattern_argument"
2193
+ }
2194
+ ]
2195
+ }
2196
+ },
2197
+ {
2198
+ "type": "CHOICE",
2199
+ "members": [
2200
+ {
2201
+ "type": "STRING",
2202
+ "value": ","
2203
+ },
2204
+ {
2205
+ "type": "BLANK"
2206
+ }
2207
+ ]
2208
+ }
2209
+ ]
2210
+ },
2211
+ {
2212
+ "type": "BLANK"
2213
+ }
2214
+ ]
2215
+ },
2216
+ {
2217
+ "type": "CHOICE",
2218
+ "members": [
2219
+ {
2220
+ "type": "SYMBOL",
2221
+ "name": "pattern_spread"
2222
+ },
2223
+ {
2224
+ "type": "BLANK"
2225
+ }
2226
+ ]
2227
+ },
2228
+ {
2229
+ "type": "STRING",
2230
+ "value": ")"
2231
+ }
2232
+ ]
2233
+ },
2234
+ "record_pattern_argument": {
2235
+ "type": "SEQ",
2236
+ "members": [
2237
+ {
2238
+ "type": "CHOICE",
2239
+ "members": [
2240
+ {
2241
+ "type": "SEQ",
2242
+ "members": [
2243
+ {
2244
+ "type": "FIELD",
2245
+ "name": "label",
2246
+ "content": {
2247
+ "type": "SYMBOL",
2248
+ "name": "label"
2249
+ }
2250
+ },
2251
+ {
2252
+ "type": "STRING",
2253
+ "value": ":"
2254
+ }
2255
+ ]
2256
+ },
2257
+ {
2258
+ "type": "BLANK"
2259
+ }
2260
+ ]
2261
+ },
2262
+ {
2263
+ "type": "FIELD",
2264
+ "name": "pattern",
2265
+ "content": {
2266
+ "type": "SYMBOL",
2267
+ "name": "_pattern"
2268
+ }
2269
+ }
2270
+ ]
2271
+ },
2272
+ "pattern_spread": {
2273
+ "type": "SEQ",
2274
+ "members": [
2275
+ {
2276
+ "type": "STRING",
2277
+ "value": ".."
2278
+ },
2279
+ {
2280
+ "type": "CHOICE",
2281
+ "members": [
2282
+ {
2283
+ "type": "STRING",
2284
+ "value": ","
2285
+ },
2286
+ {
2287
+ "type": "BLANK"
2288
+ }
2289
+ ]
2290
+ }
2291
+ ]
2292
+ },
1354
2293
  "field": {
1355
2294
  "type": "SEQ",
1356
2295
  "members": [
@@ -1633,6 +2572,10 @@
1633
2572
  "type": "PATTERN",
1634
2573
  "value": "[a-z][a-z]*"
1635
2574
  },
2575
+ "visibility_modifier": {
2576
+ "type": "STRING",
2577
+ "value": "pub"
2578
+ },
1636
2579
  "float": {
1637
2580
  "type": "PATTERN",
1638
2581
  "value": "-?[0-9_]+\\.[0-9_]*(e-?[0-9_]+)?"
@@ -1756,10 +2699,22 @@
1756
2699
  "type": "PATTERN",
1757
2700
  "value": "[a-zA-Z_][a-zA-Z_0-9]*"
1758
2701
  },
2702
+ "label": {
2703
+ "type": "SYMBOL",
2704
+ "name": "_name"
2705
+ },
2706
+ "discard": {
2707
+ "type": "SYMBOL",
2708
+ "name": "_discard_name"
2709
+ },
1759
2710
  "type_identifier": {
1760
2711
  "type": "SYMBOL",
1761
2712
  "name": "_upname"
1762
2713
  },
2714
+ "constructor_name": {
2715
+ "type": "SYMBOL",
2716
+ "name": "_upname"
2717
+ },
1763
2718
  "remote_type_identifier": {
1764
2719
  "type": "SEQ",
1765
2720
  "members": [
src/node-types.json CHANGED
@@ -1,4 +1,133 @@
1
1
  [
2
+ {
3
+ "type": "anonymous_function",
4
+ "named": true,
5
+ "fields": {
6
+ "body": {
7
+ "multiple": false,
8
+ "required": true,
9
+ "types": [
10
+ {
11
+ "type": "function_body",
12
+ "named": true
13
+ }
14
+ ]
15
+ },
16
+ "parameters": {
17
+ "multiple": false,
18
+ "required": true,
19
+ "types": [
20
+ {
21
+ "type": "function_parameters",
22
+ "named": true
23
+ }
24
+ ]
25
+ },
26
+ "return_type": {
27
+ "multiple": false,
28
+ "required": false,
29
+ "types": [
30
+ {
31
+ "type": "function_type",
32
+ "named": true
33
+ },
34
+ {
35
+ "type": "generic",
36
+ "named": true
37
+ },
38
+ {
39
+ "type": "type",
40
+ "named": true
41
+ }
42
+ ]
43
+ }
44
+ }
45
+ },
46
+ {
47
+ "type": "argument",
48
+ "named": true,
49
+ "fields": {
50
+ "label": {
51
+ "multiple": false,
52
+ "required": false,
53
+ "types": [
54
+ {
55
+ "type": "label",
56
+ "named": true
57
+ }
58
+ ]
59
+ },
60
+ "value": {
61
+ "multiple": false,
62
+ "required": true,
63
+ "types": [
64
+ {
65
+ "type": "anonymous_function",
66
+ "named": true
67
+ },
68
+ {
69
+ "type": "binary_expression",
70
+ "named": true
71
+ },
72
+ {
73
+ "type": "expression_group",
74
+ "named": true
75
+ },
76
+ {
77
+ "type": "field_access",
78
+ "named": true
79
+ },
80
+ {
81
+ "type": "float",
82
+ "named": true
83
+ },
84
+ {
85
+ "type": "function_call",
86
+ "named": true
87
+ },
88
+ {
89
+ "type": "hole",
90
+ "named": true
91
+ },
92
+ {
93
+ "type": "identifier",
94
+ "named": true
95
+ },
96
+ {
97
+ "type": "integer",
98
+ "named": true
99
+ },
100
+ {
101
+ "type": "negation",
102
+ "named": true
103
+ },
104
+ {
105
+ "type": "string",
106
+ "named": true
107
+ },
108
+ {
109
+ "type": "when",
110
+ "named": true
111
+ }
112
+ ]
113
+ }
114
+ }
115
+ },
116
+ {
117
+ "type": "arguments",
118
+ "named": true,
119
+ "fields": {},
120
+ "children": {
121
+ "multiple": true,
122
+ "required": false,
123
+ "types": [
124
+ {
125
+ "type": "argument",
126
+ "named": true
127
+ }
128
+ ]
129
+ }
130
+ },
2
131
  {
3
132
  "type": "binary_expression",
4
133
  "named": true,
@@ -7,18 +136,34 @@
7
136
  "multiple": false,
8
137
  "required": true,
9
138
  "types": [
139
+ {
140
+ "type": "anonymous_function",
141
+ "named": true
142
+ },
10
143
  {
11
144
  "type": "binary_expression",
12
145
  "named": true
13
146
  },
147
+ {
148
+ "type": "discard",
149
+ "named": true
150
+ },
14
151
  {
15
152
  "type": "expression_group",
16
153
  "named": true
17
154
  },
155
+ {
156
+ "type": "field_access",
157
+ "named": true
158
+ },
18
159
  {
19
160
  "type": "float",
20
161
  "named": true
21
162
  },
163
+ {
164
+ "type": "function_call",
165
+ "named": true
166
+ },
22
167
  {
23
168
  "type": "identifier",
24
169
  "named": true
@@ -31,9 +176,17 @@
31
176
  "type": "negation",
32
177
  "named": true
33
178
  },
179
+ {
180
+ "type": "record_pattern",
181
+ "named": true
182
+ },
34
183
  {
35
184
  "type": "string",
36
185
  "named": true
186
+ },
187
+ {
188
+ "type": "when",
189
+ "named": true
37
190
  }
38
191
  ]
39
192
  },
@@ -107,18 +260,34 @@
107
260
  "multiple": false,
108
261
  "required": true,
109
262
  "types": [
263
+ {
264
+ "type": "anonymous_function",
265
+ "named": true
266
+ },
110
267
  {
111
268
  "type": "binary_expression",
112
269
  "named": true
113
270
  },
271
+ {
272
+ "type": "discard",
273
+ "named": true
274
+ },
114
275
  {
115
276
  "type": "expression_group",
116
277
  "named": true
117
278
  },
279
+ {
280
+ "type": "field_access",
281
+ "named": true
282
+ },
118
283
  {
119
284
  "type": "float",
120
285
  "named": true
121
286
  },
287
+ {
288
+ "type": "function_call",
289
+ "named": true
290
+ },
122
291
  {
123
292
  "type": "identifier",
124
293
  "named": true
@@ -131,14 +300,32 @@
131
300
  "type": "negation",
132
301
  "named": true
133
302
  },
303
+ {
304
+ "type": "record_pattern",
305
+ "named": true
306
+ },
134
307
  {
135
308
  "type": "string",
136
309
  "named": true
310
+ },
311
+ {
312
+ "type": "when",
313
+ "named": true
137
314
  }
138
315
  ]
139
316
  }
140
317
  }
141
318
  },
319
+ {
320
+ "type": "constructor_name",
321
+ "named": true,
322
+ "fields": {}
323
+ },
324
+ {
325
+ "type": "discard",
326
+ "named": true,
327
+ "fields": {}
328
+ },
142
329
  {
143
330
  "type": "enum",
144
331
  "named": true,
@@ -201,6 +388,16 @@
201
388
  }
202
389
  ]
203
390
  }
391
+ },
392
+ "children": {
393
+ "multiple": false,
394
+ "required": false,
395
+ "types": [
396
+ {
397
+ "type": "visibility_modifier",
398
+ "named": true
399
+ }
400
+ ]
204
401
  }
205
402
  },
206
403
  {
@@ -211,6 +408,10 @@
211
408
  "multiple": true,
212
409
  "required": false,
213
410
  "types": [
411
+ {
412
+ "type": "anonymous_function",
413
+ "named": true
414
+ },
214
415
  {
215
416
  "type": "binary_expression",
216
417
  "named": true
@@ -219,10 +420,18 @@
219
420
  "type": "expression_group",
220
421
  "named": true
221
422
  },
423
+ {
424
+ "type": "field_access",
425
+ "named": true
426
+ },
222
427
  {
223
428
  "type": "float",
224
429
  "named": true
225
430
  },
431
+ {
432
+ "type": "function_call",
433
+ "named": true
434
+ },
226
435
  {
227
436
  "type": "identifier",
228
437
  "named": true
@@ -242,6 +451,10 @@
242
451
  {
243
452
  "type": "string",
244
453
  "named": true
454
+ },
455
+ {
456
+ "type": "when",
457
+ "named": true
245
458
  }
246
459
  ]
247
460
  }
@@ -280,6 +493,52 @@
280
493
  }
281
494
  }
282
495
  },
496
+ {
497
+ "type": "field_access",
498
+ "named": true,
499
+ "fields": {
500
+ "field": {
501
+ "multiple": false,
502
+ "required": true,
503
+ "types": [
504
+ {
505
+ "type": "label",
506
+ "named": true
507
+ }
508
+ ]
509
+ },
510
+ "record": {
511
+ "multiple": false,
512
+ "required": true,
513
+ "types": [
514
+ {
515
+ "type": "expression_group",
516
+ "named": true
517
+ },
518
+ {
519
+ "type": "field_access",
520
+ "named": true
521
+ },
522
+ {
523
+ "type": "function_call",
524
+ "named": true
525
+ },
526
+ {
527
+ "type": "identifier",
528
+ "named": true
529
+ },
530
+ {
531
+ "type": "record",
532
+ "named": true
533
+ },
534
+ {
535
+ "type": "when",
536
+ "named": true
537
+ }
538
+ ]
539
+ }
540
+ }
541
+ },
283
542
  {
284
543
  "type": "function",
285
544
  "named": true,
@@ -288,6 +547,10 @@
288
547
  "multiple": true,
289
548
  "required": true,
290
549
  "types": [
550
+ {
551
+ "type": "anonymous_function",
552
+ "named": true
553
+ },
291
554
  {
292
555
  "type": "binary_expression",
293
556
  "named": true
@@ -296,10 +559,18 @@
296
559
  "type": "expression_group",
297
560
  "named": true
298
561
  },
562
+ {
563
+ "type": "field_access",
564
+ "named": true
565
+ },
299
566
  {
300
567
  "type": "float",
301
568
  "named": true
302
569
  },
570
+ {
571
+ "type": "function_call",
572
+ "named": true
573
+ },
303
574
  {
304
575
  "type": "identifier",
305
576
  "named": true
@@ -320,6 +591,10 @@
320
591
  "type": "string",
321
592
  "named": true
322
593
  },
594
+ {
595
+ "type": "when",
596
+ "named": true
597
+ },
323
598
  {
324
599
  "type": "{",
325
600
  "named": false
@@ -364,7 +639,7 @@
364
639
  },
365
640
  "return": {
366
641
  "multiple": false,
367
- "required": true,
642
+ "required": false,
368
643
  "types": [
369
644
  {
370
645
  "type": "return_type",
@@ -372,10 +647,20 @@
372
647
  }
373
648
  ]
374
649
  }
650
+ },
651
+ "children": {
652
+ "multiple": false,
653
+ "required": false,
654
+ "types": [
655
+ {
656
+ "type": "visibility_modifier",
657
+ "named": true
658
+ }
659
+ ]
375
660
  }
376
661
  },
377
662
  {
378
- "type": "function_parameter_types",
663
+ "type": "function_body",
379
664
  "named": true,
380
665
  "fields": {},
381
666
  "children": {
@@ -383,25 +668,183 @@
383
668
  "required": false,
384
669
  "types": [
385
670
  {
386
- "type": "function_type",
671
+ "type": "anonymous_function",
387
672
  "named": true
388
673
  },
389
674
  {
390
- "type": "generic",
675
+ "type": "binary_expression",
391
676
  "named": true
392
677
  },
393
678
  {
394
- "type": "type",
679
+ "type": "expression_group",
395
680
  "named": true
681
+ },
682
+ {
683
+ "type": "field_access",
684
+ "named": true
685
+ },
686
+ {
687
+ "type": "float",
688
+ "named": true
689
+ },
690
+ {
691
+ "type": "function_call",
692
+ "named": true
693
+ },
694
+ {
695
+ "type": "identifier",
696
+ "named": true
697
+ },
698
+ {
699
+ "type": "integer",
700
+ "named": true
701
+ },
702
+ {
703
+ "type": "let",
704
+ "named": true
705
+ },
706
+ {
707
+ "type": "negation",
708
+ "named": true
709
+ },
710
+ {
711
+ "type": "string",
712
+ "named": true
713
+ },
714
+ {
715
+ "type": "when",
716
+ "named": true
396
- }
717
+ }
397
- ]
718
+ ]
398
- }
719
+ }
399
- },
720
+ },
400
- {
721
+ {
722
+ "type": "function_call",
723
+ "named": true,
724
+ "fields": {
725
+ "arguments": {
726
+ "multiple": false,
727
+ "required": true,
728
+ "types": [
729
+ {
730
+ "type": "arguments",
731
+ "named": true
732
+ }
733
+ ]
734
+ },
735
+ "function": {
736
+ "multiple": false,
737
+ "required": true,
738
+ "types": [
739
+ {
740
+ "type": "anonymous_function",
741
+ "named": true
742
+ },
743
+ {
744
+ "type": "expression_group",
745
+ "named": true
746
+ },
747
+ {
748
+ "type": "field_access",
749
+ "named": true
750
+ },
751
+ {
752
+ "type": "function_call",
753
+ "named": true
754
+ },
755
+ {
756
+ "type": "identifier",
757
+ "named": true
758
+ },
759
+ {
760
+ "type": "when",
761
+ "named": true
762
+ }
763
+ ]
764
+ }
765
+ }
766
+ },
767
+ {
768
+ "type": "function_parameter",
769
+ "named": true,
770
+ "fields": {
771
+ "name": {
772
+ "multiple": false,
773
+ "required": true,
774
+ "types": [
775
+ {
776
+ "type": "discard",
777
+ "named": true
778
+ },
779
+ {
780
+ "type": "identifier",
781
+ "named": true
782
+ }
783
+ ]
784
+ },
785
+ "type": {
786
+ "multiple": false,
787
+ "required": false,
788
+ "types": [
789
+ {
401
- "type": "function_type",
790
+ "type": "function_type",
791
+ "named": true
792
+ },
793
+ {
794
+ "type": "generic",
795
+ "named": true
796
+ },
797
+ {
798
+ "type": "type",
799
+ "named": true
800
+ }
801
+ ]
802
+ }
803
+ }
804
+ },
805
+ {
806
+ "type": "function_parameter_types",
402
- "named": true,
807
+ "named": true,
808
+ "fields": {},
809
+ "children": {
810
+ "multiple": true,
811
+ "required": false,
812
+ "types": [
813
+ {
814
+ "type": "function_type",
815
+ "named": true
816
+ },
817
+ {
818
+ "type": "generic",
819
+ "named": true
820
+ },
821
+ {
822
+ "type": "type",
823
+ "named": true
824
+ }
825
+ ]
826
+ }
827
+ },
828
+ {
829
+ "type": "function_parameters",
830
+ "named": true,
831
+ "fields": {},
832
+ "children": {
833
+ "multiple": true,
834
+ "required": false,
835
+ "types": [
836
+ {
837
+ "type": "function_parameter",
838
+ "named": true
839
+ }
840
+ ]
841
+ }
842
+ },
843
+ {
844
+ "type": "function_type",
845
+ "named": true,
403
- "fields": {
846
+ "fields": {
404
- "parameter_types": {
847
+ "parameter_types": {
405
848
  "multiple": false,
406
849
  "required": false,
407
850
  "types": [
@@ -438,36 +881,306 @@
438
881
  ]
439
882
  }
440
883
  },
884
+ {
885
+ "type": "hole",
886
+ "named": true,
887
+ "fields": {}
888
+ },
441
889
  {
442
890
  "type": "import",
443
891
  "named": true,
444
892
  "fields": {
445
893
  "alias": {
446
894
  "multiple": false,
447
- "required": false,
895
+ "required": false,
896
+ "types": [
897
+ {
898
+ "type": "identifier",
899
+ "named": true
900
+ }
901
+ ]
902
+ },
903
+ "imports": {
904
+ "multiple": false,
905
+ "required": false,
906
+ "types": [
907
+ {
908
+ "type": "unqualified_imports",
909
+ "named": true
910
+ }
911
+ ]
912
+ },
913
+ "module": {
914
+ "multiple": false,
915
+ "required": true,
916
+ "types": [
917
+ {
918
+ "type": "module_name",
919
+ "named": true
920
+ }
921
+ ]
922
+ }
923
+ }
924
+ },
925
+ {
926
+ "type": "integer",
927
+ "named": true,
928
+ "fields": {}
929
+ },
930
+ {
931
+ "type": "label",
932
+ "named": true,
933
+ "fields": {}
934
+ },
935
+ {
936
+ "type": "let",
937
+ "named": true,
938
+ "fields": {
939
+ "assign": {
940
+ "multiple": true,
941
+ "required": false,
942
+ "types": [
943
+ {
944
+ "type": "as",
945
+ "named": false
946
+ },
947
+ {
948
+ "type": "identifier",
949
+ "named": true
950
+ }
951
+ ]
952
+ },
953
+ "pattern": {
954
+ "multiple": true,
955
+ "required": true,
956
+ "types": [
957
+ {
958
+ "type": "as",
959
+ "named": false
960
+ },
961
+ {
962
+ "type": "binary_expression",
963
+ "named": true
964
+ },
965
+ {
966
+ "type": "discard",
967
+ "named": true
968
+ },
969
+ {
970
+ "type": "float",
971
+ "named": true
972
+ },
973
+ {
974
+ "type": "identifier",
975
+ "named": true
976
+ },
977
+ {
978
+ "type": "integer",
979
+ "named": true
980
+ },
981
+ {
982
+ "type": "record_pattern",
983
+ "named": true
984
+ },
985
+ {
986
+ "type": "string",
987
+ "named": true
988
+ }
989
+ ]
990
+ },
991
+ "type": {
992
+ "multiple": false,
993
+ "required": false,
994
+ "types": [
995
+ {
996
+ "type": "function_type",
997
+ "named": true
998
+ },
999
+ {
1000
+ "type": "generic",
1001
+ "named": true
1002
+ },
1003
+ {
1004
+ "type": "type",
1005
+ "named": true
1006
+ }
1007
+ ]
1008
+ },
1009
+ "value": {
1010
+ "multiple": false,
1011
+ "required": true,
1012
+ "types": [
1013
+ {
1014
+ "type": "anonymous_function",
1015
+ "named": true
1016
+ },
1017
+ {
1018
+ "type": "binary_expression",
1019
+ "named": true
1020
+ },
1021
+ {
1022
+ "type": "expression_group",
1023
+ "named": true
1024
+ },
1025
+ {
1026
+ "type": "field_access",
1027
+ "named": true
1028
+ },
1029
+ {
1030
+ "type": "float",
1031
+ "named": true
1032
+ },
1033
+ {
1034
+ "type": "function_call",
1035
+ "named": true
1036
+ },
1037
+ {
1038
+ "type": "identifier",
1039
+ "named": true
1040
+ },
1041
+ {
1042
+ "type": "integer",
1043
+ "named": true
1044
+ },
1045
+ {
1046
+ "type": "negation",
1047
+ "named": true
1048
+ },
1049
+ {
1050
+ "type": "string",
1051
+ "named": true
1052
+ },
1053
+ {
1054
+ "type": "when",
1055
+ "named": true
1056
+ }
1057
+ ]
1058
+ }
1059
+ }
1060
+ },
1061
+ {
1062
+ "type": "module",
1063
+ "named": true,
1064
+ "fields": {
1065
+ "module": {
1066
+ "multiple": false,
1067
+ "required": true,
1068
+ "types": [
1069
+ {
1070
+ "type": "module_name",
1071
+ "named": true
1072
+ }
1073
+ ]
1074
+ }
1075
+ }
1076
+ },
1077
+ {
1078
+ "type": "module_name",
1079
+ "named": true,
1080
+ "fields": {}
1081
+ },
1082
+ {
1083
+ "type": "negation",
1084
+ "named": true,
1085
+ "fields": {},
1086
+ "children": {
1087
+ "multiple": false,
1088
+ "required": true,
1089
+ "types": [
1090
+ {
1091
+ "type": "anonymous_function",
1092
+ "named": true
1093
+ },
1094
+ {
1095
+ "type": "expression_group",
1096
+ "named": true
1097
+ },
1098
+ {
1099
+ "type": "field_access",
1100
+ "named": true
1101
+ },
1102
+ {
1103
+ "type": "float",
1104
+ "named": true
1105
+ },
1106
+ {
1107
+ "type": "function_call",
1108
+ "named": true
1109
+ },
1110
+ {
1111
+ "type": "identifier",
1112
+ "named": true
1113
+ },
1114
+ {
1115
+ "type": "integer",
1116
+ "named": true
1117
+ },
1118
+ {
1119
+ "type": "negation",
1120
+ "named": true
1121
+ },
1122
+ {
1123
+ "type": "string",
1124
+ "named": true
1125
+ },
1126
+ {
1127
+ "type": "when",
1128
+ "named": true
1129
+ }
1130
+ ]
1131
+ }
1132
+ },
1133
+ {
1134
+ "type": "pattern_spread",
1135
+ "named": true,
1136
+ "fields": {}
1137
+ },
1138
+ {
1139
+ "type": "record",
1140
+ "named": true,
1141
+ "fields": {
1142
+ "arguments": {
1143
+ "multiple": false,
1144
+ "required": false,
1145
+ "types": [
1146
+ {
1147
+ "type": "arguments",
1148
+ "named": true
1149
+ }
1150
+ ]
1151
+ },
1152
+ "name": {
1153
+ "multiple": false,
1154
+ "required": true,
448
1155
  "types": [
449
1156
  {
450
- "type": "identifier",
1157
+ "type": "constructor_name",
451
1158
  "named": true
452
1159
  }
453
1160
  ]
1161
+ }
1162
+ }
454
- },
1163
+ },
1164
+ {
1165
+ "type": "record_pattern",
1166
+ "named": true,
455
- "imports": {
1167
+ "fields": {
1168
+ "arguments": {
456
1169
  "multiple": false,
457
1170
  "required": false,
458
1171
  "types": [
459
1172
  {
460
- "type": "unqualified_imports",
1173
+ "type": "record_pattern_arguments",
461
1174
  "named": true
462
1175
  }
463
1176
  ]
464
1177
  },
465
- "module": {
1178
+ "name": {
466
1179
  "multiple": false,
467
1180
  "required": true,
468
1181
  "types": [
469
1182
  {
470
- "type": "module_name",
1183
+ "type": "constructor_name",
471
1184
  "named": true
472
1185
  }
473
1186
  ]
@@ -475,12 +1188,7 @@
475
1188
  }
476
1189
  },
477
1190
  {
478
- "type": "integer",
1191
+ "type": "record_pattern_argument",
479
- "named": true,
480
- "fields": {}
481
- },
482
- {
483
- "type": "let",
484
1192
  "named": true,
485
1193
  "fields": {
486
1194
  "assign": {
@@ -497,6 +1205,16 @@
497
1205
  }
498
1206
  ]
499
1207
  },
1208
+ "label": {
1209
+ "multiple": false,
1210
+ "required": false,
1211
+ "types": [
1212
+ {
1213
+ "type": "label",
1214
+ "named": true
1215
+ }
1216
+ ]
1217
+ },
500
1218
  "pattern": {
501
1219
  "multiple": true,
502
1220
  "required": true,
@@ -509,6 +1227,10 @@
509
1227
  "type": "binary_expression",
510
1228
  "named": true
511
1229
  },
1230
+ {
1231
+ "type": "discard",
1232
+ "named": true
1233
+ },
512
1234
  {
513
1235
  "type": "float",
514
1236
  "named": true
@@ -520,23 +1242,48 @@
520
1242
  {
521
1243
  "type": "integer",
522
1244
  "named": true
523
- }
524
- ]
525
- },
1245
+ },
526
- "type": {
527
- "multiple": false,
528
- "required": false,
529
- "types": [
530
1246
  {
531
- "type": "function_type",
1247
+ "type": "record_pattern",
532
1248
  "named": true
533
1249
  },
534
1250
  {
535
- "type": "generic",
1251
+ "type": "string",
536
1252
  "named": true
1253
+ }
1254
+ ]
1255
+ }
1256
+ }
537
- },
1257
+ },
1258
+ {
1259
+ "type": "record_pattern_arguments",
1260
+ "named": true,
1261
+ "fields": {},
1262
+ "children": {
1263
+ "multiple": true,
1264
+ "required": false,
1265
+ "types": [
1266
+ {
1267
+ "type": "pattern_spread",
1268
+ "named": true
1269
+ },
1270
+ {
1271
+ "type": "record_pattern_argument",
1272
+ "named": true
1273
+ }
1274
+ ]
1275
+ }
1276
+ },
1277
+ {
1278
+ "type": "record_update_argument",
1279
+ "named": true,
1280
+ "fields": {
1281
+ "label": {
1282
+ "multiple": false,
1283
+ "required": true,
1284
+ "types": [
538
1285
  {
539
- "type": "type",
1286
+ "type": "label",
540
1287
  "named": true
541
1288
  }
542
1289
  ]
@@ -545,6 +1292,10 @@
545
1292
  "multiple": false,
546
1293
  "required": true,
547
1294
  "types": [
1295
+ {
1296
+ "type": "anonymous_function",
1297
+ "named": true
1298
+ },
548
1299
  {
549
1300
  "type": "binary_expression",
550
1301
  "named": true
@@ -553,10 +1304,18 @@
553
1304
  "type": "expression_group",
554
1305
  "named": true
555
1306
  },
1307
+ {
1308
+ "type": "field_access",
1309
+ "named": true
1310
+ },
556
1311
  {
557
1312
  "type": "float",
558
1313
  "named": true
559
1314
  },
1315
+ {
1316
+ "type": "function_call",
1317
+ "named": true
1318
+ },
560
1319
  {
561
1320
  "type": "identifier",
562
1321
  "named": true
@@ -572,21 +1331,9 @@
572
1331
  {
573
1332
  "type": "string",
574
1333
  "named": true
575
- }
576
- ]
577
- }
578
- }
579
- },
1334
+ },
580
- {
581
- "type": "module",
582
- "named": true,
583
- "fields": {
584
- "module": {
585
- "multiple": false,
586
- "required": true,
587
- "types": [
588
1335
  {
589
- "type": "module_name",
1336
+ "type": "when",
590
1337
  "named": true
591
1338
  }
592
1339
  ]
@@ -594,40 +1341,15 @@
594
1341
  }
595
1342
  },
596
1343
  {
597
- "type": "module_name",
1344
+ "type": "record_update_arguments",
598
- "named": true,
599
- "fields": {}
600
- },
601
- {
602
- "type": "negation",
603
1345
  "named": true,
604
1346
  "fields": {},
605
1347
  "children": {
606
- "multiple": false,
1348
+ "multiple": true,
607
1349
  "required": true,
608
1350
  "types": [
609
1351
  {
610
- "type": "expression_group",
1352
+ "type": "record_update_argument",
611
- "named": true
612
- },
613
- {
614
- "type": "float",
615
- "named": true
616
- },
617
- {
618
- "type": "identifier",
619
- "named": true
620
- },
621
- {
622
- "type": "integer",
623
- "named": true
624
- },
625
- {
626
- "type": "negation",
627
- "named": true
628
- },
629
- {
630
- "type": "string",
631
1353
  "named": true
632
1354
  }
633
1355
  ]
@@ -749,6 +1471,16 @@
749
1471
  }
750
1472
  ]
751
1473
  }
1474
+ },
1475
+ "children": {
1476
+ "multiple": false,
1477
+ "required": false,
1478
+ "types": [
1479
+ {
1480
+ "type": "visibility_modifier",
1481
+ "named": true
1482
+ }
1483
+ ]
752
1484
  }
753
1485
  },
754
1486
  {
@@ -869,6 +1601,120 @@
869
1601
  ]
870
1602
  }
871
1603
  },
1604
+ {
1605
+ "type": "when",
1606
+ "named": true,
1607
+ "fields": {},
1608
+ "children": {
1609
+ "multiple": true,
1610
+ "required": false,
1611
+ "types": [
1612
+ {
1613
+ "type": "anonymous_function",
1614
+ "named": true
1615
+ },
1616
+ {
1617
+ "type": "binary_expression",
1618
+ "named": true
1619
+ },
1620
+ {
1621
+ "type": "expression_group",
1622
+ "named": true
1623
+ },
1624
+ {
1625
+ "type": "field_access",
1626
+ "named": true
1627
+ },
1628
+ {
1629
+ "type": "float",
1630
+ "named": true
1631
+ },
1632
+ {
1633
+ "type": "function_call",
1634
+ "named": true
1635
+ },
1636
+ {
1637
+ "type": "identifier",
1638
+ "named": true
1639
+ },
1640
+ {
1641
+ "type": "integer",
1642
+ "named": true
1643
+ },
1644
+ {
1645
+ "type": "negation",
1646
+ "named": true
1647
+ },
1648
+ {
1649
+ "type": "string",
1650
+ "named": true
1651
+ },
1652
+ {
1653
+ "type": "when",
1654
+ "named": true
1655
+ },
1656
+ {
1657
+ "type": "when_entry",
1658
+ "named": true
1659
+ }
1660
+ ]
1661
+ }
1662
+ },
1663
+ {
1664
+ "type": "when_entry",
1665
+ "named": true,
1666
+ "fields": {},
1667
+ "children": {
1668
+ "multiple": true,
1669
+ "required": true,
1670
+ "types": [
1671
+ {
1672
+ "type": "anonymous_function",
1673
+ "named": true
1674
+ },
1675
+ {
1676
+ "type": "binary_expression",
1677
+ "named": true
1678
+ },
1679
+ {
1680
+ "type": "expression_group",
1681
+ "named": true
1682
+ },
1683
+ {
1684
+ "type": "field_access",
1685
+ "named": true
1686
+ },
1687
+ {
1688
+ "type": "float",
1689
+ "named": true
1690
+ },
1691
+ {
1692
+ "type": "function_call",
1693
+ "named": true
1694
+ },
1695
+ {
1696
+ "type": "identifier",
1697
+ "named": true
1698
+ },
1699
+ {
1700
+ "type": "integer",
1701
+ "named": true
1702
+ },
1703
+ {
1704
+ "type": "negation",
1705
+ "named": true
1706
+ },
1707
+ {
1708
+ "type": "string",
1709
+ "named": true
1710
+ },
1711
+ {
1712
+ "type": "when",
1713
+ "named": true
1714
+ }
1715
+ ]
1716
+ }
1717
+ },
872
1718
  {
873
1719
  "type": "!",
874
1720
  "named": false
@@ -921,6 +1767,10 @@
921
1767
  "type": ".",
922
1768
  "named": false
923
1769
  },
1770
+ {
1771
+ "type": "..",
1772
+ "named": false
1773
+ },
924
1774
  {
925
1775
  "type": "/",
926
1776
  "named": false
@@ -957,6 +1807,18 @@
957
1807
  "type": ">=",
958
1808
  "named": false
959
1809
  },
1810
+ {
1811
+ "type": "[",
1812
+ "named": false
1813
+ },
1814
+ {
1815
+ "type": "]",
1816
+ "named": false
1817
+ },
1818
+ {
1819
+ "type": "_",
1820
+ "named": false
1821
+ },
960
1822
  {
961
1823
  "type": "as",
962
1824
  "named": false
@@ -1001,6 +1863,14 @@
1001
1863
  "type": "type",
1002
1864
  "named": false
1003
1865
  },
1866
+ {
1867
+ "type": "visibility_modifier",
1868
+ "named": true
1869
+ },
1870
+ {
1871
+ "type": "when",
1872
+ "named": false
1873
+ },
1004
1874
  {
1005
1875
  "type": "{",
1006
1876
  "named": false
test/corpus/function.txt CHANGED
@@ -4,12 +4,18 @@ Function - Simple
4
4
 
5
5
  module palm
6
6
 
7
- fn main() {
7
+ pub fn main() {
8
8
  let a = "123"
9
+ let b = 5
10
+ let c = 5.1
11
+ when b {
12
+ 1 -> "Hello"
13
+ _ -> "World"
14
+ }
9
15
  }
10
16
 
11
- fn add(a: Int, b: Int) -> Int {
17
+ pub fn add(a: Int, b: Int) -> Int {
12
- let a = "123"
18
+ a + b
13
19
  }
14
20
 
15
21
  --------------------------------------------------------------------------------
@@ -18,22 +24,41 @@ fn add(a: Int, b: Int) -> Int {
18
24
  (module
19
25
  (module_name))
20
26
  (function
27
+ (visibility_modifier)
21
28
  (identifier)
22
29
  (let
23
30
  (identifier)
24
31
  (string
32
+ (quoted_content)))
33
+ (let
34
+ (identifier)
35
+ (integer))
36
+ (let
37
+ (identifier)
38
+ (float))
39
+ (when
40
+ (identifier)
41
+ (when_entry
42
+ (integer)
43
+ (string
44
+ (quoted_content)))
45
+ (when_entry
46
+ (string
25
- (quoted_content))))
47
+ (quoted_content)))))
26
48
  (function
49
+ (visibility_modifier)
27
50
  (identifier)
28
- (type_field
51
+ (field
29
52
  (identifier)
53
+ (type
30
- (identifier))
54
+ (type_identifier)))
31
- (type_field
55
+ (field
32
56
  (identifier)
57
+ (type
33
- (identifier))
58
+ (type_identifier)))
34
59
  (return_type
60
+ (type
35
- (type_identifier))
61
+ (type_identifier)))
36
- (let
62
+ (binary_expression
37
63
  (identifier)
38
- (string
39
- (quoted_content)))))
64
+ (identifier))))