jpsx 0.1.16 → 0.1.19
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 +143 -242
- package/dist/api/__tests__/compile.test.js +2 -2
- package/dist/api/__tests__/runtime.test.js +129 -123
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +3 -0
- package/dist/generator/generator.js +2 -2
- package/dist/lexer/tokenizer.d.ts +4 -2
- package/dist/lexer/tokenizer.d.ts.map +1 -1
- package/dist/lexer/tokenizer.js +71 -29
- package/dist/parser/grammar.d.ts.map +1 -1
- package/dist/parser/grammar.js +148 -74
- package/dist/parser/parser.js +1 -1
- package/package.json +85 -53
package/dist/parser/grammar.js
CHANGED
|
@@ -55,12 +55,9 @@ const AUG_ASSIGN = { test: (t) => t.type === "OP" && ["+=", "-=", "*=", "/="].in
|
|
|
55
55
|
const grammar = {
|
|
56
56
|
Lexer: undefined,
|
|
57
57
|
ParserRules: [
|
|
58
|
-
{ "name": "program", "symbols": ["
|
|
59
|
-
{ "name": "
|
|
60
|
-
|
|
61
|
-
params: d[2],
|
|
62
|
-
body: d[6]
|
|
63
|
-
}) },
|
|
58
|
+
{ "name": "program", "symbols": ["statements_opt"], "postprocess": (d) => ({ type: "Program", body: (d[0] || []).filter((s) => s !== null) }) },
|
|
59
|
+
{ "name": "statements_opt", "symbols": ["statements"], "postprocess": id },
|
|
60
|
+
{ "name": "statements_opt", "symbols": [], "postprocess": () => [] },
|
|
64
61
|
{ "name": "statements", "symbols": ["statement"], "postprocess": (d) => [d[0]] },
|
|
65
62
|
{ "name": "statements", "symbols": ["statement", "_", "statements"], "postprocess": (d) => [d[0], ...d[2]] },
|
|
66
63
|
{ "name": "statement", "symbols": ["function_def"], "postprocess": id },
|
|
@@ -73,62 +70,83 @@ const grammar = {
|
|
|
73
70
|
{ "name": "statement", "symbols": ["import_stmt"], "postprocess": id },
|
|
74
71
|
{ "name": "statement", "symbols": ["export_stmt"], "postprocess": id },
|
|
75
72
|
{ "name": "statement", "symbols": ["expr_stmt"], "postprocess": id },
|
|
76
|
-
{ "name": "
|
|
73
|
+
{ "name": "statement", "symbols": [NEWLINE], "postprocess": () => null }, // Skip blank lines
|
|
74
|
+
{
|
|
75
|
+
"name": "import_stmt", "symbols": [IMPORT, "_", IDENT, "_", NEWLINE], "postprocess": (d) => ({
|
|
77
76
|
type: "ImportDeclaration",
|
|
78
77
|
source: d[2].value,
|
|
79
78
|
specifiers: [{ local: d[2].value, imported: d[2].value }]
|
|
80
|
-
})
|
|
81
|
-
|
|
79
|
+
})
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "import_stmt", "symbols": [FROM, "_", IDENT, "_", IMPORT, "_", IDENT, "_", NEWLINE], "postprocess": (d) => ({
|
|
82
83
|
type: "ImportDeclaration",
|
|
83
84
|
source: d[2].value,
|
|
84
85
|
specifiers: [{ local: d[6].value, imported: d[6].value }]
|
|
85
|
-
})
|
|
86
|
-
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "import_stmt", "symbols": [FROM, "_", IDENT, "_", IMPORT, "_", IDENT, "_", AS, "_", IDENT, "_", NEWLINE], "postprocess": (d) => ({
|
|
87
90
|
type: "ImportDeclaration",
|
|
88
91
|
source: d[2].value,
|
|
89
92
|
specifiers: [{ local: d[10].value, imported: d[6].value }]
|
|
90
|
-
})
|
|
91
|
-
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "export_stmt", "symbols": [EXPORT, "_", "statement"], "postprocess": (d) => ({
|
|
92
97
|
type: "ExportDeclaration",
|
|
93
98
|
declaration: d[2]
|
|
94
|
-
})
|
|
95
|
-
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "return_stmt", "symbols": [RETURN, "_", "expression_list", "_", "newline_opt"], "postprocess": (d) => ({
|
|
96
103
|
type: "ReturnStatement",
|
|
97
104
|
argument: d[2].length > 1 ? { type: "ArrayLiteral", elements: d[2] } : d[2][0]
|
|
98
|
-
})
|
|
105
|
+
})
|
|
106
|
+
},
|
|
99
107
|
{ "name": "return_stmt", "symbols": [RETURN, "_", NEWLINE], "postprocess": () => ({ type: "ReturnStatement", argument: null }) },
|
|
108
|
+
{ "name": "newline_opt", "symbols": [NEWLINE] },
|
|
109
|
+
{ "name": "newline_opt", "symbols": [] },
|
|
100
110
|
{ "name": "expression_list", "symbols": ["expression"], "postprocess": (d) => [d[0]] },
|
|
101
111
|
{ "name": "expression_list", "symbols": ["expression", "_", COMMA, "_", "expression_list"], "postprocess": (d) => [d[0], ...d[4]] },
|
|
102
|
-
{ "name": "expr_stmt", "symbols": ["expression", "_",
|
|
112
|
+
{ "name": "expr_stmt", "symbols": ["expression", "_", "newline_opt"], "postprocess": (d) => ({ type: "ExpressionStatement", expression: d[0] }) },
|
|
103
113
|
{ "name": "expression", "symbols": ["assignment_expr"], "postprocess": id },
|
|
104
114
|
{ "name": "expression", "symbols": ["conditional_expr"], "postprocess": id },
|
|
105
115
|
{ "name": "expression", "symbols": ["binary_expr"], "postprocess": id },
|
|
106
|
-
{
|
|
116
|
+
{
|
|
117
|
+
"name": "assignment_expr", "symbols": ["target_expr", "_", ASSIGN, "_", "expression"], "postprocess": (d) => ({
|
|
107
118
|
type: "BinaryExpression",
|
|
108
119
|
operator: d[2].value,
|
|
109
120
|
left: d[0],
|
|
110
121
|
right: d[4]
|
|
111
|
-
})
|
|
112
|
-
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "assignment_expr", "symbols": ["target_expr", "_", AUG_ASSIGN, "_", "expression"], "postprocess": (d) => ({
|
|
113
126
|
type: "BinaryExpression",
|
|
114
127
|
operator: d[2].value,
|
|
115
128
|
left: d[0],
|
|
116
129
|
right: d[4]
|
|
117
|
-
})
|
|
130
|
+
})
|
|
131
|
+
},
|
|
118
132
|
{ "name": "target_expr", "symbols": [IDENT], "postprocess": (d) => ({ type: "Identifier", name: d[0].value }) },
|
|
119
133
|
{ "name": "target_expr", "symbols": ["member_expr"], "postprocess": id },
|
|
120
|
-
{
|
|
134
|
+
{
|
|
135
|
+
"name": "target_expr", "symbols": [IDENT, "_", COMMA, "_", "target_expr_list"], "postprocess": (d) => ({
|
|
121
136
|
type: "ArrayLiteral",
|
|
122
137
|
elements: [{ type: "Identifier", name: d[0].value }, ...d[4]]
|
|
123
|
-
})
|
|
138
|
+
})
|
|
139
|
+
},
|
|
124
140
|
{ "name": "target_expr_list", "symbols": [IDENT], "postprocess": (d) => [{ type: "Identifier", name: d[0].value }] },
|
|
125
141
|
{ "name": "target_expr_list", "symbols": [IDENT, "_", COMMA, "_", "target_expr_list"], "postprocess": (d) => [{ type: "Identifier", name: d[0].value }, ...d[4]] },
|
|
126
|
-
{
|
|
142
|
+
{
|
|
143
|
+
"name": "function_def", "symbols": [DEF, "_", IDENT, "_", LPAREN, "_", "func_params", "_", RPAREN, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
127
144
|
type: "FunctionDeclaration",
|
|
128
145
|
name: d[2].value,
|
|
129
146
|
params: d[6],
|
|
130
147
|
body: d[16].filter((s) => s !== null)
|
|
131
|
-
})
|
|
148
|
+
})
|
|
149
|
+
},
|
|
132
150
|
{ "name": "func_params", "symbols": [IDENT], "postprocess": (d) => [d[0].value] },
|
|
133
151
|
{ "name": "func_params", "symbols": [IDENT, "_", COMMA, "_", "func_params"], "postprocess": (d) => [d[0].value, ...d[4]] },
|
|
134
152
|
{ "name": "func_params", "symbols": [IDENT, "_", ASSIGN, "_", "param_value"], "postprocess": (d) => [d[0].value + "=" + d[4].value] },
|
|
@@ -137,82 +155,116 @@ const grammar = {
|
|
|
137
155
|
{ "name": "param_value", "symbols": ["number_literal"], "postprocess": id },
|
|
138
156
|
{ "name": "param_value", "symbols": ["string_literal"], "postprocess": id },
|
|
139
157
|
{ "name": "param_value", "symbols": ["boolean_literal"], "postprocess": id },
|
|
140
|
-
{
|
|
158
|
+
{
|
|
159
|
+
"name": "if_stmt", "symbols": [IF, "_", "expression", "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
141
160
|
type: "IfStatement",
|
|
142
161
|
test: d[2],
|
|
143
162
|
consequent: d[10].filter((s) => s !== null),
|
|
144
163
|
alternate: null
|
|
145
|
-
})
|
|
146
|
-
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "if_stmt", "symbols": [IF, "_", "expression", "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT, "_", ELSE, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
147
168
|
type: "IfStatement",
|
|
148
169
|
test: d[2],
|
|
149
170
|
consequent: d[10].filter((s) => s !== null),
|
|
150
171
|
alternate: d[22].filter((s) => s !== null)
|
|
151
|
-
})
|
|
152
|
-
|
|
172
|
+
})
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"name": "for_stmt", "symbols": [FOR, "_", "loop_vars", "_", IN, "_", RANGE, "_", LPAREN, "_", "expression", "_", COMMA, "_", "expression", "_", RPAREN, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
153
176
|
type: "ForStatement",
|
|
154
177
|
iterator: d[2],
|
|
155
178
|
start: d[10],
|
|
156
179
|
end: d[14],
|
|
157
180
|
body: d[24].filter((s) => s !== null)
|
|
158
|
-
})
|
|
159
|
-
|
|
181
|
+
})
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"name": "for_stmt", "symbols": [FOR, "_", "loop_vars", "_", IN, "_", RANGE, "_", LPAREN, "_", "expression", "_", RPAREN, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
185
|
+
type: "ForStatement",
|
|
186
|
+
iterator: d[2],
|
|
187
|
+
start: { type: "NumberLiteral", value: 0 },
|
|
188
|
+
end: d[10],
|
|
189
|
+
body: d[20].filter((s) => s !== null)
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"name": "for_stmt", "symbols": [FOR, "_", "loop_vars", "_", IN, "_", "expression", "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
160
194
|
type: "ForStatement",
|
|
161
195
|
iterator: d[2],
|
|
162
196
|
collection: d[6],
|
|
163
197
|
body: d[14].filter((s) => s !== null)
|
|
164
|
-
})
|
|
198
|
+
})
|
|
199
|
+
},
|
|
165
200
|
{ "name": "loop_vars", "symbols": [IDENT], "postprocess": (d) => d[0].value },
|
|
166
201
|
{ "name": "loop_vars", "symbols": [IDENT, "_", COMMA, "_", "loop_vars"], "postprocess": (d) => "[" + d[0].value + ", " + d[4].replace(/^\[|\]$/g, "") + "]" },
|
|
167
|
-
{
|
|
202
|
+
{
|
|
203
|
+
"name": "try_stmt", "symbols": [TRY, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT, "_", EXCEPT, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
168
204
|
type: "TryStatement",
|
|
169
205
|
block: d[8].filter((s) => s !== null),
|
|
170
206
|
handler: d[20].filter((s) => s !== null)
|
|
171
|
-
})
|
|
172
|
-
|
|
207
|
+
})
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"name": "class_def", "symbols": [CLASS, "_", IDENT, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
173
211
|
type: "ClassDeclaration",
|
|
174
212
|
name: d[2].value,
|
|
175
213
|
superClass: null,
|
|
176
214
|
body: d[10].filter((s) => s !== null)
|
|
177
|
-
})
|
|
178
|
-
|
|
215
|
+
})
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"name": "class_def", "symbols": [CLASS, "_", IDENT, "_", LPAREN, "_", IDENT, "_", RPAREN, "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
179
219
|
type: "ClassDeclaration",
|
|
180
220
|
name: d[2].value,
|
|
181
221
|
superClass: d[6].value,
|
|
182
222
|
body: d[16].filter((s) => s !== null)
|
|
183
|
-
})
|
|
184
|
-
|
|
223
|
+
})
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"name": "conditional_expr", "symbols": ["binary_expr", "_", IF, "_", "expression", "_", ELSE, "_", "expression"], "postprocess": (d) => ({
|
|
185
227
|
type: "ConditionalExpression",
|
|
186
228
|
test: d[4],
|
|
187
229
|
consequent: d[0],
|
|
188
230
|
alternate: d[8]
|
|
189
|
-
})
|
|
190
|
-
|
|
231
|
+
})
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"name": "binary_expr", "symbols": ["binary_expr", "_", OP, "_", "unary_expr"], "postprocess": (d) => ({
|
|
191
235
|
type: "BinaryExpression",
|
|
192
236
|
operator: d[2].value,
|
|
193
237
|
left: d[0],
|
|
194
238
|
right: d[4]
|
|
195
|
-
})
|
|
196
|
-
|
|
239
|
+
})
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"name": "binary_expr", "symbols": ["binary_expr", "_", AND, "_", "unary_expr"], "postprocess": (d) => ({
|
|
197
243
|
type: "BinaryExpression",
|
|
198
244
|
operator: "and",
|
|
199
245
|
left: d[0],
|
|
200
246
|
right: d[4]
|
|
201
|
-
})
|
|
202
|
-
|
|
247
|
+
})
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"name": "binary_expr", "symbols": ["binary_expr", "_", OR, "_", "unary_expr"], "postprocess": (d) => ({
|
|
203
251
|
type: "BinaryExpression",
|
|
204
252
|
operator: "or",
|
|
205
253
|
left: d[0],
|
|
206
254
|
right: d[4]
|
|
207
|
-
})
|
|
208
|
-
|
|
255
|
+
})
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"name": "binary_expr", "symbols": ["binary_expr", "_", IN, "_", "unary_expr"], "postprocess": (d) => ({
|
|
209
259
|
type: "BinaryExpression",
|
|
210
|
-
operator: "in",
|
|
260
|
+
operator: "in",
|
|
211
261
|
left: d[0],
|
|
212
262
|
right: d[4]
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
|
|
263
|
+
})
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"name": "binary_expr", "symbols": ["binary_expr", "_", NOT, "_", IN, "_", "unary_expr"], "postprocess": (d) => ({
|
|
267
|
+
type: "UnaryExpression",
|
|
216
268
|
operator: "!",
|
|
217
269
|
argument: {
|
|
218
270
|
type: "BinaryExpression",
|
|
@@ -220,9 +272,11 @@ const grammar = {
|
|
|
220
272
|
left: d[0],
|
|
221
273
|
right: d[6]
|
|
222
274
|
}
|
|
223
|
-
})
|
|
275
|
+
})
|
|
276
|
+
},
|
|
224
277
|
{ "name": "binary_expr", "symbols": ["unary_expr"], "postprocess": id },
|
|
225
|
-
{
|
|
278
|
+
{
|
|
279
|
+
"name": "unary_expr", "symbols": [OP, "_", "unary_expr"], "postprocess": (d) => {
|
|
226
280
|
if (d[0].value === "-") {
|
|
227
281
|
return {
|
|
228
282
|
type: "BinaryExpression",
|
|
@@ -232,17 +286,27 @@ const grammar = {
|
|
|
232
286
|
};
|
|
233
287
|
}
|
|
234
288
|
return d[2];
|
|
235
|
-
}
|
|
236
|
-
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"name": "unary_expr", "symbols": [NOT, "_", "unary_expr"], "postprocess": (d) => ({
|
|
237
293
|
type: "UnaryExpression",
|
|
238
294
|
operator: "!",
|
|
239
295
|
argument: d[2]
|
|
240
|
-
})
|
|
296
|
+
})
|
|
297
|
+
},
|
|
241
298
|
{ "name": "unary_expr", "symbols": ["operand"], "postprocess": id },
|
|
242
299
|
{ "name": "operand", "symbols": ["call_expr"], "postprocess": id },
|
|
243
300
|
{ "name": "operand", "symbols": ["list_comp"], "postprocess": id },
|
|
244
301
|
{ "name": "operand", "symbols": ["lambda_expr"], "postprocess": id },
|
|
245
|
-
{
|
|
302
|
+
{
|
|
303
|
+
"name": "lambda_expr", "symbols": [LAMBDA, "_", "func_params", "_", COLON, "_", "expression"], "postprocess": (d) => ({
|
|
304
|
+
type: "LambdaExpression",
|
|
305
|
+
params: d[2],
|
|
306
|
+
body: d[6]
|
|
307
|
+
})
|
|
308
|
+
},
|
|
309
|
+
{ "name": "operand", "symbols": ["identifier_expr"], "postprocess": id },
|
|
246
310
|
{ "name": "operand", "symbols": ["number_literal"], "postprocess": id },
|
|
247
311
|
{ "name": "operand", "symbols": ["string_literal"], "postprocess": id },
|
|
248
312
|
{ "name": "operand", "symbols": ["boolean_literal"], "postprocess": id },
|
|
@@ -250,47 +314,57 @@ const grammar = {
|
|
|
250
314
|
{ "name": "operand", "symbols": ["object_literal"], "postprocess": id },
|
|
251
315
|
{ "name": "operand", "symbols": ["member_expr"], "postprocess": id },
|
|
252
316
|
{ "name": "operand", "symbols": [LPAREN, "_", "expression", "_", RPAREN], "postprocess": (d) => d[2] },
|
|
253
|
-
{
|
|
317
|
+
{
|
|
318
|
+
"name": "member_expr", "symbols": ["operand", "_", DOT, "_", "identifier"], "postprocess": (d) => ({
|
|
254
319
|
type: "MemberExpression",
|
|
255
320
|
object: d[0],
|
|
256
|
-
property: { type: "Identifier", name: d[4]
|
|
321
|
+
property: { type: "Identifier", name: d[4] },
|
|
257
322
|
computed: false
|
|
258
|
-
})
|
|
259
|
-
|
|
323
|
+
})
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"name": "member_expr", "symbols": ["operand", "_", LBRACKET, "_", "expression", "_", RBRACKET], "postprocess": (d) => ({
|
|
260
327
|
type: "MemberExpression",
|
|
261
328
|
object: d[0],
|
|
262
|
-
property: d[4],
|
|
263
|
-
// Wait, my MemberExpression type in AST might expect Identifier for property but for computed it is Expression.
|
|
264
|
-
// Let's check AST type.
|
|
329
|
+
property: d[4],
|
|
265
330
|
computed: true
|
|
266
|
-
})
|
|
267
|
-
|
|
331
|
+
})
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
"name": "call_expr", "symbols": ["operand", "_", LPAREN, "_", "args", "_", RPAREN], "postprocess": (d) => ({
|
|
268
335
|
type: "CallExpression",
|
|
269
336
|
callee: d[0],
|
|
270
337
|
args: d[4]
|
|
271
|
-
})
|
|
272
|
-
|
|
338
|
+
})
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"name": "list_comp", "symbols": [LBRACKET, "_", "expression", "_", FOR, "_", IDENT, "_", IN, "_", "expression", "_", "opt_if_clause", "_", RBRACKET], "postprocess": (d) => ({
|
|
273
342
|
type: "ListComprehension",
|
|
274
343
|
expression: d[2],
|
|
275
344
|
iterator: d[6].value,
|
|
276
345
|
collection: d[10],
|
|
277
346
|
test: d[12]
|
|
278
|
-
})
|
|
347
|
+
})
|
|
348
|
+
},
|
|
279
349
|
{ "name": "opt_if_clause", "symbols": [IF, "_", "expression"], "postprocess": (d) => d[2] },
|
|
280
350
|
{ "name": "opt_if_clause", "symbols": [], "postprocess": () => null },
|
|
281
351
|
{ "name": "args", "symbols": ["expression"], "postprocess": (d) => [d[0]] },
|
|
282
352
|
{ "name": "args", "symbols": ["args", "_", COMMA, "_", "expression"], "postprocess": (d) => [...d[0], d[4]] },
|
|
283
353
|
{ "name": "args", "symbols": [], "postprocess": () => [] },
|
|
284
|
-
{ "name": "
|
|
354
|
+
{ "name": "identifier_expr", "symbols": ["identifier"], "postprocess": (d) => ({ type: "Identifier", name: d[0] }) },
|
|
355
|
+
{ "name": "identifier", "symbols": [IDENT], "postprocess": (d) => d[0].value },
|
|
356
|
+
{ "name": "identifier", "symbols": [RANGE], "postprocess": (d) => d[0].value },
|
|
285
357
|
{ "name": "string_literal", "symbols": [STRING], "postprocess": (d) => ({ type: "StringLiteral", value: d[0].value }) },
|
|
286
358
|
{ "name": "string_literal", "symbols": [FSTRING], "postprocess": (d) => ({ type: "FStringLiteral", value: d[0].value }) },
|
|
287
359
|
{ "name": "number_literal", "symbols": [NUMBER], "postprocess": (d) => ({ type: "NumberLiteral", value: Number(d[0].value) }) },
|
|
288
360
|
{ "name": "_", "symbols": [] },
|
|
289
|
-
{
|
|
361
|
+
{
|
|
362
|
+
"name": "while_stmt", "symbols": [WHILE, "_", "expression", "_", COLON, "_", NEWLINE, "_", INDENT, "_", "statements", "_", DEDENT], "postprocess": (d) => ({
|
|
290
363
|
type: "WhileStatement",
|
|
291
364
|
test: d[2],
|
|
292
365
|
body: d[10].filter((s) => s !== null)
|
|
293
|
-
})
|
|
366
|
+
})
|
|
367
|
+
},
|
|
294
368
|
{ "name": "sws", "symbols": [NEWLINE, "sws"] },
|
|
295
369
|
{ "name": "sws", "symbols": [INDENT, "sws"] },
|
|
296
370
|
{ "name": "sws", "symbols": [DEDENT, "sws"] },
|
|
@@ -305,7 +379,7 @@ const grammar = {
|
|
|
305
379
|
{ "name": "object_literal", "symbols": [LBRACE, "sws", RBRACE], "postprocess": () => ({ type: "ObjectLiteral", properties: [] }) },
|
|
306
380
|
{ "name": "properties", "symbols": ["property"], "postprocess": (d) => [d[0]] },
|
|
307
381
|
{ "name": "properties", "symbols": ["properties", "sws", COMMA, "sws", "property"], "postprocess": (d) => [...d[0], d[4]] },
|
|
308
|
-
{ "name": "property", "symbols": [
|
|
382
|
+
{ "name": "property", "symbols": ["string_literal", "sws", COLON, "sws", "expression"], "postprocess": (d) => ({ key: d[0].value, value: d[4] }) }
|
|
309
383
|
],
|
|
310
384
|
ParserStart: "program",
|
|
311
385
|
};
|
package/dist/parser/parser.js
CHANGED
|
@@ -41,7 +41,7 @@ export function parse(tokens) {
|
|
|
41
41
|
throw new Error("Parser produced no results.");
|
|
42
42
|
}
|
|
43
43
|
if (parser.results.length > 1) {
|
|
44
|
-
|
|
44
|
+
// Ambiguous results, but we take the first one. Silent now.
|
|
45
45
|
}
|
|
46
46
|
return parser.results[0];
|
|
47
47
|
}
|
package/package.json
CHANGED
|
@@ -1,54 +1,86 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "jpsx",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Just Python Script (JPS) - A Python-like language that compiles to JavaScript",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"compiler",
|
|
7
|
-
"python",
|
|
8
|
-
"javascript",
|
|
9
|
-
"jps"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "jpsx",
|
|
3
|
+
"version": "0.1.19",
|
|
4
|
+
"description": "Just Python Script (JPS) - A Python-like language that compiles to JavaScript",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"compiler",
|
|
7
|
+
"python",
|
|
8
|
+
"javascript",
|
|
9
|
+
"jps",
|
|
10
|
+
"jpsx",
|
|
11
|
+
"react",
|
|
12
|
+
"vue",
|
|
13
|
+
"svelte",
|
|
14
|
+
"angular",
|
|
15
|
+
"nextjs",
|
|
16
|
+
"nuxtjs",
|
|
17
|
+
"sveltekit",
|
|
18
|
+
"remix",
|
|
19
|
+
"astro",
|
|
20
|
+
"solidjs",
|
|
21
|
+
"qwik",
|
|
22
|
+
"bun",
|
|
23
|
+
"deno",
|
|
24
|
+
"node",
|
|
25
|
+
"react",
|
|
26
|
+
"vue",
|
|
27
|
+
"svelte",
|
|
28
|
+
"angular",
|
|
29
|
+
"nextjs",
|
|
30
|
+
"nuxtjs",
|
|
31
|
+
"sveltekit",
|
|
32
|
+
"remix",
|
|
33
|
+
"astro",
|
|
34
|
+
"solidjs",
|
|
35
|
+
"qwik",
|
|
36
|
+
"bun",
|
|
37
|
+
"deno",
|
|
38
|
+
"node"
|
|
39
|
+
],
|
|
40
|
+
"author": "Loaii abdalslam",
|
|
41
|
+
"license": "ISC",
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"bin": {
|
|
46
|
+
"jps": "./dist/cli/index.js"
|
|
47
|
+
},
|
|
48
|
+
"main": "./dist/api/index.js",
|
|
49
|
+
"types": "./dist/api/index.d.ts",
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"types": "./dist/api/index.d.ts",
|
|
53
|
+
"import": "./dist/api/index.js",
|
|
54
|
+
"require": "./dist/api/index.cjs"
|
|
55
|
+
},
|
|
56
|
+
"./cli": "./dist/cli/index.js",
|
|
57
|
+
"./runtime": "./dist/runtime/index.js",
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"private": false,
|
|
61
|
+
"workspaces": [
|
|
62
|
+
"packages/*"
|
|
63
|
+
],
|
|
64
|
+
"type": "module",
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -p tsconfig.json",
|
|
67
|
+
"start": "node dist/cli/index.js",
|
|
68
|
+
"test": "jest"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"chalk": "^5.6.2",
|
|
72
|
+
"commander": "^14.0.2",
|
|
73
|
+
"moo": "^0.5.2",
|
|
74
|
+
"nearley": "^2.20.1"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@types/jest": "^29.5.12",
|
|
78
|
+
"@types/moo": "^0.5.10",
|
|
79
|
+
"@types/nearley": "^2.11.5",
|
|
80
|
+
"@types/node": "^22.19.7",
|
|
81
|
+
"jest": "^29.7.0",
|
|
82
|
+
"ts-jest": "^29.1.2",
|
|
83
|
+
"ts-node": "^10.9.2",
|
|
84
|
+
"typescript": "^5.3.3"
|
|
85
|
+
}
|
|
54
86
|
}
|