starlight-cli 1.1.2 → 1.1.4
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 +121 -122
- package/dist/index.js +170 -70
- package/package.json +1 -1
- package/src/evaluator.js +97 -34
- package/src/lexer.js +1 -1
- package/src/parser.js +71 -34
- package/src/starlight.js +1 -1
package/README.md
CHANGED
|
@@ -2,52 +2,64 @@
|
|
|
2
2
|
|
|
3
3
|
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.
|
|
4
4
|
|
|
5
|
-
**Official Reference:** [
|
|
5
|
+
**Official Reference:** [
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## Key Features
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
|
|
12
|
+
- **Modern, Simple Syntax** – Familiar to JavaScript and Python developers
|
|
13
|
+
- **Async / Await** – Native support for asynchronous operations
|
|
14
|
+
- **Modules & Imports** – Import JavaScript packages or other `.sl` files
|
|
15
|
+
- **Server-side Ready** – Built on Node.js, ideal for backend logic
|
|
16
|
+
- **Interactive I/O** – Built-in `ask` and `sldeploy`
|
|
17
|
+
- **Built-in Utilities** – `sleep`, `len`, `keys`, `values`, `fetch`, `get`, `post`
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
---
|
|
19
21
|
|
|
20
22
|
## Installation
|
|
21
23
|
|
|
22
|
-
1. Install **Node.js** (v18+ recommended)
|
|
23
|
-
2. Install Starlight CLI:
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Install **Node.js** (v18+ recommended)1. $1
|
|
26
|
+
Install Starlight CLI:1. $1
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
26
31
|
npm install -g starlight-cli
|
|
32
|
+
|
|
27
33
|
```
|
|
28
34
|
|
|
29
35
|
---
|
|
30
36
|
|
|
31
37
|
## Your First Program (`hello.sl`)
|
|
32
38
|
|
|
33
|
-
```
|
|
39
|
+
```
|
|
40
|
+
|
|
34
41
|
let name = ask("What is your name?")
|
|
35
42
|
sldeploy "Hello, " + name + "!"
|
|
43
|
+
|
|
36
44
|
```
|
|
37
45
|
|
|
38
46
|
Run:
|
|
39
47
|
|
|
40
|
-
```
|
|
48
|
+
```
|
|
49
|
+
|
|
41
50
|
starlight hello.sl
|
|
51
|
+
|
|
42
52
|
```
|
|
43
53
|
|
|
44
54
|
---
|
|
45
55
|
|
|
46
56
|
## Output
|
|
47
57
|
|
|
48
|
-
```
|
|
58
|
+
```
|
|
59
|
+
|
|
49
60
|
What is your name? Alice
|
|
50
61
|
Hello, Alice!
|
|
62
|
+
|
|
51
63
|
```
|
|
52
64
|
|
|
53
65
|
---
|
|
@@ -56,200 +68,187 @@ Hello, Alice!
|
|
|
56
68
|
|
|
57
69
|
### Variables
|
|
58
70
|
|
|
59
|
-
```
|
|
71
|
+
```
|
|
72
|
+
|
|
60
73
|
let x = 10
|
|
61
74
|
let text = "hello"
|
|
75
|
+
|
|
62
76
|
```
|
|
63
77
|
|
|
64
78
|
---
|
|
65
79
|
|
|
66
80
|
### Functions
|
|
67
81
|
|
|
68
|
-
```
|
|
82
|
+
```
|
|
83
|
+
|
|
69
84
|
func add(a, b) {
|
|
70
85
|
return a + b
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
sldeploy add(2, 3)
|
|
89
|
+
|
|
74
90
|
```
|
|
75
91
|
|
|
76
92
|
### Async Functions
|
|
77
93
|
|
|
78
|
-
```
|
|
94
|
+
```
|
|
95
|
+
|
|
79
96
|
async func load() {
|
|
80
97
|
let data = await get("https://example.com/api")
|
|
81
98
|
sldeploy data
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
load()
|
|
102
|
+
|
|
85
103
|
```
|
|
86
104
|
|
|
87
105
|
---
|
|
88
106
|
|
|
89
|
-
##
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
if (x > 5) {
|
|
93
|
-
sldeploy "Greater than 5"
|
|
94
|
-
} else {
|
|
95
|
-
sldeploy "5 or less"
|
|
96
|
-
}
|
|
97
|
-
```
|
|
107
|
+
## Arrow Functions
|
|
98
108
|
|
|
99
|
-
|
|
109
|
+
Arrow functions provide a **concise and expressive** way to define functions. They support expressions, block bodies, conditionals, loops, and `return` statements.
|
|
100
110
|
|
|
101
|
-
|
|
111
|
+
### Basic Arrow Function
|
|
102
112
|
|
|
103
|
-
|
|
113
|
+
```
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
sldeploy i
|
|
109
|
-
i = i + 1
|
|
110
|
-
}
|
|
115
|
+
let square = x => x * x
|
|
116
|
+
sldeploy square(5)
|
|
117
|
+
|
|
111
118
|
```
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
### Multiple Parameters
|
|
114
121
|
|
|
115
|
-
|
|
122
|
+
```
|
|
116
123
|
|
|
124
|
+
let add = (a, b) => a + b
|
|
125
|
+
sldeploy add(10, 20)
|
|
126
|
+
|
|
117
127
|
```
|
|
118
|
-
for (let i = 0; i < 3; i = i + 1) {
|
|
119
|
-
sldeploy i
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
### For-In Loop (Python-style)
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
### Block Body with if / else
|
|
128
130
|
|
|
129
|
-
```
|
|
130
|
-
let items = ["apple", "banana", "orange"]
|
|
131
|
+
```
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
let label = p => {
|
|
134
|
+
if (p.price > 1000) {
|
|
135
|
+
return "Premium"
|
|
136
|
+
} else {
|
|
137
|
+
return "Standard"
|
|
138
|
+
}
|
|
134
139
|
}
|
|
140
|
+
|
|
135
141
|
```
|
|
136
142
|
|
|
137
|
-
|
|
143
|
+
### Arrow Functions with Objects
|
|
138
144
|
|
|
139
|
-
```
|
|
140
|
-
for let item in items {
|
|
141
|
-
sldeploy item
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Iterate over object keys:
|
|
146
|
-
|
|
147
|
-
```
|
|
148
|
-
let user = { "name": "Alice", "age": 20 }
|
|
145
|
+
```
|
|
149
146
|
|
|
150
|
-
|
|
151
|
-
|
|
147
|
+
let summarize = p => {
|
|
148
|
+
return {
|
|
149
|
+
"name": p.name,
|
|
150
|
+
"value": p.price * p.stock
|
|
151
|
+
}
|
|
152
152
|
}
|
|
153
|
+
|
|
153
154
|
```
|
|
154
155
|
|
|
156
|
+
Arrow functions capture their surrounding scope and behave like standard functions while remaining lightweight and readable.
|
|
157
|
+
|
|
155
158
|
---
|
|
156
159
|
|
|
157
|
-
##
|
|
160
|
+
## Conditionals
|
|
158
161
|
|
|
159
|
-
```
|
|
160
|
-
let product = {
|
|
161
|
-
"name": "Star Lamp",
|
|
162
|
-
"price": 50,
|
|
163
|
-
"tags": ["space", "light"]
|
|
164
|
-
}
|
|
162
|
+
```
|
|
165
163
|
|
|
166
|
-
|
|
164
|
+
if (x > 5) {
|
|
165
|
+
sldeploy "Greater than 5"
|
|
166
|
+
} else {
|
|
167
|
+
sldeploy "5 or less"
|
|
168
|
+
}
|
|
169
|
+
|
|
167
170
|
```
|
|
168
171
|
|
|
169
172
|
---
|
|
170
173
|
|
|
171
|
-
##
|
|
172
|
-
|
|
173
|
-
`sldeploy` works like Python's `print` and can display **any type**:
|
|
174
|
-
|
|
175
|
-
```
|
|
176
|
-
sldeploy 42
|
|
177
|
-
sldeploy "hello"
|
|
178
|
-
sldeploy true
|
|
179
|
-
sldeploy [1, 2, 3]
|
|
180
|
-
sldeploy { "a": 1, "b": 2 }
|
|
181
|
-
```
|
|
174
|
+
## Loops
|
|
182
175
|
|
|
183
|
-
|
|
176
|
+
### While Loop
|
|
184
177
|
|
|
185
|
-
|
|
178
|
+
```
|
|
186
179
|
|
|
187
|
-
|
|
180
|
+
let i = 0
|
|
181
|
+
while (i {
|
|
182
|
+
let response = await get("https://jsonplaceholder.typicode.com/todos/1")
|
|
183
|
+
sldeploy response
|
|
184
|
+
}
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
sldeploy "You entered: " + age
|
|
186
|
+
server()
|
|
187
|
+
|
|
192
188
|
```
|
|
193
189
|
|
|
194
190
|
---
|
|
195
191
|
|
|
196
|
-
##
|
|
192
|
+
## Start & Race Statements
|
|
197
193
|
|
|
198
|
-
|
|
194
|
+
Starlight includes a **start / race** control structure similar to a switch statement, with **fall-through behavior**.
|
|
199
195
|
|
|
200
|
-
|
|
201
|
-
import colors from "starlight-color"
|
|
196
|
+
### Syntax
|
|
202
197
|
|
|
203
|
-
|
|
204
|
-
```
|
|
198
|
+
```
|
|
205
199
|
|
|
206
|
-
|
|
200
|
+
start (value) {
|
|
201
|
+
race (1) {
|
|
202
|
+
# body
|
|
203
|
+
}
|
|
207
204
|
|
|
205
|
+
race (2) {
|
|
206
|
+
# body
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
208
210
|
```
|
|
209
|
-
import { add } from "./math.sl"
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
---
|
|
213
211
|
|
|
214
|
-
|
|
212
|
+
### Example
|
|
215
213
|
|
|
216
|
-
|
|
217
|
-
* `keys(object)` – object keys
|
|
218
|
-
* `values(object)` – object values
|
|
219
|
-
* `sleep(ms)` – async delay
|
|
220
|
-
* `fetch(url)` – low-level fetch
|
|
221
|
-
* `get(url)` – GET request
|
|
222
|
-
* `post(url, data)` – POST request
|
|
223
|
-
* `num(value)` – convert to number
|
|
224
|
-
* `str(value)` – convert to string
|
|
214
|
+
```
|
|
225
215
|
|
|
226
|
-
|
|
216
|
+
define x = 2;
|
|
227
217
|
|
|
228
|
-
|
|
218
|
+
start (x) {
|
|
219
|
+
race (1) { sldeploy("Race 1 executed"); }
|
|
220
|
+
race (2) { sldeploy("Race 2 executed"); }
|
|
221
|
+
race (3) { sldeploy("Race 3 executed"); }
|
|
222
|
+
}
|
|
229
223
|
|
|
224
|
+
sldeploy("Done with start statement");
|
|
225
|
+
|
|
230
226
|
```
|
|
231
|
-
define server = async () => {
|
|
232
|
-
let response = await get("https://jsonplaceholder.typicode.com/todos/1")
|
|
233
|
-
sldeploy response
|
|
234
|
-
}
|
|
235
227
|
|
|
236
|
-
|
|
228
|
+
### Expected Output
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Race 2 executed
|
|
233
|
+
Race 3 executed
|
|
234
|
+
Done with start statement
|
|
235
|
+
|
|
237
236
|
```
|
|
238
237
|
|
|
239
238
|
---
|
|
240
239
|
|
|
241
240
|
## Why Starlight?
|
|
242
241
|
|
|
243
|
-
Starlight is designed for developers who want:
|
|
244
242
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
243
|
+
- A **simple but powerful** scripting language
|
|
244
|
+
- **Fast server-side automation**
|
|
245
|
+
- Familiar syntax with **less boilerplate**
|
|
246
|
+
- Full access to the **Node.js ecosystem**
|
|
247
|
+
|
|
249
248
|
|
|
250
249
|
---
|
|
251
250
|
|
|
252
251
|
📘 Full documentation and tutorials:
|
|
253
|
-
|
|
252
|
+
https://starlight-learn-lang.pages.dev/](https://starlight-learn-lang.pages.dev/>https://starlight-learn-lang.pages.dev/</link)
|
|
254
253
|
|
|
255
|
-
**License:** MIT
|
|
254
|
+
**License:** MIT
|