sardonyx 0.1.85 → 0.2.1
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.
- checksums.yaml +4 -4
- data/bin/sdx +1 -1
- data/lib/sdx/compiler/parser.rb +186 -101
- data/lib/sdx/vm/datatypes.rb +0 -2
- data/lib/sdx/vm/vm.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b18e4b27873132c4a3c503bdd971322516681b0766d2de32c4937bfb502a0e6
|
|
4
|
+
data.tar.gz: 32ab2476bb7f1f98fee2860e721f52e3ef38e8e739652b28a74c68a6889fca47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eaa1ca5fa9355b8a351556aaae7f8b997f5cd0cc22ce66bce333b21f819a9c950c1ac98ebed53d4f19bf522844ed61221b57b04dedf710974fb743b32d28fe0b
|
|
7
|
+
data.tar.gz: 9c950d38de0816ab641f36cdfbf05d958460b97b97b23ba7331c38f836cafef13102bfdf0ca16f5bcfcc89dda4d00923a83bdaffc1cd0e183c2c6da4319aabe5
|
data/bin/sdx
CHANGED
data/lib/sdx/compiler/parser.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Parser
|
|
|
14
14
|
/\A-?[0-9]+\.[0-9]+/ => :float,
|
|
15
15
|
/\A-?[0-9]+/ => :number,
|
|
16
16
|
/\A(\+|-)/ => :l1op,
|
|
17
|
-
/\A(
|
|
17
|
+
/\A(\/|\*|%|\^)/ => :l2op,
|
|
18
18
|
/\A(<|>|<=|>=|==|!=)/ => :l1op,
|
|
19
19
|
/\A(\+|-|\*|\/|%)?=/ => :eq,
|
|
20
20
|
/\A"([^"]|\\")*"/ => :string,
|
|
@@ -125,13 +125,15 @@ module Parser
|
|
|
125
125
|
|
|
126
126
|
def self.parse_parens(tokens)
|
|
127
127
|
if self.expect tokens, :lpar
|
|
128
|
-
tokens = tokens[1
|
|
129
|
-
|
|
128
|
+
tokens = tokens[1..-1]
|
|
129
|
+
res = self.parse_expr tokens
|
|
130
|
+
unless res
|
|
130
131
|
return nil
|
|
131
132
|
end
|
|
132
133
|
e, part = self.parse_expr tokens
|
|
133
|
-
tokens = tokens[part
|
|
134
|
-
|
|
134
|
+
tokens = tokens[part..-1]
|
|
135
|
+
res = self.expect tokens, :rpar
|
|
136
|
+
unless res
|
|
135
137
|
return nil
|
|
136
138
|
end
|
|
137
139
|
return [e, part + 2]
|
|
@@ -144,7 +146,7 @@ module Parser
|
|
|
144
146
|
unless (self.expect tokens, :lbrack)
|
|
145
147
|
return nil
|
|
146
148
|
end
|
|
147
|
-
tokens = tokens[1
|
|
149
|
+
tokens = tokens[1..-1]
|
|
148
150
|
children = []
|
|
149
151
|
total = 1
|
|
150
152
|
while true
|
|
@@ -152,13 +154,14 @@ module Parser
|
|
|
152
154
|
total += 1
|
|
153
155
|
break
|
|
154
156
|
end
|
|
155
|
-
|
|
157
|
+
res = self.parse_expr tokens
|
|
158
|
+
unless res
|
|
156
159
|
return nil
|
|
157
160
|
end
|
|
158
|
-
e, part =
|
|
161
|
+
e, part = res
|
|
159
162
|
children << e
|
|
160
163
|
total += part
|
|
161
|
-
tokens = tokens[part
|
|
164
|
+
tokens = tokens[part..-1]
|
|
162
165
|
if self.expect tokens, :rbrack
|
|
163
166
|
total += 1
|
|
164
167
|
break
|
|
@@ -167,7 +170,7 @@ module Parser
|
|
|
167
170
|
return nil
|
|
168
171
|
end
|
|
169
172
|
total += 1
|
|
170
|
-
tokens = tokens[1
|
|
173
|
+
tokens = tokens[1..-1]
|
|
171
174
|
end
|
|
172
175
|
[ (Node.new :list, "", children), total ]
|
|
173
176
|
end
|
|
@@ -176,7 +179,7 @@ module Parser
|
|
|
176
179
|
unless (self.expect tokens, :lbrace)
|
|
177
180
|
return nil
|
|
178
181
|
end
|
|
179
|
-
tokens = tokens[1
|
|
182
|
+
tokens = tokens[1..-1]
|
|
180
183
|
children = []
|
|
181
184
|
total = 1
|
|
182
185
|
while true
|
|
@@ -188,7 +191,7 @@ module Parser
|
|
|
188
191
|
if e
|
|
189
192
|
children << e[0]
|
|
190
193
|
total += e[1]
|
|
191
|
-
tokens = tokens[e[1]
|
|
194
|
+
tokens = tokens[e[1]..-1]
|
|
192
195
|
else
|
|
193
196
|
puts "Syntax error at token ", tokens[0]
|
|
194
197
|
Kernel.exit 1
|
|
@@ -199,41 +202,52 @@ module Parser
|
|
|
199
202
|
end
|
|
200
203
|
|
|
201
204
|
def self.parse_literal(tokens)
|
|
202
|
-
(self.parse_block tokens) ||
|
|
205
|
+
(self.parse_block tokens) ||
|
|
206
|
+
(self.parse_bool tokens) ||
|
|
207
|
+
(self.parse_float tokens) ||
|
|
208
|
+
(self.parse_name tokens) ||
|
|
209
|
+
(self.parse_number tokens) ||
|
|
210
|
+
(self.parse_list tokens) ||
|
|
211
|
+
(self.parse_string tokens) ||
|
|
212
|
+
(self.parse_nil tokens) ||
|
|
213
|
+
(self.parse_parens tokens)
|
|
203
214
|
end
|
|
204
215
|
|
|
205
216
|
def self.parse_call(tokens)
|
|
206
|
-
|
|
217
|
+
res = (self.parse_literal tokens)
|
|
218
|
+
unless res
|
|
207
219
|
return nil
|
|
208
220
|
end
|
|
209
|
-
callee =
|
|
221
|
+
callee = res
|
|
210
222
|
total = callee[1]
|
|
211
|
-
tokens = tokens[total
|
|
223
|
+
tokens = tokens[total..-1]
|
|
212
224
|
callee = callee[0]
|
|
213
225
|
if self.expect tokens, :lpar
|
|
214
226
|
args = []
|
|
215
|
-
tokens = tokens[1
|
|
227
|
+
tokens = tokens[1..-1]
|
|
216
228
|
total += 1
|
|
217
229
|
if self.expect tokens, :rpar
|
|
218
230
|
return [ (Node.new :call, callee, args), total + 1 ]
|
|
219
231
|
end
|
|
220
232
|
while true
|
|
221
|
-
|
|
233
|
+
res = (self.parse_expr tokens)
|
|
234
|
+
unless res
|
|
222
235
|
return nil
|
|
223
236
|
end
|
|
224
|
-
arg, part =
|
|
237
|
+
arg, part = res
|
|
225
238
|
total += part
|
|
226
|
-
tokens = tokens[part
|
|
239
|
+
tokens = tokens[part..-1]
|
|
227
240
|
args << arg
|
|
228
|
-
total += 1
|
|
229
241
|
if self.expect tokens, :rpar
|
|
230
|
-
tokens = tokens[1
|
|
242
|
+
tokens = tokens[1..-1]
|
|
243
|
+
total += 1
|
|
231
244
|
break
|
|
232
245
|
end
|
|
233
246
|
unless (self.expect tokens, :comma)
|
|
234
247
|
return nil
|
|
235
248
|
end
|
|
236
|
-
|
|
249
|
+
total += 1
|
|
250
|
+
tokens = tokens[1..-1]
|
|
237
251
|
end
|
|
238
252
|
return [ (Node.new :call, callee, args), total ]
|
|
239
253
|
else
|
|
@@ -246,36 +260,38 @@ module Parser
|
|
|
246
260
|
return nil
|
|
247
261
|
end
|
|
248
262
|
total = 1
|
|
249
|
-
tokens = tokens[1
|
|
263
|
+
tokens = tokens[1..-1]
|
|
250
264
|
if self.lookahead tokens, :lpar, 1
|
|
251
|
-
|
|
265
|
+
res = (self.parse_literal tokens)
|
|
266
|
+
unless res
|
|
252
267
|
return nil
|
|
253
268
|
end
|
|
254
|
-
callee =
|
|
269
|
+
callee = res
|
|
255
270
|
callee = callee[0]
|
|
256
271
|
args = []
|
|
257
|
-
tokens = tokens[2
|
|
272
|
+
tokens = tokens[2..-1]
|
|
258
273
|
total += 2
|
|
259
274
|
if self.expect tokens, :rpar
|
|
260
275
|
return [ (Node.new :call, callee, args), total + 1 ]
|
|
261
276
|
end
|
|
262
277
|
while true
|
|
263
|
-
|
|
278
|
+
res = (self.parse_expr tokens)
|
|
279
|
+
unless res
|
|
264
280
|
return nil
|
|
265
281
|
end
|
|
266
|
-
arg, part =
|
|
282
|
+
arg, part = res
|
|
267
283
|
total += part
|
|
268
|
-
tokens = tokens[part
|
|
284
|
+
tokens = tokens[part..-1]
|
|
269
285
|
args << arg
|
|
270
286
|
total += 1
|
|
271
287
|
if self.expect tokens, :rpar
|
|
272
|
-
tokens = tokens[1
|
|
288
|
+
tokens = tokens[1..-1]
|
|
273
289
|
break
|
|
274
290
|
end
|
|
275
291
|
unless (self.expect tokens, :comma)
|
|
276
292
|
return nil
|
|
277
293
|
end
|
|
278
|
-
tokens = tokens[1
|
|
294
|
+
tokens = tokens[1..-1]
|
|
279
295
|
end
|
|
280
296
|
return [ (Node.new :new, callee, args), total ]
|
|
281
297
|
else
|
|
@@ -288,30 +304,33 @@ module Parser
|
|
|
288
304
|
return nil
|
|
289
305
|
end
|
|
290
306
|
total = 1
|
|
291
|
-
tokens = tokens[1
|
|
292
|
-
|
|
307
|
+
tokens = tokens[1..-1]
|
|
308
|
+
res = self.parse_expr tokens
|
|
309
|
+
unless res
|
|
293
310
|
return nil
|
|
294
311
|
end
|
|
295
|
-
e, part =
|
|
312
|
+
e, part = res
|
|
296
313
|
total += part
|
|
297
|
-
tokens = tokens[part
|
|
298
|
-
|
|
314
|
+
tokens = tokens[part..-1]
|
|
315
|
+
res = self.parse_expr tokens
|
|
316
|
+
unless res
|
|
299
317
|
return nil
|
|
300
318
|
end
|
|
301
|
-
block, part =
|
|
319
|
+
block, part = res
|
|
302
320
|
total += part
|
|
303
|
-
tokens = tokens[part
|
|
321
|
+
tokens = tokens[part..-1]
|
|
304
322
|
el = nil
|
|
305
323
|
if self.expect tokens, :else
|
|
306
324
|
total += 1
|
|
307
|
-
tokens = tokens[1
|
|
308
|
-
|
|
325
|
+
tokens = tokens[1..-1]
|
|
326
|
+
res = self.parse_expr tokens
|
|
327
|
+
unless res
|
|
309
328
|
return nil
|
|
310
329
|
end
|
|
311
|
-
el, part =
|
|
330
|
+
el, part = res
|
|
312
331
|
total += part
|
|
313
332
|
end
|
|
314
|
-
|
|
333
|
+
[ (Node.new :if, e, [block, el]), total ]
|
|
315
334
|
end
|
|
316
335
|
|
|
317
336
|
def self.parse_while(tokens)
|
|
@@ -319,19 +338,21 @@ module Parser
|
|
|
319
338
|
return nil
|
|
320
339
|
end
|
|
321
340
|
total = 1
|
|
322
|
-
tokens = tokens[1
|
|
323
|
-
|
|
341
|
+
tokens = tokens[1..-1]
|
|
342
|
+
res = self.parse_expr tokens
|
|
343
|
+
unless res
|
|
324
344
|
return nil
|
|
325
345
|
end
|
|
326
|
-
e, part =
|
|
346
|
+
e, part = res
|
|
327
347
|
total += part
|
|
328
|
-
tokens = tokens[part
|
|
329
|
-
|
|
348
|
+
tokens = tokens[part..-1]
|
|
349
|
+
res = self.parse_expr tokens
|
|
350
|
+
unless res
|
|
330
351
|
return nil
|
|
331
352
|
end
|
|
332
|
-
block, part =
|
|
353
|
+
block, part = res
|
|
333
354
|
total += part
|
|
334
|
-
|
|
355
|
+
[ (Node.new :while, e, [block]), total ]
|
|
335
356
|
end
|
|
336
357
|
|
|
337
358
|
def self.parse_for(tokens)
|
|
@@ -339,69 +360,120 @@ module Parser
|
|
|
339
360
|
return nil
|
|
340
361
|
end
|
|
341
362
|
total = 1
|
|
342
|
-
tokens = tokens[1
|
|
363
|
+
tokens = tokens[1..-1]
|
|
343
364
|
name = nil
|
|
344
365
|
if self.expect tokens, :name and self.lookahead tokens, :in, 1
|
|
345
366
|
name = tokens[0][0]
|
|
346
367
|
total += 2
|
|
347
|
-
tokens = tokens[2
|
|
368
|
+
tokens = tokens[2..-1]
|
|
348
369
|
end
|
|
349
|
-
|
|
370
|
+
res = self.parse_expr tokens
|
|
371
|
+
unless res
|
|
350
372
|
return nil
|
|
351
373
|
end
|
|
352
|
-
e, part =
|
|
374
|
+
e, part = res
|
|
353
375
|
total += part
|
|
354
|
-
tokens = tokens[part
|
|
355
|
-
|
|
376
|
+
tokens = tokens[part..-1]
|
|
377
|
+
res = self.parse_expr tokens
|
|
378
|
+
unless res
|
|
356
379
|
return nil
|
|
357
380
|
end
|
|
358
|
-
block, part =
|
|
381
|
+
block, part = res
|
|
359
382
|
total += part
|
|
360
|
-
|
|
383
|
+
[ (Node.new :for, e, [name, block]), total ]
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
def self.parse_factor(tokens)
|
|
387
|
+
(self.parse_call tokens) ||
|
|
388
|
+
(self.parse_require tokens) ||
|
|
389
|
+
(self.parse_new tokens) ||
|
|
390
|
+
(self.parse_object tokens) ||
|
|
391
|
+
(self.parse_fn tokens) ||
|
|
392
|
+
(self.parse_assign tokens) ||
|
|
393
|
+
(self.parse_literal tokens) ||
|
|
394
|
+
(self.parse_if tokens) ||
|
|
395
|
+
(self.parse_while tokens) ||
|
|
396
|
+
(self.parse_for tokens)
|
|
361
397
|
end
|
|
362
398
|
|
|
363
399
|
def self.parse_term(tokens)
|
|
364
400
|
total = 0
|
|
365
|
-
|
|
401
|
+
res = self.parse_factor tokens
|
|
402
|
+
unless res
|
|
366
403
|
return nil
|
|
367
404
|
end
|
|
368
|
-
lhs, part =
|
|
405
|
+
lhs, part = res
|
|
369
406
|
total += part
|
|
370
|
-
tokens = tokens[part
|
|
407
|
+
tokens = tokens[part..-1]
|
|
371
408
|
unless self.expect tokens, :l2op
|
|
372
409
|
return [lhs, part]
|
|
373
410
|
end
|
|
374
411
|
op = tokens[0][0]
|
|
375
412
|
total += 1
|
|
376
|
-
tokens = tokens[1
|
|
377
|
-
|
|
413
|
+
tokens = tokens[1..-1]
|
|
414
|
+
res = self.parse_factor tokens
|
|
415
|
+
unless res
|
|
378
416
|
return nil
|
|
379
417
|
end
|
|
380
|
-
rhs, part =
|
|
418
|
+
rhs, part = res
|
|
381
419
|
total += part
|
|
382
|
-
|
|
420
|
+
tokens = tokens[part..-1]
|
|
421
|
+
out = (Node.new :op, op, [lhs])
|
|
422
|
+
while self.expect tokens, :l2op
|
|
423
|
+
op = tokens[0][0]
|
|
424
|
+
total += 1
|
|
425
|
+
tokens = tokens[1..-1]
|
|
426
|
+
res = self.parse_term tokens
|
|
427
|
+
unless res
|
|
428
|
+
return nil
|
|
429
|
+
end
|
|
430
|
+
rhs2, part = res
|
|
431
|
+
total += part
|
|
432
|
+
tokens = tokens[part..-1]
|
|
433
|
+
rhs = Node.new :op, op, [rhs, rhs2]
|
|
434
|
+
end
|
|
435
|
+
out.children << rhs
|
|
436
|
+
[out, total]
|
|
383
437
|
end
|
|
384
438
|
|
|
385
439
|
def self.parse_op(tokens)
|
|
386
440
|
total = 0
|
|
387
|
-
|
|
441
|
+
res = self.parse_term tokens
|
|
442
|
+
unless res
|
|
388
443
|
return nil
|
|
389
444
|
end
|
|
390
|
-
lhs, part =
|
|
445
|
+
lhs, part = res
|
|
391
446
|
total += part
|
|
392
|
-
tokens = tokens[part
|
|
447
|
+
tokens = tokens[part..-1]
|
|
393
448
|
unless self.expect tokens, :l1op
|
|
394
449
|
return [lhs, part]
|
|
395
450
|
end
|
|
396
451
|
op = tokens[0][0]
|
|
397
452
|
total += 1
|
|
398
|
-
tokens = tokens[1
|
|
399
|
-
|
|
453
|
+
tokens = tokens[1..-1]
|
|
454
|
+
res = self.parse_term tokens
|
|
455
|
+
unless res
|
|
400
456
|
return nil
|
|
401
457
|
end
|
|
402
|
-
rhs, part =
|
|
458
|
+
rhs, part = res
|
|
403
459
|
total += part
|
|
404
|
-
|
|
460
|
+
tokens = tokens[part..-1]
|
|
461
|
+
out = (Node.new :op, op, [lhs])
|
|
462
|
+
while self.expect tokens, :l1op
|
|
463
|
+
op = tokens[0][0]
|
|
464
|
+
total += 1
|
|
465
|
+
tokens = tokens[1..-1]
|
|
466
|
+
res = self.parse_term tokens
|
|
467
|
+
unless res
|
|
468
|
+
return nil
|
|
469
|
+
end
|
|
470
|
+
rhs2, part = res
|
|
471
|
+
total += part
|
|
472
|
+
tokens = tokens[part..-1]
|
|
473
|
+
rhs = Node.new :op, op, [rhs, rhs2]
|
|
474
|
+
end
|
|
475
|
+
out.children << rhs
|
|
476
|
+
[out, total]
|
|
405
477
|
end
|
|
406
478
|
|
|
407
479
|
def self.parse_assign(tokens)
|
|
@@ -411,19 +483,20 @@ module Parser
|
|
|
411
483
|
end
|
|
412
484
|
name = tokens[0][0]
|
|
413
485
|
total += 1
|
|
414
|
-
tokens = tokens[1
|
|
486
|
+
tokens = tokens[1..-1]
|
|
415
487
|
unless self.expect tokens, :eq
|
|
416
488
|
return nil
|
|
417
489
|
end
|
|
418
490
|
eq = tokens[0][0]
|
|
419
491
|
total += 1
|
|
420
|
-
tokens = tokens[1
|
|
421
|
-
|
|
492
|
+
tokens = tokens[1..-1]
|
|
493
|
+
res = self.parse_expr tokens
|
|
494
|
+
unless res
|
|
422
495
|
return nil
|
|
423
496
|
end
|
|
424
|
-
rhs, part =
|
|
497
|
+
rhs, part = res
|
|
425
498
|
total += part
|
|
426
|
-
|
|
499
|
+
[ (Node.new :assign, eq, [name, rhs]), total]
|
|
427
500
|
end
|
|
428
501
|
|
|
429
502
|
def self.parse_fn(tokens)
|
|
@@ -431,23 +504,23 @@ module Parser
|
|
|
431
504
|
return nil
|
|
432
505
|
end
|
|
433
506
|
total = 1
|
|
434
|
-
tokens = tokens[1
|
|
507
|
+
tokens = tokens[1..-1]
|
|
435
508
|
unless self.expect tokens, :name
|
|
436
509
|
return nil
|
|
437
510
|
end
|
|
438
511
|
name = tokens[0][0]
|
|
439
512
|
total += 1
|
|
440
|
-
tokens = tokens[1
|
|
513
|
+
tokens = tokens[1..-1]
|
|
441
514
|
unless self.expect tokens, :lpar
|
|
442
515
|
return nil
|
|
443
516
|
end
|
|
444
517
|
total += 1
|
|
445
|
-
tokens = tokens[1
|
|
518
|
+
tokens = tokens[1..-1]
|
|
446
519
|
args = []
|
|
447
520
|
while true
|
|
448
521
|
if self.expect tokens, :rpar
|
|
449
522
|
total += 1
|
|
450
|
-
tokens = tokens[1
|
|
523
|
+
tokens = tokens[1..-1]
|
|
451
524
|
break
|
|
452
525
|
end
|
|
453
526
|
unless self.expect tokens, :name
|
|
@@ -455,24 +528,25 @@ module Parser
|
|
|
455
528
|
end
|
|
456
529
|
args << tokens[0][0]
|
|
457
530
|
total += 1
|
|
458
|
-
tokens = tokens[1
|
|
531
|
+
tokens = tokens[1..-1]
|
|
459
532
|
if self.expect tokens, :rpar
|
|
460
533
|
total += 1
|
|
461
|
-
tokens = tokens[1
|
|
534
|
+
tokens = tokens[1..-1]
|
|
462
535
|
break
|
|
463
536
|
end
|
|
464
537
|
unless self.expect tokens, :comma
|
|
465
538
|
return nil
|
|
466
539
|
end
|
|
467
540
|
total += 1
|
|
468
|
-
tokens = tokens[1
|
|
541
|
+
tokens = tokens[1..-1]
|
|
469
542
|
end
|
|
470
|
-
|
|
543
|
+
res = self.parse_expr tokens
|
|
544
|
+
unless res
|
|
471
545
|
return nil
|
|
472
546
|
end
|
|
473
|
-
body, part =
|
|
547
|
+
body, part = res
|
|
474
548
|
total += part
|
|
475
|
-
|
|
549
|
+
[ (Node.new :fn, name, [args, body]), total ]
|
|
476
550
|
end
|
|
477
551
|
|
|
478
552
|
def self.parse_object(tokens)
|
|
@@ -480,21 +554,21 @@ module Parser
|
|
|
480
554
|
return nil
|
|
481
555
|
end
|
|
482
556
|
total = 1
|
|
483
|
-
tokens = tokens[1
|
|
557
|
+
tokens = tokens[1..-1]
|
|
484
558
|
unless self.expect tokens, :name
|
|
485
559
|
return nil
|
|
486
560
|
end
|
|
487
561
|
name = tokens[0][0]
|
|
488
562
|
total += 1
|
|
489
|
-
tokens = tokens[1
|
|
563
|
+
tokens = tokens[1..-1]
|
|
490
564
|
args = []
|
|
491
565
|
if self.expect tokens, :lpar
|
|
492
566
|
total += 1
|
|
493
|
-
tokens = tokens[1
|
|
567
|
+
tokens = tokens[1..-1]
|
|
494
568
|
while true
|
|
495
569
|
if self.expect tokens, :rpar
|
|
496
570
|
total += 1
|
|
497
|
-
tokens = tokens[1
|
|
571
|
+
tokens = tokens[1..-1]
|
|
498
572
|
break
|
|
499
573
|
end
|
|
500
574
|
unless self.expect tokens, :name
|
|
@@ -502,40 +576,51 @@ module Parser
|
|
|
502
576
|
end
|
|
503
577
|
args << tokens[0][0]
|
|
504
578
|
total += 1
|
|
505
|
-
tokens = tokens[1
|
|
579
|
+
tokens = tokens[1..-1]
|
|
506
580
|
if self.expect tokens, :rpar
|
|
507
581
|
total += 1
|
|
508
|
-
tokens = tokens[1
|
|
582
|
+
tokens = tokens[1..-1]
|
|
509
583
|
break
|
|
510
584
|
end
|
|
511
585
|
unless self.expect tokens, :comma
|
|
512
586
|
return nil
|
|
513
587
|
end
|
|
514
588
|
total += 1
|
|
515
|
-
tokens = tokens[1
|
|
589
|
+
tokens = tokens[1..-1]
|
|
516
590
|
end
|
|
517
591
|
end
|
|
518
|
-
|
|
592
|
+
res = self.parse_expr tokens
|
|
593
|
+
unless res
|
|
519
594
|
return nil
|
|
520
595
|
end
|
|
521
|
-
body, part =
|
|
596
|
+
body, part = res
|
|
522
597
|
total += part
|
|
523
|
-
|
|
598
|
+
[ (Node.new :object, name, [args, body]), total ]
|
|
524
599
|
end
|
|
525
600
|
|
|
526
601
|
def self.parse_require(tokens)
|
|
527
602
|
unless self.expect tokens, :require
|
|
528
603
|
return nil
|
|
529
604
|
end
|
|
530
|
-
tokens = tokens[1
|
|
605
|
+
tokens = tokens[1..-1]
|
|
531
606
|
unless self.expect tokens, :string
|
|
532
607
|
return nil
|
|
533
608
|
end
|
|
534
|
-
|
|
609
|
+
[ (Node.new :require, tokens[0][0][1..-2], []), 2 ]
|
|
535
610
|
end
|
|
536
611
|
|
|
537
612
|
def self.parse_expr(tokens)
|
|
538
|
-
(self.
|
|
613
|
+
(self.parse_op tokens) ||
|
|
614
|
+
(self.parse_call tokens) ||
|
|
615
|
+
(self.parse_require tokens) ||
|
|
616
|
+
(self.parse_new tokens) ||
|
|
617
|
+
(self.parse_object tokens) ||
|
|
618
|
+
(self.parse_fn tokens) ||
|
|
619
|
+
(self.parse_assign tokens) ||
|
|
620
|
+
(self.parse_literal tokens) ||
|
|
621
|
+
(self.parse_if tokens) ||
|
|
622
|
+
(self.parse_while tokens) ||
|
|
623
|
+
(self.parse_for tokens)
|
|
539
624
|
end
|
|
540
625
|
|
|
541
626
|
def self.parse(tokens, path)
|
|
@@ -562,7 +647,7 @@ module Parser
|
|
|
562
647
|
else
|
|
563
648
|
parsed << e[0]
|
|
564
649
|
end
|
|
565
|
-
tokens = tokens[e[1]
|
|
650
|
+
tokens = tokens[e[1]..-1]
|
|
566
651
|
else
|
|
567
652
|
puts "Syntax error at token ", tokens[0][1]
|
|
568
653
|
Kernel.exit 1
|
data/lib/sdx/vm/datatypes.rb
CHANGED
data/lib/sdx/vm/vm.rb
CHANGED