starlight-cli 1.0.29 → 1.0.31

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/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Starlight Language
2
+
3
+ Starlight is a lightweight, developer-oriented programming language designed for server-side scripting, automation, and general-purpose programming. It combines simplicity with powerful features like async/await, custom modules, and a clear, concise syntax.
4
+
5
+ **Official Reference:** [https://starlight-learn-lang.pages.dev/](https://starlight-learn-lang.pages.dev/)
6
+
7
+ ## Features
8
+
9
+ - Modern Syntax: Inspired by JavaScript and Python, optimized for server-side tasks.
10
+ - Async/Await Support: Handle asynchronous operations cleanly.
11
+ - Modules & Imports: Use `import` to bring in libraries or other `.sl` files.
12
+ - Server-side Ready: Ideal for scripting, automation, and backend logic.
13
+ - Interactive Input: Built-in `ask` and `sldeploy` commands for user interaction.
14
+ - Built-in Utilities: `sleep(ms)`, `len()`, `keys()`, `values()`, `fetch()`, `get()`, `post()`.
15
+
16
+ ## Getting Started
17
+
18
+ 1. Install Node.js (v18+ recommended)
19
+ 2. Install via NPM:
20
+
21
+ \`\`\`
22
+ npm install starlight-cli
23
+ \`\`\`
24
+
25
+ ## Example Program (`hello.sl`)
26
+
27
+ \`\`\`
28
+ let name = ask("What is your name?")
29
+ sldeploy("Hello, " + name + "!")
30
+ \`\`\`
31
+
32
+ Run:
33
+
34
+ \`\`\`
35
+ starlight hello.sl
36
+ \`\`\`
37
+
38
+ Output:
39
+
40
+ \`\`\`
41
+ What is your name? Alice
42
+ Hello, Alice!
43
+ \`\`\`
44
+
45
+ ## Server-side Example
46
+
47
+ \`\`\`
48
+ define server = async () => {
49
+ let response = await get("https://jsonplaceholder.typicode.com/todos/1")
50
+ sldeploy(response)
51
+ }
52
+
53
+ server()
54
+ \`\`\`
55
+
56
+ ## Core Concepts
57
+
58
+ - Variables: `let x = 10`
59
+ - Functions: `func add(a, b) { return a + b }`
60
+ - Async Functions: `async func fetchData() { ... }`
61
+ - Conditionals: `if (x > 5) { ... } else { ... }`
62
+ - Loops: `while`, `for`
63
+ - Modules: `import { something } from "./module.sl"`
64
+
65
+ ## Why Starlight?
66
+
67
+ Starlight is developer-focused, designed for server-side scripting and automation. Its clean syntax and minimal overhead make it easy to write powerful scripts.
68
+
69
+ For full tutorials, API references, and examples, visit: [https://starlight-learn-lang.pages.dev/](https://starlight-learn-lang.pages.dev/)
70
+
71
+ License: MIT
package/dist/index.js CHANGED
@@ -1496,6 +1496,15 @@ async evaluate(node, env = this.global) {
1496
1496
  const val = await this.evaluate(node.argument, env);
1497
1497
  return val;
1498
1498
  }
1499
+ case 'NewExpression': {
1500
+ const fn = await this.evaluate(node.callee, env); // the class or constructor
1501
+ if (typeof fn !== 'function') {
1502
+ throw new Error('NewExpression callee is not a function');
1503
+ }
1504
+ const args = [];
1505
+ for (const a of node.arguments) args.push(await this.evaluate(a, env));
1506
+ return new fn(...args);
1507
+ }
1499
1508
  default:
1500
1509
  throw new Error(`Unknown node type in evaluator: ${node.type}`);
1501
1510
  }
@@ -1919,7 +1928,7 @@ class Lexer {
1919
1928
  'break', 'continue', 'func', 'return',
1920
1929
  'true', 'false', 'null',
1921
1930
  'ask', 'define', 'import', 'from', 'as',
1922
- 'async', 'await'
1931
+ 'async', 'await', 'new'
1923
1932
  ];
1924
1933
 
1925
1934
 
@@ -2444,6 +2453,22 @@ if (t.type === 'AWAIT') {
2444
2453
  const argument = this.expression();
2445
2454
  return { type: 'AwaitExpression', argument };
2446
2455
  }
2456
+ if (t.type === 'NEW') {
2457
+ this.eat('NEW');
2458
+ const callee = this.primary(); // the class or function being called
2459
+ this.eat('LPAREN');
2460
+ const args = [];
2461
+ if (this.current.type !== 'RPAREN') {
2462
+ args.push(this.expression());
2463
+ while (this.current.type === 'COMMA') {
2464
+ this.eat('COMMA');
2465
+ args.push(this.expression());
2466
+ }
2467
+ }
2468
+ this.eat('RPAREN');
2469
+ return { type: 'NewExpression', callee, arguments: args };
2470
+ }
2471
+
2447
2472
  if (t.type === 'ASK') {
2448
2473
  this.eat('ASK');
2449
2474
  this.eat('LPAREN');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -153,6 +153,15 @@ async evaluate(node, env = this.global) {
153
153
  const val = await this.evaluate(node.argument, env);
154
154
  return val;
155
155
  }
156
+ case 'NewExpression': {
157
+ const fn = await this.evaluate(node.callee, env); // the class or constructor
158
+ if (typeof fn !== 'function') {
159
+ throw new Error('NewExpression callee is not a function');
160
+ }
161
+ const args = [];
162
+ for (const a of node.arguments) args.push(await this.evaluate(a, env));
163
+ return new fn(...args);
164
+ }
156
165
  default:
157
166
  throw new Error(`Unknown node type in evaluator: ${node.type}`);
158
167
  }
package/src/lexer.js CHANGED
@@ -83,7 +83,7 @@ class Lexer {
83
83
  'break', 'continue', 'func', 'return',
84
84
  'true', 'false', 'null',
85
85
  'ask', 'define', 'import', 'from', 'as',
86
- 'async', 'await'
86
+ 'async', 'await', 'new'
87
87
  ];
88
88
 
89
89
 
package/src/parser.js CHANGED
@@ -414,6 +414,22 @@ if (t.type === 'AWAIT') {
414
414
  const argument = this.expression();
415
415
  return { type: 'AwaitExpression', argument };
416
416
  }
417
+ if (t.type === 'NEW') {
418
+ this.eat('NEW');
419
+ const callee = this.primary(); // the class or function being called
420
+ this.eat('LPAREN');
421
+ const args = [];
422
+ if (this.current.type !== 'RPAREN') {
423
+ args.push(this.expression());
424
+ while (this.current.type === 'COMMA') {
425
+ this.eat('COMMA');
426
+ args.push(this.expression());
427
+ }
428
+ }
429
+ this.eat('RPAREN');
430
+ return { type: 'NewExpression', callee, arguments: args };
431
+ }
432
+
417
433
  if (t.type === 'ASK') {
418
434
  this.eat('ASK');
419
435
  this.eat('LPAREN');