exalted_math 0.1.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.
@@ -0,0 +1,1266 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Exalted
5
+ module Maths
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :additive
10
+ end
11
+
12
+ module Additive0
13
+ def multitive
14
+ elements[0]
15
+ end
16
+
17
+ def additive
18
+ elements[4]
19
+ end
20
+ end
21
+
22
+ module Additive1
23
+ def ast
24
+ Ast.add(multitive.ast, additive.ast )
25
+ end
26
+ end
27
+
28
+ module Additive2
29
+ def multitive
30
+ elements[0]
31
+ end
32
+
33
+ def additive
34
+ elements[4]
35
+ end
36
+ end
37
+
38
+ module Additive3
39
+ def ast
40
+ Ast.sub( multitive.ast, additive.ast )
41
+ end
42
+ end
43
+
44
+ def _nt_additive
45
+ start_index = index
46
+ if node_cache[:additive].has_key?(index)
47
+ cached = node_cache[:additive][index]
48
+ if cached
49
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
50
+ @index = cached.interval.end
51
+ end
52
+ return cached
53
+ end
54
+
55
+ i0 = index
56
+ i1, s1 = index, []
57
+ r2 = _nt_multitive
58
+ s1 << r2
59
+ if r2
60
+ s3, i3 = [], index
61
+ loop do
62
+ r4 = _nt_space
63
+ if r4
64
+ s3 << r4
65
+ else
66
+ break
67
+ end
68
+ end
69
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
70
+ s1 << r3
71
+ if r3
72
+ if has_terminal?('+', false, index)
73
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
74
+ @index += 1
75
+ else
76
+ terminal_parse_failure('+')
77
+ r5 = nil
78
+ end
79
+ s1 << r5
80
+ if r5
81
+ s6, i6 = [], index
82
+ loop do
83
+ r7 = _nt_space
84
+ if r7
85
+ s6 << r7
86
+ else
87
+ break
88
+ end
89
+ end
90
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
91
+ s1 << r6
92
+ if r6
93
+ r8 = _nt_additive
94
+ s1 << r8
95
+ end
96
+ end
97
+ end
98
+ end
99
+ if s1.last
100
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
101
+ r1.extend(Additive0)
102
+ r1.extend(Additive1)
103
+ else
104
+ @index = i1
105
+ r1 = nil
106
+ end
107
+ if r1
108
+ r0 = r1
109
+ else
110
+ i9, s9 = index, []
111
+ r10 = _nt_multitive
112
+ s9 << r10
113
+ if r10
114
+ s11, i11 = [], index
115
+ loop do
116
+ r12 = _nt_space
117
+ if r12
118
+ s11 << r12
119
+ else
120
+ break
121
+ end
122
+ end
123
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
124
+ s9 << r11
125
+ if r11
126
+ if has_terminal?('-', false, index)
127
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
128
+ @index += 1
129
+ else
130
+ terminal_parse_failure('-')
131
+ r13 = nil
132
+ end
133
+ s9 << r13
134
+ if r13
135
+ s14, i14 = [], index
136
+ loop do
137
+ r15 = _nt_space
138
+ if r15
139
+ s14 << r15
140
+ else
141
+ break
142
+ end
143
+ end
144
+ r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
145
+ s9 << r14
146
+ if r14
147
+ r16 = _nt_additive
148
+ s9 << r16
149
+ end
150
+ end
151
+ end
152
+ end
153
+ if s9.last
154
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
155
+ r9.extend(Additive2)
156
+ r9.extend(Additive3)
157
+ else
158
+ @index = i9
159
+ r9 = nil
160
+ end
161
+ if r9
162
+ r0 = r9
163
+ else
164
+ r17 = _nt_multitive
165
+ if r17
166
+ r0 = r17
167
+ else
168
+ @index = i0
169
+ r0 = nil
170
+ end
171
+ end
172
+ end
173
+
174
+ node_cache[:additive][start_index] = r0
175
+
176
+ r0
177
+ end
178
+
179
+ module Multitive0
180
+ def primary
181
+ elements[0]
182
+ end
183
+
184
+ def multitive
185
+ elements[4]
186
+ end
187
+ end
188
+
189
+ module Multitive1
190
+ def ast
191
+ Ast.mul(primary.ast, multitive.ast )
192
+ end
193
+ end
194
+
195
+ module Multitive2
196
+ def primary
197
+ elements[0]
198
+ end
199
+
200
+ def multitive
201
+ elements[4]
202
+ end
203
+ end
204
+
205
+ module Multitive3
206
+ def ast
207
+ Ast.div( primary.ast, multitive.ast )
208
+ end
209
+ end
210
+
211
+ def _nt_multitive
212
+ start_index = index
213
+ if node_cache[:multitive].has_key?(index)
214
+ cached = node_cache[:multitive][index]
215
+ if cached
216
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
217
+ @index = cached.interval.end
218
+ end
219
+ return cached
220
+ end
221
+
222
+ i0 = index
223
+ i1, s1 = index, []
224
+ r2 = _nt_primary
225
+ s1 << r2
226
+ if r2
227
+ s3, i3 = [], index
228
+ loop do
229
+ r4 = _nt_space
230
+ if r4
231
+ s3 << r4
232
+ else
233
+ break
234
+ end
235
+ end
236
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
237
+ s1 << r3
238
+ if r3
239
+ if has_terminal?('*', false, index)
240
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
241
+ @index += 1
242
+ else
243
+ terminal_parse_failure('*')
244
+ r5 = nil
245
+ end
246
+ s1 << r5
247
+ if r5
248
+ s6, i6 = [], index
249
+ loop do
250
+ r7 = _nt_space
251
+ if r7
252
+ s6 << r7
253
+ else
254
+ break
255
+ end
256
+ end
257
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
258
+ s1 << r6
259
+ if r6
260
+ r8 = _nt_multitive
261
+ s1 << r8
262
+ end
263
+ end
264
+ end
265
+ end
266
+ if s1.last
267
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
268
+ r1.extend(Multitive0)
269
+ r1.extend(Multitive1)
270
+ else
271
+ @index = i1
272
+ r1 = nil
273
+ end
274
+ if r1
275
+ r0 = r1
276
+ else
277
+ i9, s9 = index, []
278
+ r10 = _nt_primary
279
+ s9 << r10
280
+ if r10
281
+ s11, i11 = [], index
282
+ loop do
283
+ r12 = _nt_space
284
+ if r12
285
+ s11 << r12
286
+ else
287
+ break
288
+ end
289
+ end
290
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
291
+ s9 << r11
292
+ if r11
293
+ if has_terminal?('/', false, index)
294
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
295
+ @index += 1
296
+ else
297
+ terminal_parse_failure('/')
298
+ r13 = nil
299
+ end
300
+ s9 << r13
301
+ if r13
302
+ s14, i14 = [], index
303
+ loop do
304
+ r15 = _nt_space
305
+ if r15
306
+ s14 << r15
307
+ else
308
+ break
309
+ end
310
+ end
311
+ r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
312
+ s9 << r14
313
+ if r14
314
+ r16 = _nt_multitive
315
+ s9 << r16
316
+ end
317
+ end
318
+ end
319
+ end
320
+ if s9.last
321
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
322
+ r9.extend(Multitive2)
323
+ r9.extend(Multitive3)
324
+ else
325
+ @index = i9
326
+ r9 = nil
327
+ end
328
+ if r9
329
+ r0 = r9
330
+ else
331
+ r17 = _nt_primary
332
+ if r17
333
+ r0 = r17
334
+ else
335
+ @index = i0
336
+ r0 = nil
337
+ end
338
+ end
339
+ end
340
+
341
+ node_cache[:multitive][start_index] = r0
342
+
343
+ r0
344
+ end
345
+
346
+ module Primary0
347
+ def additive
348
+ elements[2]
349
+ end
350
+
351
+ end
352
+
353
+ module Primary1
354
+ def ast
355
+ additive.ast
356
+ end
357
+ end
358
+
359
+ def _nt_primary
360
+ start_index = index
361
+ if node_cache[:primary].has_key?(index)
362
+ cached = node_cache[:primary][index]
363
+ if cached
364
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
365
+ @index = cached.interval.end
366
+ end
367
+ return cached
368
+ end
369
+
370
+ i0 = index
371
+ i1, s1 = index, []
372
+ if has_terminal?('(', false, index)
373
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
374
+ @index += 1
375
+ else
376
+ terminal_parse_failure('(')
377
+ r2 = nil
378
+ end
379
+ s1 << r2
380
+ if r2
381
+ s3, i3 = [], index
382
+ loop do
383
+ r4 = _nt_space
384
+ if r4
385
+ s3 << r4
386
+ else
387
+ break
388
+ end
389
+ end
390
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
391
+ s1 << r3
392
+ if r3
393
+ r5 = _nt_additive
394
+ s1 << r5
395
+ if r5
396
+ s6, i6 = [], index
397
+ loop do
398
+ r7 = _nt_space
399
+ if r7
400
+ s6 << r7
401
+ else
402
+ break
403
+ end
404
+ end
405
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
406
+ s1 << r6
407
+ if r6
408
+ if has_terminal?(')', false, index)
409
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
410
+ @index += 1
411
+ else
412
+ terminal_parse_failure(')')
413
+ r8 = nil
414
+ end
415
+ s1 << r8
416
+ end
417
+ end
418
+ end
419
+ end
420
+ if s1.last
421
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
422
+ r1.extend(Primary0)
423
+ r1.extend(Primary1)
424
+ else
425
+ @index = i1
426
+ r1 = nil
427
+ end
428
+ if r1
429
+ r0 = r1
430
+ else
431
+ r9 = _nt_number
432
+ if r9
433
+ r0 = r9
434
+ else
435
+ r10 = _nt_spec
436
+ if r10
437
+ r0 = r10
438
+ else
439
+ r11 = _nt_max
440
+ if r11
441
+ r0 = r11
442
+ else
443
+ r12 = _nt_min
444
+ if r12
445
+ r0 = r12
446
+ else
447
+ r13 = _nt_stat
448
+ if r13
449
+ r0 = r13
450
+ else
451
+ @index = i0
452
+ r0 = nil
453
+ end
454
+ end
455
+ end
456
+ end
457
+ end
458
+ end
459
+
460
+ node_cache[:primary][start_index] = r0
461
+
462
+ r0
463
+ end
464
+
465
+ module Spec0
466
+ def speciality
467
+ elements[4]
468
+ end
469
+
470
+ end
471
+
472
+ module Spec1
473
+ def value
474
+ speciality.text_value
475
+ end
476
+
477
+ def ast
478
+ Ast.spec(value)
479
+ end
480
+ end
481
+
482
+ def _nt_spec
483
+ start_index = index
484
+ if node_cache[:spec].has_key?(index)
485
+ cached = node_cache[:spec][index]
486
+ if cached
487
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
488
+ @index = cached.interval.end
489
+ end
490
+ return cached
491
+ end
492
+
493
+ i0, s0 = index, []
494
+ if has_terminal?('\G[Ss]', true, index)
495
+ r1 = true
496
+ @index += 1
497
+ else
498
+ r1 = nil
499
+ end
500
+ s0 << r1
501
+ if r1
502
+ if has_terminal?('pec', false, index)
503
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 3))
504
+ @index += 3
505
+ else
506
+ terminal_parse_failure('pec')
507
+ r2 = nil
508
+ end
509
+ s0 << r2
510
+ if r2
511
+ if has_terminal?('iality', false, index)
512
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 6))
513
+ @index += 6
514
+ else
515
+ terminal_parse_failure('iality')
516
+ r4 = nil
517
+ end
518
+ if r4
519
+ r3 = r4
520
+ else
521
+ r3 = instantiate_node(SyntaxNode,input, index...index)
522
+ end
523
+ s0 << r3
524
+ if r3
525
+ if has_terminal?(':"', false, index)
526
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
527
+ @index += 2
528
+ else
529
+ terminal_parse_failure(':"')
530
+ r5 = nil
531
+ end
532
+ s0 << r5
533
+ if r5
534
+ s6, i6 = [], index
535
+ loop do
536
+ if has_terminal?('\G[^"]', true, index)
537
+ r7 = true
538
+ @index += 1
539
+ else
540
+ r7 = nil
541
+ end
542
+ if r7
543
+ s6 << r7
544
+ else
545
+ break
546
+ end
547
+ end
548
+ if s6.empty?
549
+ @index = i6
550
+ r6 = nil
551
+ else
552
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
553
+ end
554
+ s0 << r6
555
+ if r6
556
+ if has_terminal?('"', false, index)
557
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
558
+ @index += 1
559
+ else
560
+ terminal_parse_failure('"')
561
+ r8 = nil
562
+ end
563
+ s0 << r8
564
+ end
565
+ end
566
+ end
567
+ end
568
+ end
569
+ if s0.last
570
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
571
+ r0.extend(Spec0)
572
+ r0.extend(Spec1)
573
+ else
574
+ @index = i0
575
+ r0 = nil
576
+ end
577
+
578
+ node_cache[:spec][start_index] = r0
579
+
580
+ r0
581
+ end
582
+
583
+ module Max0
584
+ def number
585
+ elements[1]
586
+ end
587
+
588
+ end
589
+
590
+ module Max1
591
+ def num
592
+ elements[1]
593
+ end
594
+
595
+ def list
596
+ elements[4]
597
+ end
598
+
599
+ end
600
+
601
+ module Max2
602
+ def count
603
+ if num.elements
604
+ num.elements.detect { |e| e.respond_to?(:value) }.value
605
+ else
606
+ 1
607
+ end
608
+ end
609
+
610
+ def ast
611
+ Ast.max( count, list.asts )
612
+ end
613
+ end
614
+
615
+ def _nt_max
616
+ start_index = index
617
+ if node_cache[:max].has_key?(index)
618
+ cached = node_cache[:max][index]
619
+ if cached
620
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
621
+ @index = cached.interval.end
622
+ end
623
+ return cached
624
+ end
625
+
626
+ i0, s0 = index, []
627
+ i1 = index
628
+ if has_terminal?('max', false, index)
629
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 3))
630
+ @index += 3
631
+ else
632
+ terminal_parse_failure('max')
633
+ r2 = nil
634
+ end
635
+ if r2
636
+ r1 = r2
637
+ else
638
+ if has_terminal?('highest', false, index)
639
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 7))
640
+ @index += 7
641
+ else
642
+ terminal_parse_failure('highest')
643
+ r3 = nil
644
+ end
645
+ if r3
646
+ r1 = r3
647
+ else
648
+ @index = i1
649
+ r1 = nil
650
+ end
651
+ end
652
+ s0 << r1
653
+ if r1
654
+ i5, s5 = index, []
655
+ if has_terminal?('[', false, index)
656
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
657
+ @index += 1
658
+ else
659
+ terminal_parse_failure('[')
660
+ r6 = nil
661
+ end
662
+ s5 << r6
663
+ if r6
664
+ r7 = _nt_number
665
+ s5 << r7
666
+ if r7
667
+ if has_terminal?(']', false, index)
668
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
669
+ @index += 1
670
+ else
671
+ terminal_parse_failure(']')
672
+ r8 = nil
673
+ end
674
+ s5 << r8
675
+ end
676
+ end
677
+ if s5.last
678
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
679
+ r5.extend(Max0)
680
+ else
681
+ @index = i5
682
+ r5 = nil
683
+ end
684
+ if r5
685
+ r4 = r5
686
+ else
687
+ r4 = instantiate_node(SyntaxNode,input, index...index)
688
+ end
689
+ s0 << r4
690
+ if r4
691
+ if has_terminal?('(', false, index)
692
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
693
+ @index += 1
694
+ else
695
+ terminal_parse_failure('(')
696
+ r9 = nil
697
+ end
698
+ s0 << r9
699
+ if r9
700
+ s10, i10 = [], index
701
+ loop do
702
+ r11 = _nt_space
703
+ if r11
704
+ s10 << r11
705
+ else
706
+ break
707
+ end
708
+ end
709
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
710
+ s0 << r10
711
+ if r10
712
+ r12 = _nt_list
713
+ s0 << r12
714
+ if r12
715
+ s13, i13 = [], index
716
+ loop do
717
+ r14 = _nt_space
718
+ if r14
719
+ s13 << r14
720
+ else
721
+ break
722
+ end
723
+ end
724
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
725
+ s0 << r13
726
+ if r13
727
+ if has_terminal?(')', false, index)
728
+ r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
729
+ @index += 1
730
+ else
731
+ terminal_parse_failure(')')
732
+ r15 = nil
733
+ end
734
+ s0 << r15
735
+ end
736
+ end
737
+ end
738
+ end
739
+ end
740
+ end
741
+ if s0.last
742
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
743
+ r0.extend(Max1)
744
+ r0.extend(Max2)
745
+ else
746
+ @index = i0
747
+ r0 = nil
748
+ end
749
+
750
+ node_cache[:max][start_index] = r0
751
+
752
+ r0
753
+ end
754
+
755
+ module Min0
756
+ def number
757
+ elements[1]
758
+ end
759
+
760
+ end
761
+
762
+ module Min1
763
+ def num
764
+ elements[1]
765
+ end
766
+
767
+ def list
768
+ elements[4]
769
+ end
770
+
771
+ end
772
+
773
+ module Min2
774
+ def count
775
+ if num.elements
776
+ num.elements.detect { |e| e.respond_to?(:value) }.value
777
+ else
778
+ 1
779
+ end
780
+ end
781
+ def ast
782
+ Ast.min( count, list.asts )
783
+ end
784
+ end
785
+
786
+ def _nt_min
787
+ start_index = index
788
+ if node_cache[:min].has_key?(index)
789
+ cached = node_cache[:min][index]
790
+ if cached
791
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
792
+ @index = cached.interval.end
793
+ end
794
+ return cached
795
+ end
796
+
797
+ i0, s0 = index, []
798
+ i1 = index
799
+ if has_terminal?('min', false, index)
800
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 3))
801
+ @index += 3
802
+ else
803
+ terminal_parse_failure('min')
804
+ r2 = nil
805
+ end
806
+ if r2
807
+ r1 = r2
808
+ else
809
+ if has_terminal?('lowest', false, index)
810
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 6))
811
+ @index += 6
812
+ else
813
+ terminal_parse_failure('lowest')
814
+ r3 = nil
815
+ end
816
+ if r3
817
+ r1 = r3
818
+ else
819
+ @index = i1
820
+ r1 = nil
821
+ end
822
+ end
823
+ s0 << r1
824
+ if r1
825
+ i5, s5 = index, []
826
+ if has_terminal?('[', false, index)
827
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
828
+ @index += 1
829
+ else
830
+ terminal_parse_failure('[')
831
+ r6 = nil
832
+ end
833
+ s5 << r6
834
+ if r6
835
+ r7 = _nt_number
836
+ s5 << r7
837
+ if r7
838
+ if has_terminal?(']', false, index)
839
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
840
+ @index += 1
841
+ else
842
+ terminal_parse_failure(']')
843
+ r8 = nil
844
+ end
845
+ s5 << r8
846
+ end
847
+ end
848
+ if s5.last
849
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
850
+ r5.extend(Min0)
851
+ else
852
+ @index = i5
853
+ r5 = nil
854
+ end
855
+ if r5
856
+ r4 = r5
857
+ else
858
+ r4 = instantiate_node(SyntaxNode,input, index...index)
859
+ end
860
+ s0 << r4
861
+ if r4
862
+ if has_terminal?('(', false, index)
863
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
864
+ @index += 1
865
+ else
866
+ terminal_parse_failure('(')
867
+ r9 = nil
868
+ end
869
+ s0 << r9
870
+ if r9
871
+ s10, i10 = [], index
872
+ loop do
873
+ r11 = _nt_space
874
+ if r11
875
+ s10 << r11
876
+ else
877
+ break
878
+ end
879
+ end
880
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
881
+ s0 << r10
882
+ if r10
883
+ r12 = _nt_list
884
+ s0 << r12
885
+ if r12
886
+ s13, i13 = [], index
887
+ loop do
888
+ r14 = _nt_space
889
+ if r14
890
+ s13 << r14
891
+ else
892
+ break
893
+ end
894
+ end
895
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
896
+ s0 << r13
897
+ if r13
898
+ if has_terminal?(')', false, index)
899
+ r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
900
+ @index += 1
901
+ else
902
+ terminal_parse_failure(')')
903
+ r15 = nil
904
+ end
905
+ s0 << r15
906
+ end
907
+ end
908
+ end
909
+ end
910
+ end
911
+ end
912
+ if s0.last
913
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
914
+ r0.extend(Min1)
915
+ r0.extend(Min2)
916
+ else
917
+ @index = i0
918
+ r0 = nil
919
+ end
920
+
921
+ node_cache[:min][start_index] = r0
922
+
923
+ r0
924
+ end
925
+
926
+ module List0
927
+ end
928
+
929
+ module List1
930
+ end
931
+
932
+ module List2
933
+ def dig(values, elements)
934
+ elements.each do |elem|
935
+ values << elem if elem.respond_to?(:value)
936
+ dig(values, elem.elements) if elem.elements
937
+ end
938
+ values
939
+ end
940
+
941
+ def asts
942
+ elem_list = []
943
+ dig(elem_list, elements)
944
+ elem_list.map! { |e| e.ast }
945
+ end
946
+ end
947
+
948
+ def _nt_list
949
+ start_index = index
950
+ if node_cache[:list].has_key?(index)
951
+ cached = node_cache[:list][index]
952
+ if cached
953
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
954
+ @index = cached.interval.end
955
+ end
956
+ return cached
957
+ end
958
+
959
+ i0, s0 = index, []
960
+ s1, i1 = [], index
961
+ loop do
962
+ i2, s2 = index, []
963
+ i3 = index
964
+ r4 = _nt_number
965
+ if r4
966
+ r3 = r4
967
+ else
968
+ r5 = _nt_stat
969
+ if r5
970
+ r3 = r5
971
+ else
972
+ @index = i3
973
+ r3 = nil
974
+ end
975
+ end
976
+ s2 << r3
977
+ if r3
978
+ s6, i6 = [], index
979
+ loop do
980
+ r7 = _nt_space
981
+ if r7
982
+ s6 << r7
983
+ else
984
+ break
985
+ end
986
+ end
987
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
988
+ s2 << r6
989
+ if r6
990
+ if has_terminal?(',', false, index)
991
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
992
+ @index += 1
993
+ else
994
+ terminal_parse_failure(',')
995
+ r8 = nil
996
+ end
997
+ s2 << r8
998
+ if r8
999
+ s9, i9 = [], index
1000
+ loop do
1001
+ r10 = _nt_space
1002
+ if r10
1003
+ s9 << r10
1004
+ else
1005
+ break
1006
+ end
1007
+ end
1008
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
1009
+ s2 << r9
1010
+ end
1011
+ end
1012
+ end
1013
+ if s2.last
1014
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1015
+ r2.extend(List0)
1016
+ else
1017
+ @index = i2
1018
+ r2 = nil
1019
+ end
1020
+ if r2
1021
+ s1 << r2
1022
+ else
1023
+ break
1024
+ end
1025
+ end
1026
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
1027
+ s0 << r1
1028
+ if r1
1029
+ s11, i11 = [], index
1030
+ loop do
1031
+ r12 = _nt_space
1032
+ if r12
1033
+ s11 << r12
1034
+ else
1035
+ break
1036
+ end
1037
+ end
1038
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
1039
+ s0 << r11
1040
+ if r11
1041
+ i13 = index
1042
+ r14 = _nt_number
1043
+ if r14
1044
+ r13 = r14
1045
+ else
1046
+ r15 = _nt_stat
1047
+ if r15
1048
+ r13 = r15
1049
+ else
1050
+ @index = i13
1051
+ r13 = nil
1052
+ end
1053
+ end
1054
+ s0 << r13
1055
+ end
1056
+ end
1057
+ if s0.last
1058
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1059
+ r0.extend(List1)
1060
+ r0.extend(List2)
1061
+ else
1062
+ @index = i0
1063
+ r0 = nil
1064
+ end
1065
+
1066
+ node_cache[:list][start_index] = r0
1067
+
1068
+ r0
1069
+ end
1070
+
1071
+ def _nt_space
1072
+ start_index = index
1073
+ if node_cache[:space].has_key?(index)
1074
+ cached = node_cache[:space][index]
1075
+ if cached
1076
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1077
+ @index = cached.interval.end
1078
+ end
1079
+ return cached
1080
+ end
1081
+
1082
+ s0, i0 = [], index
1083
+ loop do
1084
+ i1 = index
1085
+ if has_terminal?(" ", false, index)
1086
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
1087
+ @index += 1
1088
+ else
1089
+ terminal_parse_failure(" ")
1090
+ r2 = nil
1091
+ end
1092
+ if r2
1093
+ r1 = r2
1094
+ else
1095
+ if has_terminal?("\t", false, index)
1096
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
1097
+ @index += 1
1098
+ else
1099
+ terminal_parse_failure("\t")
1100
+ r3 = nil
1101
+ end
1102
+ if r3
1103
+ r1 = r3
1104
+ else
1105
+ @index = i1
1106
+ r1 = nil
1107
+ end
1108
+ end
1109
+ if r1
1110
+ s0 << r1
1111
+ else
1112
+ break
1113
+ end
1114
+ end
1115
+ if s0.empty?
1116
+ @index = i0
1117
+ r0 = nil
1118
+ else
1119
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1120
+ end
1121
+
1122
+ node_cache[:space][start_index] = r0
1123
+
1124
+ r0
1125
+ end
1126
+
1127
+ module Number0
1128
+ def negative
1129
+ elements[0]
1130
+ end
1131
+
1132
+ end
1133
+
1134
+ module Number1
1135
+ def value
1136
+ text_value.to_i*neg
1137
+ end
1138
+
1139
+ def neg
1140
+ (negative.elements) ? -1 : 1
1141
+ end
1142
+ def ast
1143
+ Ast.num(value)
1144
+ end
1145
+ end
1146
+
1147
+ def _nt_number
1148
+ start_index = index
1149
+ if node_cache[:number].has_key?(index)
1150
+ cached = node_cache[:number][index]
1151
+ if cached
1152
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1153
+ @index = cached.interval.end
1154
+ end
1155
+ return cached
1156
+ end
1157
+
1158
+ i0, s0 = index, []
1159
+ if has_terminal?('-', false, index)
1160
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
1161
+ @index += 1
1162
+ else
1163
+ terminal_parse_failure('-')
1164
+ r2 = nil
1165
+ end
1166
+ if r2
1167
+ r1 = r2
1168
+ else
1169
+ r1 = instantiate_node(SyntaxNode,input, index...index)
1170
+ end
1171
+ s0 << r1
1172
+ if r1
1173
+ if has_terminal?('\G[1-9]', true, index)
1174
+ r3 = true
1175
+ @index += 1
1176
+ else
1177
+ r3 = nil
1178
+ end
1179
+ s0 << r3
1180
+ if r3
1181
+ s4, i4 = [], index
1182
+ loop do
1183
+ if has_terminal?('\G[0-9]', true, index)
1184
+ r5 = true
1185
+ @index += 1
1186
+ else
1187
+ r5 = nil
1188
+ end
1189
+ if r5
1190
+ s4 << r5
1191
+ else
1192
+ break
1193
+ end
1194
+ end
1195
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1196
+ s0 << r4
1197
+ end
1198
+ end
1199
+ if s0.last
1200
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1201
+ r0.extend(Number0)
1202
+ r0.extend(Number1)
1203
+ else
1204
+ @index = i0
1205
+ r0 = nil
1206
+ end
1207
+
1208
+ node_cache[:number][start_index] = r0
1209
+
1210
+ r0
1211
+ end
1212
+
1213
+ module Stat0
1214
+ def value
1215
+ text_value.downcase
1216
+ end
1217
+ def ast
1218
+ Ast.stat(value)
1219
+ end
1220
+ end
1221
+
1222
+ def _nt_stat
1223
+ start_index = index
1224
+ if node_cache[:stat].has_key?(index)
1225
+ cached = node_cache[:stat][index]
1226
+ if cached
1227
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1228
+ @index = cached.interval.end
1229
+ end
1230
+ return cached
1231
+ end
1232
+
1233
+ s0, i0 = [], index
1234
+ loop do
1235
+ if has_terminal?('\G[A-Za-z]', true, index)
1236
+ r1 = true
1237
+ @index += 1
1238
+ else
1239
+ r1 = nil
1240
+ end
1241
+ if r1
1242
+ s0 << r1
1243
+ else
1244
+ break
1245
+ end
1246
+ end
1247
+ if s0.empty?
1248
+ @index = i0
1249
+ r0 = nil
1250
+ else
1251
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1252
+ r0.extend(Stat0)
1253
+ end
1254
+
1255
+ node_cache[:stat][start_index] = r0
1256
+
1257
+ r0
1258
+ end
1259
+
1260
+ end
1261
+
1262
+ class MathsParser < Treetop::Runtime::CompiledParser
1263
+ include Maths
1264
+ end
1265
+
1266
+ end