Make = and => optional in function declarations (#4577)

* Make `=` and `=>` optional in function declarations

And requires `:` for return types

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Tests

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Format types in function decls

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Require  in anon function decls

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2024-11-27 15:46:58 +13:00
committed by GitHub
parent d461b09a4d
commit 3139e18dc7
70 changed files with 6696 additions and 6600 deletions

View File

@ -1,8 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 92
description: Program memory after executing fillet-and-shell.kcl
snapshot_kind: text
---
{
"environments": [
@ -913,11 +911,11 @@ snapshot_kind: text
{
"declarations": [
{
"end": 1431,
"end": 1425,
"id": {
"end": 1236,
"end": 1230,
"name": "screw",
"start": 1231,
"start": 1225,
"type": "Identifier"
},
"init": {
@ -925,23 +923,23 @@ snapshot_kind: text
{
"arguments": [
{
"end": 1257,
"end": 1251,
"raw": "\"XY\"",
"start": 1253,
"start": 1247,
"type": "Literal",
"type": "Literal",
"value": "XY"
}
],
"callee": {
"end": 1252,
"end": 1246,
"name": "startSketchOn",
"start": 1239,
"start": 1233,
"type": "Identifier"
},
"end": 1258,
"end": 1252,
"optional": false,
"start": 1239,
"start": 1233,
"type": "CallExpression",
"type": "CallExpression"
},
@ -950,124 +948,124 @@ snapshot_kind: text
{
"elements": [
{
"end": 1283,
"end": 1277,
"raw": "0",
"start": 1282,
"start": 1276,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
{
"end": 1286,
"end": 1280,
"raw": "0",
"start": 1285,
"start": 1279,
"type": "Literal",
"type": "Literal",
"value": 0.0
}
],
"end": 1287,
"start": 1281,
"end": 1281,
"start": 1275,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
{
"end": 1290,
"start": 1289,
"end": 1284,
"start": 1283,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 1280,
"end": 1274,
"name": "startProfileAt",
"start": 1266,
"start": 1260,
"type": "Identifier"
},
"end": 1291,
"end": 1285,
"optional": false,
"start": 1266,
"start": 1260,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 1339,
"end": 1333,
"properties": [
{
"end": 1323,
"end": 1317,
"key": {
"end": 1314,
"end": 1308,
"name": "center",
"start": 1308,
"start": 1302,
"type": "Identifier"
},
"start": 1308,
"start": 1302,
"type": "ObjectProperty",
"value": {
"elements": [
{
"end": 1319,
"end": 1313,
"name": "x",
"start": 1318,
"start": 1312,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 1322,
"end": 1316,
"name": "y",
"start": 1321,
"start": 1315,
"type": "Identifier",
"type": "Identifier"
}
],
"end": 1323,
"start": 1317,
"end": 1317,
"start": 1311,
"type": "ArrayExpression",
"type": "ArrayExpression"
}
},
{
"end": 1337,
"end": 1331,
"key": {
"end": 1331,
"end": 1325,
"name": "radius",
"start": 1325,
"start": 1319,
"type": "Identifier"
},
"start": 1325,
"start": 1319,
"type": "ObjectProperty",
"value": {
"end": 1337,
"end": 1331,
"raw": "2.5",
"start": 1334,
"start": 1328,
"type": "Literal",
"type": "Literal",
"value": 2.5
}
}
],
"start": 1306,
"start": 1300,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
{
"end": 1342,
"start": 1341,
"end": 1336,
"start": 1335,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 1305,
"end": 1299,
"name": "circle",
"start": 1299,
"start": 1293,
"type": "Identifier"
},
"end": 1343,
"end": 1337,
"optional": false,
"start": 1299,
"start": 1293,
"type": "CallExpression",
"type": "CallExpression"
},
@ -1076,171 +1074,181 @@ snapshot_kind: text
{
"arguments": [
{
"end": 1397,
"end": 1391,
"properties": [
{
"end": 1380,
"end": 1374,
"key": {
"end": 1371,
"end": 1365,
"name": "center",
"start": 1365,
"start": 1359,
"type": "Identifier"
},
"start": 1365,
"start": 1359,
"type": "ObjectProperty",
"value": {
"elements": [
{
"end": 1376,
"end": 1370,
"name": "x",
"start": 1375,
"start": 1369,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 1379,
"end": 1373,
"name": "y",
"start": 1378,
"start": 1372,
"type": "Identifier",
"type": "Identifier"
}
],
"end": 1380,
"start": 1374,
"end": 1374,
"start": 1368,
"type": "ArrayExpression",
"type": "ArrayExpression"
}
},
{
"end": 1395,
"end": 1389,
"key": {
"end": 1388,
"end": 1382,
"name": "radius",
"start": 1382,
"start": 1376,
"type": "Identifier"
},
"start": 1382,
"start": 1376,
"type": "ObjectProperty",
"value": {
"end": 1395,
"end": 1389,
"raw": "1.25",
"start": 1391,
"start": 1385,
"type": "Literal",
"type": "Literal",
"value": 1.25
}
}
],
"start": 1363,
"start": 1357,
"type": "ObjectExpression",
"type": "ObjectExpression"
},
{
"end": 1400,
"start": 1399,
"end": 1394,
"start": 1393,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 1362,
"end": 1356,
"name": "circle",
"start": 1356,
"start": 1350,
"type": "Identifier"
},
"end": 1401,
"end": 1395,
"optional": false,
"start": 1356,
"start": 1350,
"type": "CallExpression",
"type": "CallExpression"
},
{
"end": 1404,
"start": 1403,
"end": 1398,
"start": 1397,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 1355,
"end": 1349,
"name": "hole",
"start": 1351,
"start": 1345,
"type": "Identifier"
},
"end": 1405,
"end": 1399,
"optional": false,
"start": 1351,
"start": 1345,
"type": "CallExpression",
"type": "CallExpression"
},
{
"arguments": [
{
"end": 1427,
"end": 1421,
"name": "height",
"start": 1421,
"start": 1415,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 1430,
"start": 1429,
"end": 1424,
"start": 1423,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
],
"callee": {
"end": 1420,
"end": 1414,
"name": "extrude",
"start": 1413,
"start": 1407,
"type": "Identifier"
},
"end": 1431,
"end": 1425,
"optional": false,
"start": 1413,
"start": 1407,
"type": "CallExpression",
"type": "CallExpression"
}
],
"end": 1431,
"start": 1239,
"end": 1425,
"start": 1233,
"type": "PipeExpression",
"type": "PipeExpression"
},
"start": 1231,
"start": 1225,
"type": "VariableDeclarator"
}
],
"end": 1431,
"end": 1425,
"kind": "const",
"start": 1231,
"start": 1225,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"argument": {
"end": 1446,
"end": 1440,
"name": "screw",
"start": 1441,
"start": 1435,
"type": "Identifier",
"type": "Identifier"
},
"end": 1446,
"start": 1434,
"end": 1440,
"start": 1428,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"end": 1448,
"start": 1227
"end": 1442,
"start": 1221
},
"end": 1448,
"end": 1442,
"params": [
{
"type": "Parameter",
"identifier": {
"end": 1211,
"end": 1208,
"name": "x",
"start": 1207,
"type": "Identifier"
},
"optional": false
},
{
"type": "Parameter",
"identifier": {
"end": 1211,
"name": "y",
"start": 1210,
"type": "Identifier"
},
@ -1249,25 +1257,15 @@ snapshot_kind: text
{
"type": "Parameter",
"identifier": {
"end": 1214,
"name": "y",
"start": 1213,
"type": "Identifier"
},
"optional": false
},
{
"type": "Parameter",
"identifier": {
"end": 1222,
"end": 1219,
"name": "height",
"start": 1216,
"start": 1213,
"type": "Identifier"
},
"optional": false
}
],
"start": 1209,
"start": 1206,
"type": "FunctionExpression"
},
"memory": {
@ -2441,8 +2439,8 @@ snapshot_kind: text
"__meta": [
{
"sourceRange": [
1209,
1448,
1206,
1442,
0
]
}