@jishaanyazmi/code-script 1.0.0
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 +522 -0
- package/dist/ast.d.ts +195 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +2 -0
- package/dist/ast.js.map +1 -0
- package/dist/compiler-core.d.ts +62 -0
- package/dist/compiler-core.d.ts.map +1 -0
- package/dist/compiler-core.js +577 -0
- package/dist/compiler-core.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer.d.ts +20 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +337 -0
- package/dist/lexer.js.map +1 -0
- package/dist/parser.d.ts +24 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +584 -0
- package/dist/parser.js.map +1 -0
- package/dist/shared.d.ts +6 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +13 -0
- package/dist/shared.js.map +1 -0
- package/dist/tokenizer.d.ts +28 -0
- package/dist/tokenizer.d.ts.map +1 -0
- package/dist/tokenizer.js +32 -0
- package/dist/tokenizer.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<h1>CodeScript</h1>
|
|
4
|
+
|
|
5
|
+
<p>A beginner-friendly programming language that transpiles to JavaScript.</p>
|
|
6
|
+
|
|
7
|
+
<p>
|
|
8
|
+
<img src="https://img.shields.io/badge/version-1.0.0-blue?style=flat-square" alt="version" />
|
|
9
|
+
<img src="https://img.shields.io/badge/language-TypeScript-3178c6?style=flat-square" alt="typescript" />
|
|
10
|
+
<img src="https://img.shields.io/badge/runtime-Node.js-339933?style=flat-square" alt="nodejs" />
|
|
11
|
+
<img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="license" />
|
|
12
|
+
<img src="https://img.shields.io/badge/status-active-brightgreen?style=flat-square" alt="status" />
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## What is CodeScript?
|
|
20
|
+
|
|
21
|
+
CodeScript is a lightweight, readable programming language that compiles to JavaScript. It replaces confusing syntax with plain English keywords so beginners can focus on learning programming logic instead of fighting the language.
|
|
22
|
+
|
|
23
|
+
Every `.code` file you write is transpiled into clean, readable JavaScript and executed by Node.js.
|
|
24
|
+
|
|
25
|
+
```code
|
|
26
|
+
make name = "Zishan"
|
|
27
|
+
|
|
28
|
+
do greet(person){
|
|
29
|
+
say("Hello " + person)
|
|
30
|
+
give person
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
greet(name)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// Generated JavaScript
|
|
38
|
+
let name = "Zishan";
|
|
39
|
+
|
|
40
|
+
function greet(person){
|
|
41
|
+
console.log("Hello " + person);
|
|
42
|
+
return person;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
greet(name);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Why CodeScript?
|
|
51
|
+
|
|
52
|
+
| Problem | CodeScript Solution |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `console.log` is confusing | Use `say` instead |
|
|
55
|
+
| `let`, `const`, `var` are unclear | Use `make` and `fixed` |
|
|
56
|
+
| `function` keyword is verbose | Use `do` |
|
|
57
|
+
| `this` is confusing | Use `me` |
|
|
58
|
+
| `try/catch/finally` is intimidating | Use `attempt/oops/done` |
|
|
59
|
+
| `new` keyword feels magical | Use `create` |
|
|
60
|
+
| `null` and `undefined` are unclear | Use `empty` and `unknown` |
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
**Requirements:** Node.js 18 or higher
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install -g @codescript/cli
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Verify installation:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
codescript --version
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Quick Start
|
|
81
|
+
|
|
82
|
+
**1. Create your first file**
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Create hello.code
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```code
|
|
89
|
+
say("Hello, World!")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**2. Run it**
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
codescript hello.code
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Output:**
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
Hello, World!
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## CLI Commands
|
|
107
|
+
|
|
108
|
+
| Command | Description |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `codescript <file.code>` | Compile and run a file |
|
|
111
|
+
| `codescript build <file.code>` | Compile only — outputs a `.js` file |
|
|
112
|
+
| `codescript watch <file.code>` | Watch for changes and recompile automatically |
|
|
113
|
+
| `codescript init` | Scaffold a new CodeScript project |
|
|
114
|
+
| `codescript --version` | Show the installed version |
|
|
115
|
+
| `codescript --help` | Show usage information |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Compiler Pipeline
|
|
120
|
+
|
|
121
|
+
Every `.code` file passes through these stages before execution:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
Source (.code)
|
|
125
|
+
│
|
|
126
|
+
▼
|
|
127
|
+
Lexer → Converts characters into tokens
|
|
128
|
+
│
|
|
129
|
+
▼
|
|
130
|
+
Parser → Converts tokens into an AST
|
|
131
|
+
│
|
|
132
|
+
▼
|
|
133
|
+
AST → Abstract Syntax Tree (program structure)
|
|
134
|
+
│
|
|
135
|
+
▼
|
|
136
|
+
Semantic Analyzer → Validates scope, types, and rules
|
|
137
|
+
│
|
|
138
|
+
▼
|
|
139
|
+
Optimizer → Constant folding, dead code removal
|
|
140
|
+
│
|
|
141
|
+
▼
|
|
142
|
+
JS Generator → Emits clean JavaScript
|
|
143
|
+
│
|
|
144
|
+
▼
|
|
145
|
+
Node.js → Executes the output
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Keyword Reference
|
|
151
|
+
|
|
152
|
+
### Variables & Constants
|
|
153
|
+
|
|
154
|
+
| Keyword | JavaScript | Description |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `make` | `let` | Declares a mutable variable |
|
|
157
|
+
| `fixed` | `const` | Declares an immutable constant — must be initialized |
|
|
158
|
+
| `keep` | `var` | Legacy variable — function scoped, avoid in new code |
|
|
159
|
+
|
|
160
|
+
```code
|
|
161
|
+
make age = 20
|
|
162
|
+
fixed PI = 3.14159
|
|
163
|
+
keep counter = 0
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Functions
|
|
169
|
+
|
|
170
|
+
| Keyword | JavaScript | Description |
|
|
171
|
+
|---|---|---|
|
|
172
|
+
| `do` | `function` | Declares a reusable function |
|
|
173
|
+
| `give` | `return` | Returns a value from a function |
|
|
174
|
+
| `later` | `async` | Marks a function as asynchronous |
|
|
175
|
+
| `wait` | `await` | Waits for an async operation to complete |
|
|
176
|
+
|
|
177
|
+
```code
|
|
178
|
+
do add(a, b){
|
|
179
|
+
give a + b
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
later do fetchData(url){
|
|
183
|
+
make result = wait fetch(url)
|
|
184
|
+
give result
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
### Output & Input
|
|
191
|
+
|
|
192
|
+
| Keyword | JavaScript | Description |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| `say` | `console.log` | Prints a value to the console |
|
|
195
|
+
|
|
196
|
+
```code
|
|
197
|
+
say("Hello World")
|
|
198
|
+
say(42)
|
|
199
|
+
say(user.name)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### Conditions
|
|
205
|
+
|
|
206
|
+
| Keyword | JavaScript | Description |
|
|
207
|
+
|---|---|---|
|
|
208
|
+
| `check` | `if` | Executes a block when the condition is true |
|
|
209
|
+
| `otherwise` | `else` | Executes when the `check` condition is false |
|
|
210
|
+
| `pick` | `switch` | Selects one path from multiple options |
|
|
211
|
+
| `when` | `case` | Defines a single case inside a `pick` block |
|
|
212
|
+
| `anyway` | `default` | The fallback case inside a `pick` block |
|
|
213
|
+
|
|
214
|
+
```code
|
|
215
|
+
check(age >= 18){
|
|
216
|
+
say("Adult")
|
|
217
|
+
}otherwise{
|
|
218
|
+
say("Minor")
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
pick(day){
|
|
222
|
+
when "Monday"{
|
|
223
|
+
say("Start of the week")
|
|
224
|
+
}
|
|
225
|
+
when "Friday"{
|
|
226
|
+
say("Almost weekend")
|
|
227
|
+
}
|
|
228
|
+
anyway{
|
|
229
|
+
say("Regular day")
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### Loops
|
|
237
|
+
|
|
238
|
+
| Keyword | JavaScript | Description |
|
|
239
|
+
|---|---|---|
|
|
240
|
+
| `repeat` | `for` | Repeats a block a set number of times |
|
|
241
|
+
| `until` | `while` | Repeats while a condition is true |
|
|
242
|
+
| `stop` | `break` | Exits the nearest loop immediately |
|
|
243
|
+
| `skip` | `continue` | Skips the current iteration and continues |
|
|
244
|
+
|
|
245
|
+
```code
|
|
246
|
+
repeat(make i = 0; i < 5; i++){
|
|
247
|
+
say(i)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
make count = 0
|
|
251
|
+
until(count < 10){
|
|
252
|
+
say(count)
|
|
253
|
+
count++
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
repeat(make i = 0; i < 10; i++){
|
|
257
|
+
check(i == 5){ stop }
|
|
258
|
+
check(i == 3){ skip }
|
|
259
|
+
say(i)
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### Classes & OOP
|
|
266
|
+
|
|
267
|
+
| Keyword | JavaScript | Description |
|
|
268
|
+
|---|---|---|
|
|
269
|
+
| `type` | `class` | Declares a class |
|
|
270
|
+
| `from` | `extends` | Inherits from a parent class |
|
|
271
|
+
| `create` | `new` | Creates a new instance of a class |
|
|
272
|
+
| `me` | `this` | Refers to the current object instance |
|
|
273
|
+
| `parent` | `super` | Calls the parent class constructor or method |
|
|
274
|
+
| `shared` | `static` | Declares a static method or property |
|
|
275
|
+
| `mine` | `private` | Marks a member as private |
|
|
276
|
+
| `everyone` | `public` | Marks a member as public |
|
|
277
|
+
| `family` | `protected` | Marks a member as protected |
|
|
278
|
+
|
|
279
|
+
```code
|
|
280
|
+
type Animal{
|
|
281
|
+
do constructor(name){
|
|
282
|
+
me.name = name
|
|
283
|
+
}
|
|
284
|
+
do speak(){
|
|
285
|
+
say("I am " + me.name)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
type Dog from Animal{
|
|
290
|
+
do constructor(name){
|
|
291
|
+
parent(name)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
make dog = create Dog("Rex")
|
|
296
|
+
dog.speak()
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
### Error Handling
|
|
302
|
+
|
|
303
|
+
| Keyword | JavaScript | Description |
|
|
304
|
+
|---|---|---|
|
|
305
|
+
| `attempt` | `try` | Wraps code that might throw an error |
|
|
306
|
+
| `oops` | `catch` | Handles the error if one is thrown |
|
|
307
|
+
| `panic` | `throw` | Throws an error and stops execution |
|
|
308
|
+
| `done` | `finally` | Always runs after attempt/oops, error or not |
|
|
309
|
+
|
|
310
|
+
```code
|
|
311
|
+
attempt{
|
|
312
|
+
panic "Something went wrong"
|
|
313
|
+
}oops(err){
|
|
314
|
+
say(err)
|
|
315
|
+
}done{
|
|
316
|
+
say("Finished")
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### Modules
|
|
323
|
+
|
|
324
|
+
| Keyword | JavaScript | Description |
|
|
325
|
+
|---|---|---|
|
|
326
|
+
| `grab` | `import` | Imports code from another `.code` file |
|
|
327
|
+
| `share` | `export` | Exports variables, functions, or classes |
|
|
328
|
+
|
|
329
|
+
```code
|
|
330
|
+
// math.code
|
|
331
|
+
do add(a, b){
|
|
332
|
+
give a + b
|
|
333
|
+
}
|
|
334
|
+
share add
|
|
335
|
+
|
|
336
|
+
// main.code
|
|
337
|
+
grab { add } from "./math.code"
|
|
338
|
+
say(add(5, 3))
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
### Boolean & Null Values
|
|
344
|
+
|
|
345
|
+
| Keyword | JavaScript | Description |
|
|
346
|
+
|---|---|---|
|
|
347
|
+
| `yes` | `true` | Boolean true value |
|
|
348
|
+
| `no` | `false` | Boolean false value |
|
|
349
|
+
| `empty` | `null` | Represents an intentionally absent value |
|
|
350
|
+
| `unknown` | `undefined` | Represents an uninitialized value |
|
|
351
|
+
|
|
352
|
+
```code
|
|
353
|
+
make loggedIn = yes
|
|
354
|
+
make guest = no
|
|
355
|
+
make user = empty
|
|
356
|
+
make value = unknown
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
### Utility Keywords
|
|
362
|
+
|
|
363
|
+
| Keyword | JavaScript | Description |
|
|
364
|
+
|---|---|---|
|
|
365
|
+
| `kind` | `typeof` | Returns the type of a value as a string |
|
|
366
|
+
| `is` | `instanceof` | Checks if an object is an instance of a class |
|
|
367
|
+
| `remove` | `delete` | Deletes a property from an object |
|
|
368
|
+
|
|
369
|
+
```code
|
|
370
|
+
say(kind age) // "number"
|
|
371
|
+
say(dog is Animal) // true
|
|
372
|
+
remove user.email
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## Complete Example
|
|
378
|
+
|
|
379
|
+
```code
|
|
380
|
+
// Variables
|
|
381
|
+
make name = "Zishan"
|
|
382
|
+
fixed PI = 3.14
|
|
383
|
+
|
|
384
|
+
// Function
|
|
385
|
+
do greet(person){
|
|
386
|
+
say("Hello " + person)
|
|
387
|
+
give person
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
greet(name)
|
|
391
|
+
|
|
392
|
+
// Condition
|
|
393
|
+
check(PI > 3){
|
|
394
|
+
say("PI is greater than 3")
|
|
395
|
+
}otherwise{
|
|
396
|
+
say("PI is small")
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Loop
|
|
400
|
+
repeat(make i = 1; i < 4; i++){
|
|
401
|
+
say(i)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Array
|
|
405
|
+
make fruits = ["Apple", "Banana", "Orange"]
|
|
406
|
+
say(fruits[0])
|
|
407
|
+
|
|
408
|
+
// Object
|
|
409
|
+
make user = { name: "Alex", age: 20 }
|
|
410
|
+
say(user.name)
|
|
411
|
+
|
|
412
|
+
// Class
|
|
413
|
+
type Animal{
|
|
414
|
+
do constructor(name){
|
|
415
|
+
me.name = name
|
|
416
|
+
}
|
|
417
|
+
do speak(){
|
|
418
|
+
say("I am " + me.name)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
type Dog from Animal{
|
|
423
|
+
do constructor(name){
|
|
424
|
+
parent(name)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
make dog = create Dog("Rex")
|
|
429
|
+
dog.speak()
|
|
430
|
+
|
|
431
|
+
// Error Handling
|
|
432
|
+
attempt{
|
|
433
|
+
panic "something went wrong"
|
|
434
|
+
}oops(err){
|
|
435
|
+
say(err)
|
|
436
|
+
}done{
|
|
437
|
+
say("finished")
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**Output:**
|
|
442
|
+
|
|
443
|
+
```
|
|
444
|
+
Hello Zishan
|
|
445
|
+
PI is greater than 3
|
|
446
|
+
1
|
|
447
|
+
2
|
|
448
|
+
3
|
|
449
|
+
Apple
|
|
450
|
+
Alex
|
|
451
|
+
I am Rex
|
|
452
|
+
something went wrong
|
|
453
|
+
finished
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## Project Structure
|
|
459
|
+
|
|
460
|
+
```
|
|
461
|
+
codescript/
|
|
462
|
+
├── packages/
|
|
463
|
+
│ ├── cli/ CLI — command line interface
|
|
464
|
+
│ ├── compiler/ Compiler orchestrator
|
|
465
|
+
│ ├── lexer/ Lexer — source to tokens
|
|
466
|
+
│ ├── tokenizer/ Token type definitions
|
|
467
|
+
│ ├── parser/ Parser — tokens to AST
|
|
468
|
+
│ ├── ast/ AST node definitions
|
|
469
|
+
│ ├── semantic/ Semantic analyzer
|
|
470
|
+
│ ├── optimizer/ AST optimizer
|
|
471
|
+
│ ├── generator/ JavaScript code generator
|
|
472
|
+
│ ├── resolver/ Module resolver
|
|
473
|
+
│ ├── stdlib/ Standard library
|
|
474
|
+
│ └── shared/ Shared utilities
|
|
475
|
+
├── examples/ Example .code programs
|
|
476
|
+
├── tests/ Automated tests
|
|
477
|
+
├── docs/ Language documentation
|
|
478
|
+
└── README.md
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
## Error Messages
|
|
484
|
+
|
|
485
|
+
CodeScript produces beginner-friendly compiler errors with file, line, column, and a suggested fix.
|
|
486
|
+
|
|
487
|
+
```
|
|
488
|
+
SyntaxError
|
|
489
|
+
File: hello.code
|
|
490
|
+
Line: 12
|
|
491
|
+
Column: 8
|
|
492
|
+
Message: Expected '}' but found ')'
|
|
493
|
+
Suggestion: Close the previous block before ending the function.
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## Roadmap
|
|
499
|
+
|
|
500
|
+
| Milestone | Status |
|
|
501
|
+
|---|---|
|
|
502
|
+
| Documentation | ✅ Complete |
|
|
503
|
+
| Project Setup | ✅ Complete |
|
|
504
|
+
| CLI | ✅ Complete |
|
|
505
|
+
| Lexer | ✅ Complete |
|
|
506
|
+
| Parser + AST | ✅ Complete |
|
|
507
|
+
| Semantic Analyzer | ✅ Complete |
|
|
508
|
+
| Optimizer | ✅ Complete |
|
|
509
|
+
| JavaScript Generator | ✅ Complete |
|
|
510
|
+
| Standard Library | 🔄 In Progress |
|
|
511
|
+
| Module Resolver | 🔄 In Progress |
|
|
512
|
+
| Tests | ⏳ Planned |
|
|
513
|
+
| VS Code Extension | ⏳ Planned |
|
|
514
|
+
| Playground | ⏳ Planned |
|
|
515
|
+
| Website | ⏳ Planned |
|
|
516
|
+
| Version 1.0 Release | ⏳ Planned |
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
## License
|
|
521
|
+
|
|
522
|
+
MIT © Mohd Jishaan Azmi
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
export interface SourceLocation {
|
|
2
|
+
line: number;
|
|
3
|
+
column: number;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
7
|
+
export interface BaseNode {
|
|
8
|
+
loc: SourceLocation;
|
|
9
|
+
}
|
|
10
|
+
export type Expression = Identifier | Literal | BinaryExpression | LogicalExpression | UnaryExpression | AssignmentExpression | CallExpression | MemberExpression | ArrayExpression | ObjectExpression | NewExpression | FunctionExpression | TemplateLiteral;
|
|
11
|
+
export interface Identifier extends BaseNode {
|
|
12
|
+
kind: 'Identifier';
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
export interface Literal extends BaseNode {
|
|
16
|
+
kind: 'Literal';
|
|
17
|
+
value: string | number | boolean | null | undefined;
|
|
18
|
+
raw: string;
|
|
19
|
+
}
|
|
20
|
+
export interface BinaryExpression extends BaseNode {
|
|
21
|
+
kind: 'BinaryExpression';
|
|
22
|
+
operator: string;
|
|
23
|
+
left: Expression;
|
|
24
|
+
right: Expression;
|
|
25
|
+
}
|
|
26
|
+
export interface LogicalExpression extends BaseNode {
|
|
27
|
+
kind: 'LogicalExpression';
|
|
28
|
+
operator: '&&' | '||';
|
|
29
|
+
left: Expression;
|
|
30
|
+
right: Expression;
|
|
31
|
+
}
|
|
32
|
+
export interface UnaryExpression extends BaseNode {
|
|
33
|
+
kind: 'UnaryExpression';
|
|
34
|
+
operator: string;
|
|
35
|
+
operand: Expression;
|
|
36
|
+
}
|
|
37
|
+
export interface AssignmentExpression extends BaseNode {
|
|
38
|
+
kind: 'AssignmentExpression';
|
|
39
|
+
operator: string;
|
|
40
|
+
left: Expression;
|
|
41
|
+
right: Expression;
|
|
42
|
+
}
|
|
43
|
+
export interface CallExpression extends BaseNode {
|
|
44
|
+
kind: 'CallExpression';
|
|
45
|
+
callee: Expression;
|
|
46
|
+
args: Expression[];
|
|
47
|
+
}
|
|
48
|
+
export interface MemberExpression extends BaseNode {
|
|
49
|
+
kind: 'MemberExpression';
|
|
50
|
+
object: Expression;
|
|
51
|
+
property: Expression;
|
|
52
|
+
computed: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ArrayExpression extends BaseNode {
|
|
55
|
+
kind: 'ArrayExpression';
|
|
56
|
+
elements: Expression[];
|
|
57
|
+
}
|
|
58
|
+
export interface ObjectExpression extends BaseNode {
|
|
59
|
+
kind: 'ObjectExpression';
|
|
60
|
+
properties: ObjectProperty[];
|
|
61
|
+
}
|
|
62
|
+
export interface ObjectProperty extends BaseNode {
|
|
63
|
+
kind: 'ObjectProperty';
|
|
64
|
+
key: Identifier;
|
|
65
|
+
value: Expression;
|
|
66
|
+
}
|
|
67
|
+
export interface NewExpression extends BaseNode {
|
|
68
|
+
kind: 'NewExpression';
|
|
69
|
+
callee: Identifier;
|
|
70
|
+
args: Expression[];
|
|
71
|
+
}
|
|
72
|
+
export interface FunctionExpression extends BaseNode {
|
|
73
|
+
kind: 'FunctionExpression';
|
|
74
|
+
params: Identifier[];
|
|
75
|
+
body: BlockStatement;
|
|
76
|
+
isAsync: boolean;
|
|
77
|
+
}
|
|
78
|
+
export interface TemplateLiteral extends BaseNode {
|
|
79
|
+
kind: 'TemplateLiteral';
|
|
80
|
+
raw: string;
|
|
81
|
+
}
|
|
82
|
+
export type Statement = ProgramNode | VariableDeclaration | FunctionDeclaration | ReturnStatement | IfStatement | SwitchStatement | RepeatStatement | UntilStatement | BreakStatement | ContinueStatement | ClassDeclaration | ImportDeclaration | ExportDeclaration | TryStatement | ThrowStatement | ExpressionStatement;
|
|
83
|
+
export interface ProgramNode extends BaseNode {
|
|
84
|
+
kind: 'Program';
|
|
85
|
+
body: Statement[];
|
|
86
|
+
}
|
|
87
|
+
export interface VariableDeclaration extends BaseNode {
|
|
88
|
+
kind: 'VariableDeclaration';
|
|
89
|
+
keyword: 'make' | 'fixed' | 'keep';
|
|
90
|
+
name: Identifier;
|
|
91
|
+
value: Expression | null;
|
|
92
|
+
}
|
|
93
|
+
export interface FunctionDeclaration extends BaseNode {
|
|
94
|
+
kind: 'FunctionDeclaration';
|
|
95
|
+
name: Identifier;
|
|
96
|
+
params: Identifier[];
|
|
97
|
+
body: BlockStatement;
|
|
98
|
+
isAsync: boolean;
|
|
99
|
+
}
|
|
100
|
+
export interface BlockStatement extends BaseNode {
|
|
101
|
+
kind: 'BlockStatement';
|
|
102
|
+
body: Statement[];
|
|
103
|
+
}
|
|
104
|
+
export interface ReturnStatement extends BaseNode {
|
|
105
|
+
kind: 'ReturnStatement';
|
|
106
|
+
value: Expression | null;
|
|
107
|
+
}
|
|
108
|
+
export interface IfStatement extends BaseNode {
|
|
109
|
+
kind: 'IfStatement';
|
|
110
|
+
condition: Expression;
|
|
111
|
+
consequent: BlockStatement;
|
|
112
|
+
alternate: BlockStatement | null;
|
|
113
|
+
}
|
|
114
|
+
export interface SwitchStatement extends BaseNode {
|
|
115
|
+
kind: 'SwitchStatement';
|
|
116
|
+
discriminant: Expression;
|
|
117
|
+
cases: SwitchCase[];
|
|
118
|
+
defaultCase: BlockStatement | null;
|
|
119
|
+
}
|
|
120
|
+
export interface SwitchCase extends BaseNode {
|
|
121
|
+
kind: 'SwitchCase';
|
|
122
|
+
test: Expression;
|
|
123
|
+
body: BlockStatement;
|
|
124
|
+
}
|
|
125
|
+
export interface RepeatStatement extends BaseNode {
|
|
126
|
+
kind: 'RepeatStatement';
|
|
127
|
+
init: VariableDeclaration | ExpressionStatement | null;
|
|
128
|
+
condition: Expression | null;
|
|
129
|
+
update: Expression | null;
|
|
130
|
+
body: BlockStatement;
|
|
131
|
+
}
|
|
132
|
+
export interface UntilStatement extends BaseNode {
|
|
133
|
+
kind: 'UntilStatement';
|
|
134
|
+
condition: Expression;
|
|
135
|
+
body: BlockStatement;
|
|
136
|
+
}
|
|
137
|
+
export interface BreakStatement extends BaseNode {
|
|
138
|
+
kind: 'BreakStatement';
|
|
139
|
+
}
|
|
140
|
+
export interface ContinueStatement extends BaseNode {
|
|
141
|
+
kind: 'ContinueStatement';
|
|
142
|
+
}
|
|
143
|
+
export interface ClassDeclaration extends BaseNode {
|
|
144
|
+
kind: 'ClassDeclaration';
|
|
145
|
+
name: Identifier;
|
|
146
|
+
superClass: Identifier | null;
|
|
147
|
+
body: ClassBody;
|
|
148
|
+
}
|
|
149
|
+
export interface ClassBody extends BaseNode {
|
|
150
|
+
kind: 'ClassBody';
|
|
151
|
+
members: ClassMember[];
|
|
152
|
+
}
|
|
153
|
+
export type ClassMember = MethodDeclaration | ConstructorDeclaration;
|
|
154
|
+
export interface ConstructorDeclaration extends BaseNode {
|
|
155
|
+
kind: 'ConstructorDeclaration';
|
|
156
|
+
params: Identifier[];
|
|
157
|
+
body: BlockStatement;
|
|
158
|
+
}
|
|
159
|
+
export interface MethodDeclaration extends BaseNode {
|
|
160
|
+
kind: 'MethodDeclaration';
|
|
161
|
+
name: Identifier;
|
|
162
|
+
params: Identifier[];
|
|
163
|
+
body: BlockStatement;
|
|
164
|
+
isStatic: boolean;
|
|
165
|
+
isAsync: boolean;
|
|
166
|
+
}
|
|
167
|
+
export interface ImportDeclaration extends BaseNode {
|
|
168
|
+
kind: 'ImportDeclaration';
|
|
169
|
+
specifiers: Identifier[];
|
|
170
|
+
source: string;
|
|
171
|
+
}
|
|
172
|
+
export interface ExportDeclaration extends BaseNode {
|
|
173
|
+
kind: 'ExportDeclaration';
|
|
174
|
+
specifiers: Identifier[];
|
|
175
|
+
}
|
|
176
|
+
export interface TryStatement extends BaseNode {
|
|
177
|
+
kind: 'TryStatement';
|
|
178
|
+
body: BlockStatement;
|
|
179
|
+
handler: CatchClause | null;
|
|
180
|
+
finalizer: BlockStatement | null;
|
|
181
|
+
}
|
|
182
|
+
export interface CatchClause extends BaseNode {
|
|
183
|
+
kind: 'CatchClause';
|
|
184
|
+
param: Identifier;
|
|
185
|
+
body: BlockStatement;
|
|
186
|
+
}
|
|
187
|
+
export interface ThrowStatement extends BaseNode {
|
|
188
|
+
kind: 'ThrowStatement';
|
|
189
|
+
value: Expression;
|
|
190
|
+
}
|
|
191
|
+
export interface ExpressionStatement extends BaseNode {
|
|
192
|
+
kind: 'ExpressionStatement';
|
|
193
|
+
expression: Expression;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"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