starlight-cli 1.1.15 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/parser.js CHANGED
@@ -1292,33 +1292,100 @@ postfix() {
1292
1292
  while (true) {
1293
1293
  const t = this.current;
1294
1294
 
1295
- if (t.type === 'LBRACKET') {
1296
- const startLine = t.line;
1297
- const startCol = t.column;
1298
- this.eat('LBRACKET');
1295
+ if (t.type === 'LBRACKET') {
1296
+ const startLine = t.line;
1297
+ const startCol = t.column;
1298
+ this.eat('LBRACKET');
1299
+
1300
+ let start = null;
1301
+ let end = null;
1302
+ let step = null;
1299
1303
 
1300
- const index = this.expression();
1304
+ if (this.current.type === 'COLON') {
1305
+ this.eat('COLON');
1306
+
1307
+ if (this.current.type !== 'RBRACKET' && this.current.type !== 'COLON') {
1308
+ end = this.expression();
1309
+ }
1310
+
1311
+ if (this.current.type === 'COLON') {
1312
+ this.eat('COLON');
1313
+ if (this.current.type !== 'RBRACKET') {
1314
+ step = this.expression();
1315
+ }
1316
+ }
1317
+
1318
+ if (this.current.type !== 'RBRACKET') {
1319
+ throw new ParseError(
1320
+ "Expected ']' after slice",
1321
+ this.current,
1322
+ this.source
1323
+ );
1324
+ }
1325
+
1326
+ this.eat('RBRACKET');
1327
+
1328
+ node = {
1329
+ type: 'SliceExpression',
1330
+ object: node,
1331
+ start,
1332
+ end,
1333
+ step,
1334
+ line: startLine,
1335
+ column: startCol
1336
+ };
1337
+
1338
+ } else {
1339
+ start = this.expression();
1340
+
1341
+ if (this.current.type === 'COLON') {
1342
+ this.eat('COLON');
1343
+
1344
+ if (this.current.type !== 'RBRACKET' && this.current.type !== 'COLON') {
1345
+ end = this.expression();
1346
+ }
1347
+
1348
+ if (this.current.type === 'COLON') {
1349
+ this.eat('COLON');
1350
+ if (this.current.type !== 'RBRACKET') {
1351
+ step = this.expression();
1352
+ }
1353
+ }
1301
1354
 
1302
1355
  if (this.current.type !== 'RBRACKET') {
1303
1356
  throw new ParseError(
1304
- "Expected ']' after index expression",
1357
+ "Expected ']' after slice",
1305
1358
  this.current,
1306
- this.source,
1307
- "Index access must be closed, e.g. arr[0]"
1359
+ this.source
1308
1360
  );
1309
1361
  }
1310
1362
 
1311
1363
  this.eat('RBRACKET');
1312
1364
 
1365
+ node = {
1366
+ type: 'SliceExpression',
1367
+ object: node,
1368
+ start,
1369
+ end,
1370
+ step,
1371
+ line: startLine,
1372
+ column: startCol
1373
+ };
1374
+
1375
+ } else {
1376
+ this.eat('RBRACKET');
1313
1377
  node = {
1314
1378
  type: 'IndexExpression',
1315
1379
  object: node,
1316
- indexer: index,
1380
+ indexer: start,
1317
1381
  line: startLine,
1318
1382
  column: startCol
1319
1383
  };
1320
- continue;
1321
1384
  }
1385
+ }
1386
+ }
1387
+
1388
+
1322
1389
 
1323
1390
  if (t.type === 'LPAREN') {
1324
1391
  const startLine = t.line;
@@ -1450,6 +1517,7 @@ arrowFunction(params) {
1450
1517
  };
1451
1518
  }
1452
1519
 
1520
+
1453
1521
  primary() {
1454
1522
  const t = this.current;
1455
1523
 
@@ -1521,7 +1589,6 @@ primary() {
1521
1589
  return { type: 'NewExpression', callee, arguments: args, line: t.line, column: t.column };
1522
1590
  }
1523
1591
 
1524
- // ---- ask(...) function call ----
1525
1592
  if (t.type === 'ASK') {
1526
1593
  this.eat('ASK');
1527
1594
 
@@ -1562,6 +1629,69 @@ primary() {
1562
1629
  column: t.column
1563
1630
  };
1564
1631
  }
1632
+ if (t.type === 'FUNC') {
1633
+ const funcToken = t;
1634
+ this.eat('FUNC');
1635
+
1636
+ let params = [];
1637
+ if (this.current.type === 'LPAREN') {
1638
+ this.eat('LPAREN');
1639
+
1640
+ if (this.current.type !== 'RPAREN') {
1641
+ if (this.current.type !== 'IDENTIFIER') {
1642
+ throw new ParseError(
1643
+ "Expected parameter name",
1644
+ this.current,
1645
+ this.source
1646
+ );
1647
+ }
1648
+
1649
+ params.push(this.current.value);
1650
+ this.eat('IDENTIFIER');
1651
+
1652
+ while (this.current.type === 'COMMA') {
1653
+ this.eat('COMMA');
1654
+ if (this.current.type !== 'IDENTIFIER') {
1655
+ throw new ParseError(
1656
+ "Expected parameter name",
1657
+ this.current,
1658
+ this.source
1659
+ );
1660
+ }
1661
+ params.push(this.current.value);
1662
+ this.eat('IDENTIFIER');
1663
+ }
1664
+ }
1665
+
1666
+ if (this.current.type !== 'RPAREN') {
1667
+ throw new ParseError(
1668
+ "Expected ')' after function parameters",
1669
+ this.current,
1670
+ this.source
1671
+ );
1672
+ }
1673
+
1674
+ this.eat('RPAREN');
1675
+ }
1676
+
1677
+ if (this.current.type !== 'LBRACE') {
1678
+ throw new ParseError(
1679
+ "Expected '{' to start function body",
1680
+ this.current,
1681
+ this.source
1682
+ );
1683
+ }
1684
+
1685
+ const body = this.block();
1686
+
1687
+ return {
1688
+ type: 'FunctionExpression',
1689
+ params,
1690
+ body,
1691
+ line: funcToken.line,
1692
+ column: funcToken.column
1693
+ };
1694
+ }
1565
1695
 
1566
1696
  if (t.type === 'IDENTIFIER') {
1567
1697
  const name = t.value;
@@ -1698,7 +1828,7 @@ primary() {
1698
1828
  t,
1699
1829
  this.source
1700
1830
  );
1701
- }
1831
+ }
1702
1832
 
1703
1833
  }
1704
1834
 
package/src/starlight.js CHANGED
@@ -12,7 +12,7 @@ const Lexer = require('./lexer');
12
12
  const Parser = require('./parser');
13
13
  const Evaluator = require('./evaluator');
14
14
 
15
- const VERSION = '1.1.15';
15
+ const VERSION = '1.1.17';
16
16
 
17
17
  const COLOR = {
18
18
  reset: '\x1b[0m',