depager 0.2.3 → 0.3.0.b20160729
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.en +4 -19
- data/README.ja +42 -79
- data/bin/depager +42 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +49 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +10 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/extension/calc.simple_action.dr +33 -0
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +44 -0
- data/examples/pl0d/pl0ds.dr +337 -334
- data/examples/pl0d/test.pl0ds +33 -33
- data/examples/rie_calc/calc.rie.dr +57 -0
- data/examples/rie_calc/test.calc +4 -0
- data/examples/rie_dcuse/dcuse.rie.dr +71 -0
- data/examples/rie_dcuse/test.dcuse +1 -0
- data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
- data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
- data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
- data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
- data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
- data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
- data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
- data/examples/rie_pl0/pl0.rie.dr +450 -0
- data/examples/rie_pl0/test.pl0 +10 -0
- data/examples/sample_calc/calc.action.dr +33 -33
- data/examples/sample_calc/calc.ast.action.dr +65 -66
- data/examples/sample_calc/calc.ast.dr +55 -55
- data/examples/sample_calc/calc.cst.dr +45 -45
- data/examples/sample_calc/calc.dr +43 -43
- data/examples/sample_calc/calc.lex.dr +29 -29
- data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
- data/examples/slex_test/divreg.slex.dr +29 -29
- data/examples/slex_test/ljoin.slex.dr +36 -36
- data/examples/slex_test/test.divreg +1 -1
- data/examples/slex_test/test.ljoin +3 -3
- data/lib/depager.rb +582 -670
- data/lib/depager/grammar.rb +256 -291
- data/lib/depager/lr.rb +574 -579
- data/lib/depager/parser.rb +282 -277
- data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
- data/lib/depager/ruby/plugins/action.rb +53 -43
- data/lib/depager/ruby/plugins/ast.dr +364 -269
- data/lib/depager/ruby/plugins/ast.rb +1367 -1308
- data/lib/depager/ruby/plugins/cst.dr +172 -180
- data/lib/depager/ruby/plugins/cst.rb +587 -626
- data/lib/depager/ruby/plugins/lex.dr +85 -89
- data/lib/depager/ruby/plugins/lex.rb +310 -336
- data/lib/depager/ruby/plugins/rie.dr +723 -0
- data/lib/depager/ruby/plugins/rie.rb +1653 -0
- data/lib/depager/ruby/plugins/slex.dr +202 -200
- data/lib/depager/ruby/plugins/slex.rb +780 -817
- data/lib/depager/ruby/plugins/srp.rb +56 -51
- data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
- data/lib/depager/utils.rb +148 -318
- data/lib/depager/version.rb +4 -3
- metadata +52 -60
- data/ChangeLog +0 -16
- data/data/depager/pre-setup.rb +0 -3
- data/examples/c89/c89.tab.rb +0 -7127
- data/examples/pl0d/pl0ds.tab.rb +0 -2698
- data/examples/sample_calc/calc.action.tab.rb +0 -457
- data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
- data/examples/sample_calc/calc.ast.tab.rb +0 -665
- data/examples/sample_calc/calc.astdf.dr +0 -54
- data/examples/sample_calc/calc.astdf.tab.rb +0 -672
- data/examples/sample_calc/calc.atree.tab.rb +0 -451
- data/examples/sample_calc/calc.cst.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.dr +0 -33
- data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
- data/examples/sample_calc/calc.tab.rb +0 -365
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
- data/examples/slex_test/divreg.slex.tab.rb +0 -303
- data/examples/slex_test/ljoin.slex.tab.rb +0 -370
- data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
- data/lib/depager/ruby/plugins/astdf.rb +0 -6
- data/lib/depager/ruby/plugins/atree.dr +0 -55
- data/lib/depager/ruby/plugins/atree.rb +0 -347
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
@@ -1,1308 +1,1367 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
###
|
4
|
-
###
|
5
|
-
|
6
|
-
require 'depager/parser.rb'
|
7
|
-
|
8
|
-
|
9
|
-
module
|
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
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
###
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
end
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
end
|
622
|
-
|
623
|
-
|
624
|
-
module_eval <<-'
|
625
|
-
def
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
end
|
630
|
-
|
631
|
-
|
632
|
-
module_eval <<-'
|
633
|
-
def
|
634
|
-
_,
|
635
|
-
|
636
|
-
|
637
|
-
end
|
638
|
-
|
639
|
-
|
640
|
-
module_eval <<-'
|
641
|
-
def
|
642
|
-
|
643
|
-
[
|
644
|
-
|
645
|
-
end
|
646
|
-
|
647
|
-
|
648
|
-
module_eval <<-'
|
649
|
-
def
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
end
|
654
|
-
|
655
|
-
|
656
|
-
module_eval <<-'
|
657
|
-
def
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
end
|
678
|
-
|
679
|
-
|
680
|
-
module_eval <<-'
|
681
|
-
def
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
end
|
686
|
-
|
687
|
-
|
688
|
-
module_eval <<-'
|
689
|
-
def
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
###
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
when /\A[
|
1007
|
-
@
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
when /\A
|
1012
|
-
@
|
1013
|
-
yield
|
1014
|
-
|
1015
|
-
|
1016
|
-
when /\A
|
1017
|
-
@
|
1018
|
-
yield token(:
|
1019
|
-
|
1020
|
-
|
1021
|
-
when /\A
|
1022
|
-
@
|
1023
|
-
yield token(
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
end
|
1220
|
-
|
1221
|
-
|
1222
|
-
module_eval <<-'
|
1223
|
-
def
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
end
|
1228
|
-
|
1229
|
-
|
1230
|
-
module_eval <<-'
|
1231
|
-
def
|
1232
|
-
|
1233
|
-
"
|
1234
|
-
|
1235
|
-
end
|
1236
|
-
|
1237
|
-
|
1238
|
-
module_eval <<-'
|
1239
|
-
def
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
def
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
def
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### Depager::ASTBuilderExtension - Depager Extension (master)
|
5
|
+
###
|
6
|
+
require 'depager/parser.rb'
|
7
|
+
|
8
|
+
|
9
|
+
module Depager ; end
|
10
|
+
|
11
|
+
class Depager::ASTBuilderExtension < Depager::Extension
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@master = self
|
15
|
+
@slaves = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def extension_registered g_parser
|
19
|
+
super g_parser
|
20
|
+
|
21
|
+
@slaves[0] = Depager::ASTBuilderExtension::Slave_pre_rule_list::Parser.new(g_parser, self)
|
22
|
+
g_parser.hooks[:pre_rule_list].push [@slaves[0], :do_parse]
|
23
|
+
@slaves[1] = Depager::ASTBuilderExtension::Slave_post_rhs::Parser.new(g_parser, self)
|
24
|
+
g_parser.hooks[:post_rhs].push [@slaves[1], :do_parse]
|
25
|
+
end
|
26
|
+
|
27
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 8
|
28
|
+
attr_accessor :action_code, :on_reduce, :visitors
|
29
|
+
def init_extension
|
30
|
+
@visitors = Hash.new{|hash, key| hash[key] = []}
|
31
|
+
@action_code = ''
|
32
|
+
@on_reduce = []
|
33
|
+
@output_file_name = nil
|
34
|
+
end
|
35
|
+
def term_extension
|
36
|
+
g_parser.outer_code <<
|
37
|
+
generate_action_decorator_code(@on_reduce, @action_code)
|
38
|
+
end
|
39
|
+
|
40
|
+
def modify_action_code code, nodes=[]
|
41
|
+
code = code.gsub(/\$\.([a-z_])/, 'node.\1')
|
42
|
+
code << %{
|
43
|
+
rescue
|
44
|
+
warn "raise at src:\#{node.lineno}/\#{node.class.name}"
|
45
|
+
raise
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def gen_accept_code sym
|
50
|
+
return ''
|
51
|
+
end
|
52
|
+
|
53
|
+
def node_name name
|
54
|
+
name = name == '@List' ? "NodeList" : "Node_#{name}"
|
55
|
+
"#{target_namespace}::#{name}"
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :output_file_name
|
59
|
+
def output_file_name= name
|
60
|
+
name = name.match(/'(.+)'/) ? $1 : name
|
61
|
+
@output_file_name = name
|
62
|
+
end
|
63
|
+
|
64
|
+
DEPAGER_EXPANDED_CODE
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
###
|
69
|
+
### Depager::ASTBuilderExtension::Slave_pre_rule_list - Part of Depager Extension (slave)
|
70
|
+
###
|
71
|
+
|
72
|
+
module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
73
|
+
class Parser < Depager::LALR::Basis #:nodoc:all
|
74
|
+
include Depager::Utils::ExtensionSlaveMethods
|
75
|
+
|
76
|
+
|
77
|
+
### Reduce Table
|
78
|
+
reduce_table = [
|
79
|
+
[ -1, 1 ],
|
80
|
+
[ 0, 3 ],
|
81
|
+
[ 1, 0 ],
|
82
|
+
[ 1, 3 ],
|
83
|
+
[ 2, 0 ],
|
84
|
+
[ 2, 2 ],
|
85
|
+
[ 3, 1 ],
|
86
|
+
[ 3, 2 ],
|
87
|
+
[ 6, 3 ],
|
88
|
+
[ 7, 3 ],
|
89
|
+
[ 7, 4 ],
|
90
|
+
[ 4, 0 ],
|
91
|
+
[ 4, 2 ],
|
92
|
+
[ 4, 3 ],
|
93
|
+
[ 8, 1 ],
|
94
|
+
[ 8, 3 ],
|
95
|
+
[ 10, 1 ],
|
96
|
+
[ 10, 2 ],
|
97
|
+
[ 9, 1 ],
|
98
|
+
[ 9, 3 ],
|
99
|
+
[ 5, 0 ],
|
100
|
+
[ 5, 1 ],
|
101
|
+
[ 5, 1 ],
|
102
|
+
[ 11, 1 ],
|
103
|
+
[ 11, 2 ],
|
104
|
+
[ 12, 4 ],
|
105
|
+
]
|
106
|
+
### Term to Int
|
107
|
+
term_to_int = {
|
108
|
+
nil => 0,
|
109
|
+
false => 1,
|
110
|
+
:NODE => 2,
|
111
|
+
:ACTION => 3,
|
112
|
+
:VISITOR => 4,
|
113
|
+
:ID => 5,
|
114
|
+
"(" => 6,
|
115
|
+
")" => 7,
|
116
|
+
"[" => 8,
|
117
|
+
"]" => 9,
|
118
|
+
"," => 10,
|
119
|
+
"-" => 11,
|
120
|
+
"<" => 12,
|
121
|
+
">" => 13,
|
122
|
+
}
|
123
|
+
### Int to Term
|
124
|
+
int_to_term = [
|
125
|
+
nil,
|
126
|
+
false,
|
127
|
+
:NODE,
|
128
|
+
:ACTION,
|
129
|
+
:VISITOR,
|
130
|
+
:ID,
|
131
|
+
"(",
|
132
|
+
")",
|
133
|
+
"[",
|
134
|
+
"]",
|
135
|
+
",",
|
136
|
+
"-",
|
137
|
+
"<",
|
138
|
+
">",
|
139
|
+
]
|
140
|
+
### Action Table
|
141
|
+
action_table = [
|
142
|
+
[ nil, nil, 3, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
143
|
+
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
144
|
+
[ nil, nil, nil, nil, 5, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
145
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, 7, nil, nil, nil, nil, nil, ],
|
146
|
+
[ nil, nil, nil, nil, nil, 11, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
147
|
+
[ nil, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, nil, 16, nil, ],
|
148
|
+
[ nil, nil, nil, 17, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
149
|
+
[ nil, nil, nil, nil, nil, 20, nil, nil, nil, 18, nil, nil, nil, nil, ],
|
150
|
+
[ nil, nil, nil, nil, nil, 11, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
151
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
152
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, 7, nil, nil, nil, nil, nil, ],
|
153
|
+
[ nil, nil, nil, nil, nil, nil, 23, nil, nil, nil, nil, nil, nil, nil, ],
|
154
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
155
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
156
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 16, nil, ],
|
157
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
158
|
+
[ nil, nil, nil, nil, nil, 25, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
159
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
160
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
161
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, 26, 27, nil, nil, nil, ],
|
162
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
163
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
164
|
+
[ nil, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, nil, 16, nil, ],
|
165
|
+
[ nil, nil, nil, nil, nil, 32, nil, 29, nil, nil, nil, 33, nil, nil, ],
|
166
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
167
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 34, ],
|
168
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
169
|
+
[ nil, nil, nil, nil, nil, 35, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
170
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
171
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
172
|
+
[ nil, nil, nil, nil, nil, nil, nil, 36, nil, nil, 37, nil, nil, nil, ],
|
173
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
174
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
175
|
+
[ nil, nil, nil, nil, nil, 38, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
176
|
+
[ nil, nil, nil, 39, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
177
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
178
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
179
|
+
[ nil, nil, nil, nil, nil, 32, nil, nil, nil, nil, nil, 33, nil, nil, ],
|
180
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
181
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
182
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
183
|
+
]
|
184
|
+
### Default Reduce Table
|
185
|
+
defred_table = [
|
186
|
+
-2,
|
187
|
+
nil,
|
188
|
+
-4,
|
189
|
+
-11,
|
190
|
+
nil,
|
191
|
+
-20,
|
192
|
+
nil,
|
193
|
+
nil,
|
194
|
+
-1,
|
195
|
+
-6,
|
196
|
+
-11,
|
197
|
+
nil,
|
198
|
+
-5,
|
199
|
+
-21,
|
200
|
+
-22,
|
201
|
+
-23,
|
202
|
+
nil,
|
203
|
+
-3,
|
204
|
+
-12,
|
205
|
+
nil,
|
206
|
+
-18,
|
207
|
+
-7,
|
208
|
+
-20,
|
209
|
+
nil,
|
210
|
+
-24,
|
211
|
+
nil,
|
212
|
+
-13,
|
213
|
+
nil,
|
214
|
+
-8,
|
215
|
+
-9,
|
216
|
+
nil,
|
217
|
+
-14,
|
218
|
+
-16,
|
219
|
+
nil,
|
220
|
+
nil,
|
221
|
+
-19,
|
222
|
+
-10,
|
223
|
+
nil,
|
224
|
+
-17,
|
225
|
+
-25,
|
226
|
+
-15,
|
227
|
+
]
|
228
|
+
defred_after_shift_table = [
|
229
|
+
nil,
|
230
|
+
nil,
|
231
|
+
nil,
|
232
|
+
nil,
|
233
|
+
nil,
|
234
|
+
nil,
|
235
|
+
nil,
|
236
|
+
nil,
|
237
|
+
nil,
|
238
|
+
-6,
|
239
|
+
nil,
|
240
|
+
nil,
|
241
|
+
-5,
|
242
|
+
-21,
|
243
|
+
nil,
|
244
|
+
-23,
|
245
|
+
nil,
|
246
|
+
-3,
|
247
|
+
-12,
|
248
|
+
nil,
|
249
|
+
-18,
|
250
|
+
-7,
|
251
|
+
nil,
|
252
|
+
nil,
|
253
|
+
-24,
|
254
|
+
nil,
|
255
|
+
-13,
|
256
|
+
nil,
|
257
|
+
-8,
|
258
|
+
-9,
|
259
|
+
nil,
|
260
|
+
-14,
|
261
|
+
-16,
|
262
|
+
nil,
|
263
|
+
nil,
|
264
|
+
-19,
|
265
|
+
-10,
|
266
|
+
nil,
|
267
|
+
-17,
|
268
|
+
-25,
|
269
|
+
-15,
|
270
|
+
]
|
271
|
+
### Nonterm to Int
|
272
|
+
nonterm_to_int = {
|
273
|
+
:start => 0,
|
274
|
+
:opt_defnode => 1,
|
275
|
+
:opt_defvis => 2,
|
276
|
+
:defnode_list => 3,
|
277
|
+
:opt_attr => 4,
|
278
|
+
:opt_action => 5,
|
279
|
+
:defnode => 6,
|
280
|
+
:defnode_header => 7,
|
281
|
+
:fact_list => 8,
|
282
|
+
:id_list => 9,
|
283
|
+
:fact => 10,
|
284
|
+
:pass_action_list => 11,
|
285
|
+
:pass_action => 12,
|
286
|
+
}
|
287
|
+
### Int to Nonterm
|
288
|
+
int_to_nonterm = [
|
289
|
+
:start,
|
290
|
+
:opt_defnode,
|
291
|
+
:opt_defvis,
|
292
|
+
:defnode_list,
|
293
|
+
:opt_attr,
|
294
|
+
:opt_action,
|
295
|
+
:defnode,
|
296
|
+
:defnode_header,
|
297
|
+
:fact_list,
|
298
|
+
:id_list,
|
299
|
+
:fact,
|
300
|
+
:pass_action_list,
|
301
|
+
:pass_action,
|
302
|
+
]
|
303
|
+
### Goto Table
|
304
|
+
goto_table = [
|
305
|
+
[ 1, 2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
306
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
307
|
+
[ nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
308
|
+
[ nil, nil, nil, nil, 6, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
309
|
+
[ nil, nil, nil, 8, nil, nil, 9, 10, nil, nil, nil, nil, nil, ],
|
310
|
+
[ nil, nil, nil, nil, nil, 12, nil, nil, nil, nil, nil, 14, 15, ],
|
311
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
312
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, 19, nil, nil, nil, ],
|
313
|
+
[ nil, nil, nil, nil, nil, nil, 21, 10, nil, nil, nil, nil, nil, ],
|
314
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
315
|
+
[ nil, nil, nil, nil, 22, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
316
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
317
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
318
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
319
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 24, ],
|
320
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
321
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
322
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
323
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
324
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
325
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
326
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
327
|
+
[ nil, nil, nil, nil, nil, 28, nil, nil, nil, nil, nil, 14, 15, ],
|
328
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, 30, nil, 31, nil, nil, ],
|
329
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
330
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
331
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
332
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
333
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
334
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
335
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
336
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
337
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
338
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
339
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
340
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
341
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
342
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 40, nil, nil, ],
|
343
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
344
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
345
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
346
|
+
]
|
347
|
+
|
348
|
+
Tables = [ reduce_table, action_table,
|
349
|
+
defred_table, defred_after_shift_table, goto_table,
|
350
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
351
|
+
|
352
|
+
def initialize g_parser, master
|
353
|
+
super()
|
354
|
+
@g_parser = g_parser
|
355
|
+
@d_parser = g_parser.d_parser
|
356
|
+
@master = master
|
357
|
+
@decorated = Action.new(self)
|
358
|
+
end
|
359
|
+
|
360
|
+
|
361
|
+
def do_parse?
|
362
|
+
if @line.match(/^\s*%AST\{\s*\Z/)
|
363
|
+
@line = $'
|
364
|
+
true
|
365
|
+
else
|
366
|
+
false
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
|
371
|
+
def banner
|
372
|
+
"%AST{ ... } / Depager::ASTBuilderExtension"
|
373
|
+
end
|
374
|
+
|
375
|
+
|
376
|
+
def lex
|
377
|
+
begin
|
378
|
+
until @line.empty?
|
379
|
+
case @line
|
380
|
+
|
381
|
+
when /\A\s+/, /\A#.*/
|
382
|
+
@line = $'
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
when /\A%\}\s*\Z/
|
387
|
+
@line = $'
|
388
|
+
@line = $'; yield nil,nil
|
389
|
+
|
390
|
+
|
391
|
+
when /\ANode/
|
392
|
+
@line = $'
|
393
|
+
yield token(:NODE, $&)
|
394
|
+
|
395
|
+
|
396
|
+
when /\AVisitor/
|
397
|
+
@line = $'
|
398
|
+
yield token(:VISITOR, $&)
|
399
|
+
|
400
|
+
|
401
|
+
when /\A[a-zA-Z][a-zA-Z0-9_]*/
|
402
|
+
@line = $'
|
403
|
+
yield token(:ID, $&)
|
404
|
+
|
405
|
+
|
406
|
+
when /\A\{/
|
407
|
+
#
|
408
|
+
lineno = file.lineno; yield token(:ACTION, parse_block, lineno)
|
409
|
+
|
410
|
+
|
411
|
+
when /\A./
|
412
|
+
@line = $'
|
413
|
+
yield token($&, $&)
|
414
|
+
|
415
|
+
|
416
|
+
else
|
417
|
+
raise RuntimeError, "must not happen #{@line}"
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end while @original_line = @line = file.gets
|
421
|
+
yield nil, nil
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
|
428
|
+
class Depager::ASTBuilderExtension::Slave_pre_rule_list::Action < Depager::LALR::Action #:nodoc:all
|
429
|
+
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
430
|
+
|
431
|
+
on_reduce = [
|
432
|
+
nil,
|
433
|
+
:_act_1,
|
434
|
+
:_act_2,
|
435
|
+
:_act_3,
|
436
|
+
:_act_4,
|
437
|
+
:_act_5,
|
438
|
+
:_act_6,
|
439
|
+
:_act_7,
|
440
|
+
:_act_8,
|
441
|
+
:_act_9,
|
442
|
+
:_act_10,
|
443
|
+
:_act_11,
|
444
|
+
:_act_12,
|
445
|
+
:_act_13,
|
446
|
+
:_act_14,
|
447
|
+
:_act_15,
|
448
|
+
:_act_16,
|
449
|
+
:_act_17,
|
450
|
+
:_act_18,
|
451
|
+
:_act_19,
|
452
|
+
:_act_20,
|
453
|
+
:_act_21,
|
454
|
+
:_act_22,
|
455
|
+
:_act_23,
|
456
|
+
:_act_24,
|
457
|
+
:_act_25,
|
458
|
+
|
459
|
+
]
|
460
|
+
Tables = [ on_reduce ]
|
461
|
+
|
462
|
+
|
463
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 59
|
464
|
+
def _act_1 val
|
465
|
+
_opt_defnode, _opt_defvis, _defnode_list, = *val
|
466
|
+
|
467
|
+
code = "module #{target_namespace}\n"
|
468
|
+
code << _opt_defnode
|
469
|
+
code << val[2]
|
470
|
+
master.visitors.each do |name, body|
|
471
|
+
code << ERB.new(master.class::VISITOR_TEMPLATE, nil, '-').result(binding)
|
472
|
+
end
|
473
|
+
code << "end\n"
|
474
|
+
if master.output_file_name
|
475
|
+
File.open(master.output_file_name, 'w') do |f|
|
476
|
+
f.write code
|
477
|
+
end
|
478
|
+
g_parser.outer_code << %!require '#{master.output_file_name}'\n!
|
479
|
+
else
|
480
|
+
g_parser.outer_code << code
|
481
|
+
end
|
482
|
+
|
483
|
+
end
|
484
|
+
DEPAGER_EXPANDED_CODE
|
485
|
+
|
486
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 78
|
487
|
+
def _act_2 val
|
488
|
+
""
|
489
|
+
|
490
|
+
end
|
491
|
+
DEPAGER_EXPANDED_CODE
|
492
|
+
|
493
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 80
|
494
|
+
def _act_3 val
|
495
|
+
_NODE, _opt_attr, _ACTION, = *val
|
496
|
+
|
497
|
+
ini = %{
|
498
|
+
def initialize
|
499
|
+
#{_ACTION.value}
|
500
|
+
end
|
501
|
+
};#code
|
502
|
+
ERB.new(master.class::BASE_NODE_TEMPLATE, nil, '-').result(binding)
|
503
|
+
|
504
|
+
end
|
505
|
+
DEPAGER_EXPANDED_CODE
|
506
|
+
|
507
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 90
|
508
|
+
def _act_4 val
|
509
|
+
[]
|
510
|
+
|
511
|
+
end
|
512
|
+
DEPAGER_EXPANDED_CODE
|
513
|
+
|
514
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 92
|
515
|
+
def _act_5 val
|
516
|
+
_VISITOR, _opt_action, = *val
|
517
|
+
|
518
|
+
_opt_action[nil] ||= Token.new('', 0)
|
519
|
+
_opt_action.each do |pass, act|
|
520
|
+
master.visitors[pass].unshift(
|
521
|
+
master.expand_inline_code(act.value.to_s, act.lineno))
|
522
|
+
end
|
523
|
+
|
524
|
+
end
|
525
|
+
DEPAGER_EXPANDED_CODE
|
526
|
+
|
527
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 101
|
528
|
+
def _act_6 val
|
529
|
+
_defnode, = *val
|
530
|
+
_defnode
|
531
|
+
|
532
|
+
end
|
533
|
+
DEPAGER_EXPANDED_CODE
|
534
|
+
|
535
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 102
|
536
|
+
def _act_7 val
|
537
|
+
_defnode_list, _defnode, = *val
|
538
|
+
_defnode_list << _defnode
|
539
|
+
|
540
|
+
end
|
541
|
+
DEPAGER_EXPANDED_CODE
|
542
|
+
|
543
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 106
|
544
|
+
def _act_8 val
|
545
|
+
_defnode_header, _opt_attr, _opt_action, = *val
|
546
|
+
|
547
|
+
name, args = _defnode_header
|
548
|
+
nodes, accept, attrs = [], '', _opt_attr
|
549
|
+
args.each do |i|
|
550
|
+
if i =~ /\-(.*)/
|
551
|
+
nodes.push $1
|
552
|
+
attrs.push $1
|
553
|
+
else
|
554
|
+
nodes.push i
|
555
|
+
accept << master.gen_accept_code(i)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
_opt_action[nil] = Token.new('', 0) unless _opt_action[nil]
|
559
|
+
_opt_action.each do |pass, act|
|
560
|
+
vis_code = master.modify_action_code(act.value, nodes - attrs)
|
561
|
+
master.visitors[pass] <<
|
562
|
+
master.expand_inline_code(vis_code, act.lineno, :wrap => "def visit_Node_#{name} node")
|
563
|
+
end
|
564
|
+
ERB.new(master.class::NODE_TEMPLATE, nil, '-').result(binding)
|
565
|
+
|
566
|
+
end
|
567
|
+
DEPAGER_EXPANDED_CODE
|
568
|
+
|
569
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 128
|
570
|
+
def _act_9 val
|
571
|
+
_ID, _, _, = *val
|
572
|
+
[_ID.value, []]
|
573
|
+
|
574
|
+
end
|
575
|
+
DEPAGER_EXPANDED_CODE
|
576
|
+
|
577
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 129
|
578
|
+
def _act_10 val
|
579
|
+
_ID, _, _fact_list, _, = *val
|
580
|
+
[_ID.value, _fact_list]
|
581
|
+
|
582
|
+
end
|
583
|
+
DEPAGER_EXPANDED_CODE
|
584
|
+
|
585
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 132
|
586
|
+
def _act_11 val
|
587
|
+
[]
|
588
|
+
|
589
|
+
end
|
590
|
+
DEPAGER_EXPANDED_CODE
|
591
|
+
|
592
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 133
|
593
|
+
def _act_12 val
|
594
|
+
_, _, = *val
|
595
|
+
[]
|
596
|
+
|
597
|
+
end
|
598
|
+
DEPAGER_EXPANDED_CODE
|
599
|
+
|
600
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 134
|
601
|
+
def _act_13 val
|
602
|
+
_, _id_list, _, = *val
|
603
|
+
_id_list
|
604
|
+
|
605
|
+
end
|
606
|
+
DEPAGER_EXPANDED_CODE
|
607
|
+
|
608
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 137
|
609
|
+
def _act_14 val
|
610
|
+
_fact, = *val
|
611
|
+
[_fact]
|
612
|
+
|
613
|
+
end
|
614
|
+
DEPAGER_EXPANDED_CODE
|
615
|
+
|
616
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 138
|
617
|
+
def _act_15 val
|
618
|
+
_fact_list, _, _fact, = *val
|
619
|
+
_fact_list.push _fact
|
620
|
+
|
621
|
+
end
|
622
|
+
DEPAGER_EXPANDED_CODE
|
623
|
+
|
624
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 141
|
625
|
+
def _act_16 val
|
626
|
+
_ID, = *val
|
627
|
+
_ID.value
|
628
|
+
|
629
|
+
end
|
630
|
+
DEPAGER_EXPANDED_CODE
|
631
|
+
|
632
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 142
|
633
|
+
def _act_17 val
|
634
|
+
_, _ID, = *val
|
635
|
+
'-' + _ID.value
|
636
|
+
|
637
|
+
end
|
638
|
+
DEPAGER_EXPANDED_CODE
|
639
|
+
|
640
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 145
|
641
|
+
def _act_18 val
|
642
|
+
_ID, = *val
|
643
|
+
[ _ID.value ]
|
644
|
+
|
645
|
+
end
|
646
|
+
DEPAGER_EXPANDED_CODE
|
647
|
+
|
648
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 146
|
649
|
+
def _act_19 val
|
650
|
+
_id_list, _, _ID, = *val
|
651
|
+
_id_list.push _ID.value
|
652
|
+
|
653
|
+
end
|
654
|
+
DEPAGER_EXPANDED_CODE
|
655
|
+
|
656
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 149
|
657
|
+
def _act_20 val
|
658
|
+
{nil => Token.new('', 0)}
|
659
|
+
|
660
|
+
end
|
661
|
+
DEPAGER_EXPANDED_CODE
|
662
|
+
|
663
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 150
|
664
|
+
def _act_21 val
|
665
|
+
_ACTION, = *val
|
666
|
+
{nil => _ACTION}
|
667
|
+
|
668
|
+
end
|
669
|
+
DEPAGER_EXPANDED_CODE
|
670
|
+
|
671
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 152
|
672
|
+
def _act_22 val
|
673
|
+
_pass_action_list, = *val
|
674
|
+
|
675
|
+
Hash[ *_pass_action_list.flatten ].merge({nil => Token.new('', 0)})
|
676
|
+
|
677
|
+
end
|
678
|
+
DEPAGER_EXPANDED_CODE
|
679
|
+
|
680
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 157
|
681
|
+
def _act_23 val
|
682
|
+
_pass_action, = *val
|
683
|
+
[ _pass_action ]
|
684
|
+
|
685
|
+
end
|
686
|
+
DEPAGER_EXPANDED_CODE
|
687
|
+
|
688
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 158
|
689
|
+
def _act_24 val
|
690
|
+
_pass_action_list, _pass_action, = *val
|
691
|
+
_pass_action_list << _pass_action
|
692
|
+
|
693
|
+
end
|
694
|
+
DEPAGER_EXPANDED_CODE
|
695
|
+
|
696
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 162
|
697
|
+
def _act_25 val
|
698
|
+
_, _ID, _, _ACTION, = *val
|
699
|
+
[_ID.value, _ACTION]
|
700
|
+
|
701
|
+
end
|
702
|
+
DEPAGER_EXPANDED_CODE
|
703
|
+
|
704
|
+
|
705
|
+
end
|
706
|
+
|
707
|
+
###
|
708
|
+
### Depager::ASTBuilderExtension::Slave_post_rhs - Part of Depager Extension (slave)
|
709
|
+
###
|
710
|
+
|
711
|
+
module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
712
|
+
class Parser < Depager::LALR::Basis #:nodoc:all
|
713
|
+
include Depager::Utils::ExtensionSlaveMethods
|
714
|
+
|
715
|
+
|
716
|
+
### Reduce Table
|
717
|
+
reduce_table = [
|
718
|
+
[ -1, 1 ],
|
719
|
+
[ 0, 1 ],
|
720
|
+
[ 2, 3 ],
|
721
|
+
[ 2, 4 ],
|
722
|
+
[ 3, 1 ],
|
723
|
+
[ 3, 3 ],
|
724
|
+
[ 1, 1 ],
|
725
|
+
[ 1, 1 ],
|
726
|
+
[ 1, 1 ],
|
727
|
+
[ 4, 2 ],
|
728
|
+
[ 4, 1 ],
|
729
|
+
[ 4, 1 ],
|
730
|
+
[ 4, 1 ],
|
731
|
+
[ 4, 1 ],
|
732
|
+
[ 4, 1 ],
|
733
|
+
[ 4, 1 ],
|
734
|
+
[ 6, 0 ],
|
735
|
+
[ 6, 1 ],
|
736
|
+
[ 5, 2 ],
|
737
|
+
[ 5, 3 ],
|
738
|
+
[ 5, 3 ],
|
739
|
+
[ 5, 3 ],
|
740
|
+
]
|
741
|
+
### Term to Int
|
742
|
+
term_to_int = {
|
743
|
+
nil => 0,
|
744
|
+
false => 1,
|
745
|
+
:ID => 2,
|
746
|
+
"(" => 3,
|
747
|
+
")" => 4,
|
748
|
+
"," => 5,
|
749
|
+
:CONST => 6,
|
750
|
+
:SYMBOL => 7,
|
751
|
+
:STR => 8,
|
752
|
+
:NILNODE => 9,
|
753
|
+
:NUMBER => 10,
|
754
|
+
:NIL => 11,
|
755
|
+
:EMBED => 12,
|
756
|
+
"[" => 13,
|
757
|
+
"]" => 14,
|
758
|
+
:LL => 15,
|
759
|
+
"@" => 16,
|
760
|
+
}
|
761
|
+
### Int to Term
|
762
|
+
int_to_term = [
|
763
|
+
nil,
|
764
|
+
false,
|
765
|
+
:ID,
|
766
|
+
"(",
|
767
|
+
")",
|
768
|
+
",",
|
769
|
+
:CONST,
|
770
|
+
:SYMBOL,
|
771
|
+
:STR,
|
772
|
+
:NILNODE,
|
773
|
+
:NUMBER,
|
774
|
+
:NIL,
|
775
|
+
:EMBED,
|
776
|
+
"[",
|
777
|
+
"]",
|
778
|
+
:LL,
|
779
|
+
"@",
|
780
|
+
]
|
781
|
+
### Action Table
|
782
|
+
action_table = [
|
783
|
+
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
784
|
+
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
785
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
786
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
787
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
788
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
789
|
+
[ nil, nil, nil, 18, nil, nil, nil, nil, nil, nil, nil, nil, 17, nil, nil, nil, nil, ],
|
790
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
791
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
792
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
793
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
794
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
795
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
796
|
+
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, 19, nil, nil, ],
|
797
|
+
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
798
|
+
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
799
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
800
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
801
|
+
[ nil, nil, 6, nil, 24, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
802
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
803
|
+
[ nil, nil, nil, nil, nil, 27, nil, nil, nil, nil, nil, nil, nil, nil, 26, nil, nil, ],
|
804
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
805
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
806
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
807
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
808
|
+
[ nil, nil, nil, nil, 28, 27, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
809
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
810
|
+
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
811
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
812
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
813
|
+
]
|
814
|
+
### Default Reduce Table
|
815
|
+
defred_table = [
|
816
|
+
nil,
|
817
|
+
nil,
|
818
|
+
-1,
|
819
|
+
-6,
|
820
|
+
-7,
|
821
|
+
-8,
|
822
|
+
-16,
|
823
|
+
-10,
|
824
|
+
-11,
|
825
|
+
-12,
|
826
|
+
-13,
|
827
|
+
-14,
|
828
|
+
-15,
|
829
|
+
nil,
|
830
|
+
nil,
|
831
|
+
nil,
|
832
|
+
-9,
|
833
|
+
-17,
|
834
|
+
nil,
|
835
|
+
-18,
|
836
|
+
nil,
|
837
|
+
-4,
|
838
|
+
-20,
|
839
|
+
-21,
|
840
|
+
-2,
|
841
|
+
nil,
|
842
|
+
-19,
|
843
|
+
nil,
|
844
|
+
-3,
|
845
|
+
-5,
|
846
|
+
]
|
847
|
+
defred_after_shift_table = [
|
848
|
+
nil,
|
849
|
+
nil,
|
850
|
+
nil,
|
851
|
+
-6,
|
852
|
+
-7,
|
853
|
+
-8,
|
854
|
+
nil,
|
855
|
+
-10,
|
856
|
+
-11,
|
857
|
+
-12,
|
858
|
+
-13,
|
859
|
+
-14,
|
860
|
+
-15,
|
861
|
+
nil,
|
862
|
+
nil,
|
863
|
+
nil,
|
864
|
+
-9,
|
865
|
+
-17,
|
866
|
+
nil,
|
867
|
+
-18,
|
868
|
+
nil,
|
869
|
+
nil,
|
870
|
+
nil,
|
871
|
+
nil,
|
872
|
+
-2,
|
873
|
+
nil,
|
874
|
+
-19,
|
875
|
+
nil,
|
876
|
+
-3,
|
877
|
+
nil,
|
878
|
+
]
|
879
|
+
### Nonterm to Int
|
880
|
+
nonterm_to_int = {
|
881
|
+
:start => 0,
|
882
|
+
:fnl => 1,
|
883
|
+
:node => 2,
|
884
|
+
:fnlpair => 3,
|
885
|
+
:fact => 4,
|
886
|
+
:list => 5,
|
887
|
+
:opt_embed => 6,
|
888
|
+
}
|
889
|
+
### Int to Nonterm
|
890
|
+
int_to_nonterm = [
|
891
|
+
:start,
|
892
|
+
:fnl,
|
893
|
+
:node,
|
894
|
+
:fnlpair,
|
895
|
+
:fact,
|
896
|
+
:list,
|
897
|
+
:opt_embed,
|
898
|
+
]
|
899
|
+
### Goto Table
|
900
|
+
goto_table = [
|
901
|
+
[ 1, 2, 4, nil, 3, 5, nil, ],
|
902
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
903
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
904
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
905
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
906
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
907
|
+
[ nil, nil, nil, nil, nil, nil, 16, ],
|
908
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
909
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
910
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
911
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
912
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
913
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
914
|
+
[ nil, 21, 4, 20, 3, 5, nil, ],
|
915
|
+
[ nil, 22, 4, nil, 3, 5, nil, ],
|
916
|
+
[ nil, 23, 4, nil, 3, 5, nil, ],
|
917
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
918
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
919
|
+
[ nil, 21, 4, 25, 3, 5, nil, ],
|
920
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
921
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
922
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
923
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
924
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
925
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
926
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
927
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
928
|
+
[ nil, 29, 4, nil, 3, 5, nil, ],
|
929
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
930
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
931
|
+
]
|
932
|
+
|
933
|
+
Tables = [ reduce_table, action_table,
|
934
|
+
defred_table, defred_after_shift_table, goto_table,
|
935
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
936
|
+
|
937
|
+
def initialize g_parser, master
|
938
|
+
super()
|
939
|
+
@g_parser = g_parser
|
940
|
+
@d_parser = g_parser.d_parser
|
941
|
+
@master = master
|
942
|
+
@decorated = Action.new(self)
|
943
|
+
end
|
944
|
+
|
945
|
+
|
946
|
+
def do_parse?
|
947
|
+
if @line.match(/^\s*=>/)
|
948
|
+
@line = $'
|
949
|
+
true
|
950
|
+
else
|
951
|
+
false
|
952
|
+
end
|
953
|
+
end
|
954
|
+
|
955
|
+
|
956
|
+
def banner
|
957
|
+
"=>... / Depager::ASTBuilderExtension"
|
958
|
+
end
|
959
|
+
|
960
|
+
|
961
|
+
def lex
|
962
|
+
begin
|
963
|
+
until @line.empty?
|
964
|
+
case @line
|
965
|
+
|
966
|
+
when /\A[ \t]+/
|
967
|
+
@line = $'
|
968
|
+
|
969
|
+
|
970
|
+
|
971
|
+
when /\A\r?\n/
|
972
|
+
@line = $'
|
973
|
+
yield nil, nil
|
974
|
+
|
975
|
+
|
976
|
+
when /\A<</
|
977
|
+
@line = $'
|
978
|
+
yield token(:LL, $&)
|
979
|
+
|
980
|
+
|
981
|
+
when /\A%([a-zA-Z0-9_]+)((::[a-zA-Z0-9_]+)*)/
|
982
|
+
@line = $'
|
983
|
+
yield token(:CONST, $1+$2)
|
984
|
+
|
985
|
+
|
986
|
+
when /\A%\((.+)\)%/
|
987
|
+
@line = $'
|
988
|
+
yield token(:EMBED, $1)
|
989
|
+
|
990
|
+
|
991
|
+
when /\Anil/
|
992
|
+
@line = $'
|
993
|
+
yield token(:NIL, $&)
|
994
|
+
|
995
|
+
|
996
|
+
when /\ANilNode/
|
997
|
+
@line = $'
|
998
|
+
yield token(:NILNODE, $&)
|
999
|
+
|
1000
|
+
|
1001
|
+
when /\A[0-9]+/
|
1002
|
+
@line = $'
|
1003
|
+
yield token(:NUMBER, $&.to_i)
|
1004
|
+
|
1005
|
+
|
1006
|
+
when /\A:[a-zA-Z0-9_]+/
|
1007
|
+
@line = $'
|
1008
|
+
yield token(:SYMBOL, $&)
|
1009
|
+
|
1010
|
+
|
1011
|
+
when /\A[a-zA-Z][a-zA-Z0-9_]*/
|
1012
|
+
@line = $'
|
1013
|
+
yield token(:ID, $&)
|
1014
|
+
|
1015
|
+
|
1016
|
+
when /\A'(.+)'/
|
1017
|
+
@line = $'
|
1018
|
+
yield token(:STR, $1)
|
1019
|
+
|
1020
|
+
|
1021
|
+
when /\A./
|
1022
|
+
@line = $'
|
1023
|
+
yield token($&, $&)
|
1024
|
+
|
1025
|
+
|
1026
|
+
else
|
1027
|
+
raise RuntimeError, "must not happen #{@line}"
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
end while @original_line = @line = file.gets
|
1031
|
+
yield nil, nil
|
1032
|
+
end
|
1033
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 174
|
1034
|
+
def do_default
|
1035
|
+
n = g_parser.rules.size-1
|
1036
|
+
master.action_code << %{
|
1037
|
+
def _ast_#{n} val
|
1038
|
+
NilNode.new(basis.file.lineno)
|
1039
|
+
end
|
1040
|
+
}.unindent #code
|
1041
|
+
master.on_reduce[n] = ":_ast_#{n}"
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
DEPAGER_EXPANDED_CODE
|
1045
|
+
|
1046
|
+
end
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
|
1050
|
+
class Depager::ASTBuilderExtension::Slave_post_rhs::Action < Depager::LALR::Action #:nodoc:all
|
1051
|
+
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
1052
|
+
|
1053
|
+
on_reduce = [
|
1054
|
+
nil,
|
1055
|
+
:_act_1,
|
1056
|
+
:_act_2,
|
1057
|
+
:_act_3,
|
1058
|
+
:_act_4,
|
1059
|
+
:_act_5,
|
1060
|
+
:_act_6,
|
1061
|
+
:_act_7,
|
1062
|
+
:_act_8,
|
1063
|
+
:_act_9,
|
1064
|
+
:_act_10,
|
1065
|
+
:_act_11,
|
1066
|
+
:_act_12,
|
1067
|
+
:_act_13,
|
1068
|
+
:_act_14,
|
1069
|
+
:_act_15,
|
1070
|
+
:_act_16,
|
1071
|
+
:_act_17,
|
1072
|
+
:_act_18,
|
1073
|
+
:_act_19,
|
1074
|
+
:_act_20,
|
1075
|
+
:_act_21,
|
1076
|
+
|
1077
|
+
]
|
1078
|
+
Tables = [ on_reduce ]
|
1079
|
+
|
1080
|
+
|
1081
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 202
|
1082
|
+
def _act_1 val
|
1083
|
+
_fnl, = *val
|
1084
|
+
|
1085
|
+
n = g_parser.rules.size-1
|
1086
|
+
master.action_code <<
|
1087
|
+
master.expand_inline_code(_fnl, basis.file.lineno, :wrap => "def _ast_#{n} val")
|
1088
|
+
master.on_reduce[n] = ":_ast_#{n}"
|
1089
|
+
|
1090
|
+
end
|
1091
|
+
DEPAGER_EXPANDED_CODE
|
1092
|
+
|
1093
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 210
|
1094
|
+
def _act_2 val
|
1095
|
+
_ID, _, _, = *val
|
1096
|
+
"#{master.node_name _ID.value}.new(basis.file.lineno)"
|
1097
|
+
|
1098
|
+
end
|
1099
|
+
DEPAGER_EXPANDED_CODE
|
1100
|
+
|
1101
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 212
|
1102
|
+
def _act_3 val
|
1103
|
+
_ID, _, _fnlpair, _, = *val
|
1104
|
+
|
1105
|
+
if g_parser.rhs.size > 0
|
1106
|
+
"#{master.node_name _ID.value}.new(val[0].lineno, #{_fnlpair.join(', ')})"
|
1107
|
+
else
|
1108
|
+
"#{master.node_name _ID.value}.new(basis.file.lineno, #{_fnlpair.join(', ')})"
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
end
|
1112
|
+
DEPAGER_EXPANDED_CODE
|
1113
|
+
|
1114
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 221
|
1115
|
+
def _act_4 val
|
1116
|
+
_fnl, = *val
|
1117
|
+
[_fnl]
|
1118
|
+
|
1119
|
+
end
|
1120
|
+
DEPAGER_EXPANDED_CODE
|
1121
|
+
|
1122
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 222
|
1123
|
+
def _act_5 val
|
1124
|
+
_fnlpair, _, _fnl, = *val
|
1125
|
+
_fnlpair << _fnl
|
1126
|
+
|
1127
|
+
end
|
1128
|
+
DEPAGER_EXPANDED_CODE
|
1129
|
+
|
1130
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 225
|
1131
|
+
def _act_6 val
|
1132
|
+
_fact, = *val
|
1133
|
+
_fact
|
1134
|
+
|
1135
|
+
end
|
1136
|
+
DEPAGER_EXPANDED_CODE
|
1137
|
+
|
1138
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 226
|
1139
|
+
def _act_7 val
|
1140
|
+
_node, = *val
|
1141
|
+
_node
|
1142
|
+
|
1143
|
+
end
|
1144
|
+
DEPAGER_EXPANDED_CODE
|
1145
|
+
|
1146
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 227
|
1147
|
+
def _act_8 val
|
1148
|
+
_list, = *val
|
1149
|
+
_list
|
1150
|
+
|
1151
|
+
end
|
1152
|
+
DEPAGER_EXPANDED_CODE
|
1153
|
+
|
1154
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 231
|
1155
|
+
def _act_9 val
|
1156
|
+
_ID, _opt_embed, = *val
|
1157
|
+
|
1158
|
+
unless i = g_parser.name_to_rhs_index(_ID.value)
|
1159
|
+
warn "#{g_parser.lineno}: ?#{_ID.value}"
|
1160
|
+
raise
|
1161
|
+
end
|
1162
|
+
"val[#{i}]#{val[1]}"
|
1163
|
+
|
1164
|
+
end
|
1165
|
+
DEPAGER_EXPANDED_CODE
|
1166
|
+
|
1167
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 238
|
1168
|
+
def _act_10 val
|
1169
|
+
_CONST, = *val
|
1170
|
+
"Depager::Token.new(#{_CONST.value})"
|
1171
|
+
|
1172
|
+
end
|
1173
|
+
DEPAGER_EXPANDED_CODE
|
1174
|
+
|
1175
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 239
|
1176
|
+
def _act_11 val
|
1177
|
+
_SYMBOL, = *val
|
1178
|
+
"Depager::Token.new(#{_SYMBOL.value})"
|
1179
|
+
|
1180
|
+
end
|
1181
|
+
DEPAGER_EXPANDED_CODE
|
1182
|
+
|
1183
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 240
|
1184
|
+
def _act_12 val
|
1185
|
+
_STR, = *val
|
1186
|
+
"Depager::Token.new('#{_STR.value}')"
|
1187
|
+
|
1188
|
+
end
|
1189
|
+
DEPAGER_EXPANDED_CODE
|
1190
|
+
|
1191
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 241
|
1192
|
+
def _act_13 val
|
1193
|
+
_NILNODE, = *val
|
1194
|
+
"NilNode.new(basis.file.lineno)"
|
1195
|
+
|
1196
|
+
end
|
1197
|
+
DEPAGER_EXPANDED_CODE
|
1198
|
+
|
1199
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 242
|
1200
|
+
def _act_14 val
|
1201
|
+
_NUMBER, = *val
|
1202
|
+
"Depager::Token.new(#{_NUMBER.value})"
|
1203
|
+
|
1204
|
+
end
|
1205
|
+
DEPAGER_EXPANDED_CODE
|
1206
|
+
|
1207
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 243
|
1208
|
+
def _act_15 val
|
1209
|
+
_NIL, = *val
|
1210
|
+
"nil"
|
1211
|
+
|
1212
|
+
end
|
1213
|
+
DEPAGER_EXPANDED_CODE
|
1214
|
+
|
1215
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 246
|
1216
|
+
def _act_16 val
|
1217
|
+
''
|
1218
|
+
|
1219
|
+
end
|
1220
|
+
DEPAGER_EXPANDED_CODE
|
1221
|
+
|
1222
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 247
|
1223
|
+
def _act_17 val
|
1224
|
+
_EMBED, = *val
|
1225
|
+
_EMBED.value
|
1226
|
+
|
1227
|
+
end
|
1228
|
+
DEPAGER_EXPANDED_CODE
|
1229
|
+
|
1230
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 250
|
1231
|
+
def _act_18 val
|
1232
|
+
_, _, = *val
|
1233
|
+
"#{master.node_name '@List'}.new(basis.file.lineno, [])"
|
1234
|
+
|
1235
|
+
end
|
1236
|
+
DEPAGER_EXPANDED_CODE
|
1237
|
+
|
1238
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 252
|
1239
|
+
def _act_19 val
|
1240
|
+
_, _fnlpair, _, = *val
|
1241
|
+
|
1242
|
+
if g_parser.rhs.size > 0
|
1243
|
+
"#{master.node_name '@List'}.new(val[0].lineno, [#{_fnlpair.join(', ')}])"
|
1244
|
+
else
|
1245
|
+
"#{master.node_name '@List'}.new(basis.file.lineno, #{_fnlpair.join(', ')})"
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
end
|
1249
|
+
DEPAGER_EXPANDED_CODE
|
1250
|
+
|
1251
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 259
|
1252
|
+
def _act_20 val
|
1253
|
+
_l, _LL, _r, = *val
|
1254
|
+
"#{_l}.push(#{_r})"
|
1255
|
+
|
1256
|
+
end
|
1257
|
+
DEPAGER_EXPANDED_CODE
|
1258
|
+
|
1259
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 260
|
1260
|
+
def _act_21 val
|
1261
|
+
_l, _, _r, = *val
|
1262
|
+
"#{_l}.concat(#{_r})"
|
1263
|
+
|
1264
|
+
end
|
1265
|
+
DEPAGER_EXPANDED_CODE
|
1266
|
+
|
1267
|
+
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
|
1271
|
+
class Depager::ASTBuilderExtension
|
1272
|
+
BASE_NODE_TEMPLATE = <<-'EOS'
|
1273
|
+
class Node
|
1274
|
+
attr_accessor :lineno
|
1275
|
+
attr_accessor <%= _opt_attr.map{|i| ":#{i}" }.join(', ') %>
|
1276
|
+
<%= ini %>
|
1277
|
+
|
1278
|
+
def self.[] lineno, *args
|
1279
|
+
self.new lineno, *args
|
1280
|
+
end
|
1281
|
+
|
1282
|
+
def accept v
|
1283
|
+
end
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
class NodeList < Node
|
1287
|
+
attr_accessor :lineno
|
1288
|
+
def initialize(lineno, lst=[])
|
1289
|
+
@lineno = lineno
|
1290
|
+
@lst = lst.to_a.select{|i| ! i.is_a?(NilNode)}
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
<%- _opt_attr.each do |i| -%>
|
1294
|
+
def all_<%= i %>
|
1295
|
+
@lst.map{|i| i.<%= i %>}
|
1296
|
+
end
|
1297
|
+
<%- end -%>
|
1298
|
+
|
1299
|
+
def size
|
1300
|
+
@lst.size
|
1301
|
+
end
|
1302
|
+
alias length size
|
1303
|
+
|
1304
|
+
def push(i)
|
1305
|
+
@lst.push i unless i.is_a? NilNode
|
1306
|
+
self
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
def concat(i)
|
1310
|
+
@lst.concat i
|
1311
|
+
self
|
1312
|
+
end
|
1313
|
+
|
1314
|
+
def to_ary()
|
1315
|
+
@lst
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
alias to_a to_ary
|
1319
|
+
alias list to_ary
|
1320
|
+
|
1321
|
+
def accept(v)
|
1322
|
+
@lst.each{|i| i.accept(v) }
|
1323
|
+
end
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
class NilNode
|
1327
|
+
attr_accessor :lineno
|
1328
|
+
attr_accessor <%= _opt_attr.map{|i| ":#{i}" }.join(', ') %>
|
1329
|
+
|
1330
|
+
def initialize(lineno, *args)
|
1331
|
+
@lineno = lineno
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
def accept v
|
1335
|
+
end
|
1336
|
+
end
|
1337
|
+
EOS
|
1338
|
+
|
1339
|
+
NODE_TEMPLATE = <<-'EOS'
|
1340
|
+
class Node_<%= name %> < Node
|
1341
|
+
attr_accessor <%= nodes.map{|i| ":#{i}" }.join(', ') %>
|
1342
|
+
attr_accessor <%= attrs.map{|i| ":#{i}" }.join(', ') %>
|
1343
|
+
|
1344
|
+
def initialize <%= nodes.unshift('lineno').join(', ') %>
|
1345
|
+
super()
|
1346
|
+
@lineno = lineno
|
1347
|
+
<%= nodes.inject(''){|r,i| r << " @#{i} = #{i}\n"} %>
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
def accept v
|
1351
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
1352
|
+
<%= accept %>
|
1353
|
+
v.visit_Node_<%= name %>(self)
|
1354
|
+
self
|
1355
|
+
end
|
1356
|
+
end
|
1357
|
+
EOS
|
1358
|
+
|
1359
|
+
VISITOR_TEMPLATE = <<-'EOS'
|
1360
|
+
class Visitor<%= name ? '_' + name : '' %>
|
1361
|
+
def visit node
|
1362
|
+
node.accept(self)
|
1363
|
+
end
|
1364
|
+
<%= body.join %>
|
1365
|
+
end # Visitor<%= name ? '_' + name : '' %>
|
1366
|
+
EOS
|
1367
|
+
end
|