starlight-cli 1.1.11 → 1.1.13
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 +62 -357
- package/dist/index.js +1553 -529
- package/package.json +1 -1
- package/src/evaluator.js +649 -363
- package/src/parser.js +904 -166
- package/src/starlight.js +1 -1
package/README.md
CHANGED
|
@@ -4,417 +4,122 @@
|
|
|
4
4
|
Starlight is a lightweight, developer-oriented programming language designed for **server-side scripting, automation, and general-purpose programming**. It combines a clean, readable syntax inspired by JavaScript and Python with powerful runtime features such as async/await, modules, and interactive I/O.
|
|
5
5
|
|
|
6
6
|
**Official Reference:**
|
|
7
|
-
https://
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Key Features
|
|
12
|
-
|
|
13
|
-
- **Modern, Simple Syntax** – Familiar to JavaScript and Python developers
|
|
14
|
-
- **Async / Await** – Native support for asynchronous operations
|
|
15
|
-
- **Modules & Imports** – Import JavaScript packages or other `.sl` files
|
|
16
|
-
- **Server-side Ready** – Built on Node.js, ideal for backend logic
|
|
17
|
-
- **Interactive I/O** – Built-in `ask` and `sldeploy`
|
|
18
|
-
- **Built-in Utilities** – `sleep`, `len`, `keys`, `values`, `fetch`, `get`, `post`
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
1. Install **Node.js** (v18+ recommended)
|
|
25
|
-
2. Install the Starlight CLI:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install -g starlight-cli
|
|
29
|
-
````
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Your First Program (`hello.sl`)
|
|
34
|
-
|
|
35
|
-
```sl
|
|
36
|
-
let name = ask("What is your name?")
|
|
37
|
-
sldeploy "Hello, " + name + "!"
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Run:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
starlight hello.sl
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Output
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
What is your name? Alice
|
|
50
|
-
Hello, Alice!
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Core Language Concepts
|
|
56
|
-
|
|
57
|
-
### Variables
|
|
58
|
-
|
|
59
|
-
```sl
|
|
60
|
-
let x = 10
|
|
61
|
-
let text = "hello"
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
### Functions
|
|
67
|
-
|
|
68
|
-
```sl
|
|
69
|
-
func add(a, b) {
|
|
70
|
-
return a + b
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
sldeploy add(2, 3)
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
### Async Functions
|
|
79
|
-
|
|
80
|
-
```sl
|
|
81
|
-
async func load() {
|
|
82
|
-
let data = await get("https://example.com/api")
|
|
83
|
-
sldeploy data
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
load()
|
|
87
|
-
```
|
|
88
|
-
|
|
7
|
+
https://starlight-programming-language.pages.dev/tutorials
|
|
89
8
|
---
|
|
9
|
+
## Error Handling in Starlight
|
|
90
10
|
|
|
91
|
-
|
|
11
|
+
Starlight is designed with **modern, developer-friendly error handling** that clearly explains what went wrong, where it happened, and how to fix it.
|
|
92
12
|
|
|
93
|
-
|
|
13
|
+
### Modern Diagnostic Style
|
|
94
14
|
|
|
95
|
-
|
|
15
|
+
Starlight errors follow the same diagnostic standards used by modern languages such as JavaScript, Rust, and Python:
|
|
96
16
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
17
|
+
- Clear error message
|
|
18
|
+
- Exact **line and column number**
|
|
19
|
+
- Source code preview
|
|
20
|
+
- Visual caret (`^`) pointing to the error location
|
|
21
|
+
- Helpful suggestions when possible
|
|
101
22
|
|
|
102
|
-
|
|
23
|
+
Example:
|
|
103
24
|
|
|
104
|
-
```sl
|
|
105
|
-
let add = (a, b) => a + b
|
|
106
|
-
sldeploy add(10, 20)
|
|
107
25
|
```
|
|
108
26
|
|
|
109
|
-
|
|
27
|
+
Unterminated block
|
|
28
|
+
Did you forget to close the block with '}'?
|
|
29
|
+
at line 5, column 0
|
|
110
30
|
|
|
111
|
-
```sl
|
|
112
|
-
let label = p => {
|
|
113
|
-
if (p.price > 1000) {
|
|
114
|
-
return "Premium"
|
|
115
|
-
} else {
|
|
116
|
-
return "Standard"
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
31
|
```
|
|
120
|
-
|
|
121
|
-
### Arrow Functions with Objects
|
|
122
|
-
|
|
123
|
-
```sl
|
|
124
|
-
let summarize = p => {
|
|
125
|
-
return {
|
|
126
|
-
"name": p.name,
|
|
127
|
-
"value": p.price * p.stock
|
|
128
|
-
}
|
|
129
|
-
}
|
|
32
|
+
^
|
|
130
33
|
```
|
|
131
34
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## Conditionals
|
|
137
|
-
|
|
138
|
-
```sl
|
|
139
|
-
if (x > 5) {
|
|
140
|
-
sldeploy "Greater than 5"
|
|
141
|
-
} else {
|
|
142
|
-
sldeploy "5 or less"
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
## Loops
|
|
149
|
-
|
|
150
|
-
### While Loop
|
|
35
|
+
````
|
|
151
36
|
|
|
152
|
-
|
|
153
|
-
let i = 0
|
|
154
|
-
while (i < 3) {
|
|
155
|
-
sldeploy i
|
|
156
|
-
i = i + 1
|
|
157
|
-
}
|
|
158
|
-
```
|
|
37
|
+
This format makes debugging fast and intuitive, even for beginners.
|
|
159
38
|
|
|
160
39
|
---
|
|
161
40
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
Starlight includes a **start / race** control structure similar to a switch statement, with **fall-through behavior**.
|
|
41
|
+
### 🧠 Syntax Errors (Parser Errors)
|
|
165
42
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
```sl
|
|
169
|
-
start (value) {
|
|
170
|
-
race (1) {
|
|
171
|
-
# body
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
race (2) {
|
|
175
|
-
# body
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
```
|
|
43
|
+
Syntax errors are detected during parsing and reported before execution begins.
|
|
179
44
|
|
|
180
|
-
|
|
45
|
+
Features:
|
|
46
|
+
- Precise location tracking
|
|
47
|
+
- Friendly suggestions
|
|
48
|
+
- No Node.js stack traces
|
|
49
|
+
- Clean termination
|
|
181
50
|
|
|
51
|
+
Example:
|
|
182
52
|
```sl
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
race (1) { sldeploy("Race 1 executed") }
|
|
187
|
-
race (2) { sldeploy("Race 2 executed") }
|
|
188
|
-
race (3) { sldeploy("Race 3 executed") }
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
sldeploy("Done with start statement")
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Expected Output
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
Race 2 executed
|
|
198
|
-
Race 3 executed
|
|
199
|
-
Done with start statement
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## Markdown Preview (`starlight filename.md`)
|
|
205
|
-
|
|
206
|
-
Starlight can also be used to **preview Markdown files** directly from the CLI.
|
|
207
|
-
|
|
208
|
-
### Usage
|
|
209
|
-
|
|
210
|
-
```bash
|
|
211
|
-
starlight README.md
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
### How It Works (Execution Flow)
|
|
215
|
-
|
|
216
|
-
1. The CLI detects the `.md` file extension
|
|
217
|
-
2. The Markdown file is read from disk
|
|
218
|
-
3. Markdown is converted to HTML using a full-featured Markdown renderer
|
|
219
|
-
4. A **temporary HTML file** is created in the system temp directory
|
|
220
|
-
5. The file is opened in your default browser using `file://`
|
|
221
|
-
6. After the browser loads, the temporary file is **automatically deleted**
|
|
222
|
-
|
|
223
|
-
This makes Starlight useful not only as a programming language, but also as a **developer productivity tool**.
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## Array Helpers: map, filter, reduce
|
|
228
|
-
|
|
229
|
-
Starlight provides built-in **functional helpers** for working with arrays: `map`, `filter`, and `reduce`.
|
|
230
|
-
These helpers are **async-aware**, work seamlessly with **arrow functions**, and integrate fully with Starlight’s runtime and error handling.
|
|
231
|
-
|
|
232
|
-
Unlike JavaScript, these are **global functions** (not methods), keeping the language simple and consistent.
|
|
233
|
-
|
|
234
|
-
---
|
|
235
|
-
|
|
236
|
-
### map(array, fn)
|
|
237
|
-
|
|
238
|
-
Transforms each element of an array using a callback function and returns a **new array**.
|
|
239
|
-
|
|
240
|
-
**Syntax:**
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
map(array, fn)
|
|
244
|
-
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
**Example:**
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
let numbers = [1, 2, 3, 4]
|
|
251
|
-
|
|
252
|
-
let squared = await map(numbers, x => x * x)
|
|
253
|
-
|
|
254
|
-
sldeploy squared
|
|
255
|
-
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
**Output:**
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
[ 1, 4, 9, 16 ]
|
|
262
|
-
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
- `fn` receives `(value, index, array)`
|
|
266
|
-
- Does **not** modify the original array
|
|
267
|
-
- Supports `async` arrow functions
|
|
268
|
-
|
|
269
|
-
---
|
|
270
|
-
|
|
271
|
-
### filter(array, fn)
|
|
272
|
-
|
|
273
|
-
Selects elements from an array that satisfy a condition and returns a **new array**.
|
|
274
|
-
|
|
275
|
-
**Syntax:**
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
filter(array, fn)
|
|
279
|
-
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
**Example:**
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
let numbers = [1, 2, 3, 4, 5, 6]
|
|
286
|
-
|
|
287
|
-
let evens = await filter(numbers, x => x % 2 == 0)
|
|
288
|
-
|
|
289
|
-
sldeploy evens
|
|
53
|
+
if true {
|
|
54
|
+
sldeploy("This block is never closed")
|
|
55
|
+
````
|
|
290
56
|
|
|
291
|
-
|
|
57
|
+
Output:
|
|
292
58
|
|
|
293
|
-
**Output:**
|
|
294
59
|
```
|
|
60
|
+
Unterminated block
|
|
61
|
+
Did you forget to close the block with '}'?
|
|
62
|
+
at line 2, column 0
|
|
295
63
|
|
|
296
|
-
|
|
297
|
-
|
|
64
|
+
^
|
|
298
65
|
```
|
|
299
66
|
|
|
300
|
-
- `fn` must return `true` or `false`
|
|
301
|
-
- `fn` receives `(value, index, array)`
|
|
302
|
-
- Original array remains unchanged
|
|
303
|
-
|
|
304
67
|
---
|
|
305
68
|
|
|
306
|
-
###
|
|
69
|
+
### ⚙️ Runtime Errors (Evaluator Errors)
|
|
307
70
|
|
|
308
|
-
|
|
71
|
+
Runtime errors occur during execution and include:
|
|
309
72
|
|
|
310
|
-
|
|
311
|
-
|
|
73
|
+
* Undefined variables
|
|
74
|
+
* Invalid operations
|
|
75
|
+
* Logical mistakes
|
|
312
76
|
|
|
313
|
-
|
|
77
|
+
Starlight also provides **intelligent name suggestions**:
|
|
314
78
|
|
|
315
79
|
```
|
|
316
|
-
|
|
317
|
-
|
|
80
|
+
Undefined variable: "scroe"
|
|
81
|
+
Did you mean "score"?
|
|
82
|
+
at line 10, column 5
|
|
83
|
+
^
|
|
318
84
|
```
|
|
319
85
|
|
|
320
|
-
let numbers = [1, 2, 3, 4, 5]
|
|
321
|
-
|
|
322
|
-
let total = await reduce(numbers, (acc, value) => acc + value, 0)
|
|
323
|
-
|
|
324
|
-
sldeploy total
|
|
325
|
-
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
**Output:**
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
15
|
|
332
|
-
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
- `fn` receives `(accumulator, value, index, array)`
|
|
336
|
-
- `initial` is optional, but recommended
|
|
337
|
-
- Throws a runtime error if used on an empty array without an initial value
|
|
338
|
-
|
|
339
86
|
---
|
|
340
87
|
|
|
341
|
-
###
|
|
342
|
-
|
|
343
|
-
All three helpers support `async` functions:
|
|
344
|
-
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
let results = await map(items, async item => {
|
|
348
|
-
await sleep(100)
|
|
349
|
-
return item * 2
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
---
|
|
88
|
+
### 🎨 Color-Coded Errors
|
|
355
89
|
|
|
356
|
-
|
|
90
|
+
Errors are color-coded for clarity:
|
|
357
91
|
|
|
358
|
-
|
|
92
|
+
* **Red** – Fatal syntax or runtime errors
|
|
93
|
+
* **Yellow** – Warnings or suggestions
|
|
94
|
+
* **White** – Neutral information (source preview, pointers)
|
|
359
95
|
|
|
360
|
-
|
|
361
|
-
- Avoid prototype complexity
|
|
362
|
-
- Work consistently with all iterables
|
|
363
|
-
- Integrate cleanly with the evaluator and runtime
|
|
96
|
+
This ensures errors are readable in all terminals.
|
|
364
97
|
|
|
365
98
|
---
|
|
366
99
|
|
|
367
|
-
###
|
|
100
|
+
### Safe Execution Model
|
|
368
101
|
|
|
369
|
-
|
|
102
|
+
* Execution **stops immediately** on error
|
|
103
|
+
* No uncaught exceptions
|
|
104
|
+
* No JavaScript stack traces leaked
|
|
105
|
+
* Clean exit behavior
|
|
370
106
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
```sl
|
|
374
|
-
value = expression1 ?? expression2
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
* `expression1` is evaluated first.
|
|
378
|
-
* If it is **not null or undefined**, its value is used.
|
|
379
|
-
* Otherwise, the value of `expression2` is used.
|
|
380
|
-
|
|
381
|
-
**Example:**
|
|
382
|
-
|
|
383
|
-
```sl
|
|
384
|
-
define a = null
|
|
385
|
-
define b = a ?? 42
|
|
386
|
-
sldeploy b # Output: 42
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
**Notes:**
|
|
390
|
-
|
|
391
|
-
* Only `null` and `undefined` are treated as "empty" values. Other falsy values like `0`, `false`, or `""` will **not** trigger the default.
|
|
392
|
-
* This operator is optional. If you prefer, you can achieve the same result using a simple `if` statement:
|
|
393
|
-
|
|
394
|
-
```sl
|
|
395
|
-
define a = null
|
|
396
|
-
define b = if a != null then a else 42
|
|
397
|
-
sldeploy b # Output: 42
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
This operator simplifies code that needs default values and makes your scripts cleaner and more readable.
|
|
107
|
+
This keeps Starlight predictable and safe for learning and production use.
|
|
401
108
|
|
|
402
109
|
---
|
|
403
110
|
|
|
404
|
-
|
|
111
|
+
### Summary
|
|
405
112
|
|
|
406
|
-
|
|
407
|
-
* **Fast server-side automation**
|
|
408
|
-
* Familiar syntax with **less boilerplate**
|
|
409
|
-
* Full access to the **Node.js ecosystem**
|
|
113
|
+
Starlight’s error handling is:
|
|
410
114
|
|
|
411
|
-
|
|
115
|
+
* Modern
|
|
116
|
+
* Precise
|
|
117
|
+
* Beginner-friendly
|
|
118
|
+
* Professional-grade
|
|
412
119
|
|
|
413
|
-
|
|
120
|
+
By using caret-based diagnostics and intelligent suggestions, Starlight provides a first-class developer experience from day one.
|
|
414
121
|
|
|
415
|
-
MIT License
|
|
416
122
|
|
|
417
|
-
---
|
|
418
123
|
|
|
419
124
|
## Author and Developer
|
|
420
125
|
Dominex Macedon
|