equation 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1977 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Equation
5
+ include Treetop::Runtime
6
+
7
+ def root
8
+ @root ||= :expression
9
+ end
10
+
11
+ def _nt_expression
12
+ start_index = index
13
+ if node_cache[:expression].has_key?(index)
14
+ cached = node_cache[:expression][index]
15
+ if cached
16
+ node_cache[:expression][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
17
+ @index = cached.interval.end
18
+ end
19
+ return cached
20
+ end
21
+
22
+ i0 = index
23
+ r1 = _nt_logical
24
+ if r1
25
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
26
+ r0 = r1
27
+ else
28
+ r2 = _nt_comparison
29
+ if r2
30
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
31
+ r0 = r2
32
+ else
33
+ r3 = _nt_additive
34
+ if r3
35
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
36
+ r0 = r3
37
+ else
38
+ r4 = _nt_standalone
39
+ if r4
40
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
41
+ r0 = r4
42
+ else
43
+ @index = i0
44
+ r0 = nil
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ node_cache[:expression][start_index] = r0
51
+
52
+ r0
53
+ end
54
+
55
+ module Logical0
56
+ def operator
57
+ elements[0]
58
+ end
59
+
60
+ def space1
61
+ elements[1]
62
+ end
63
+
64
+ def rhs
65
+ elements[2]
66
+ end
67
+
68
+ def space2
69
+ elements[3]
70
+ end
71
+ end
72
+
73
+ module Logical1
74
+ def lhs
75
+ elements[0]
76
+ end
77
+
78
+ def space
79
+ elements[1]
80
+ end
81
+
82
+ def tail
83
+ elements[2]
84
+ end
85
+ end
86
+
87
+ module Logical2
88
+ def value(ctx:)
89
+ base = lhs.value(ctx: ctx)
90
+ tail.elements.each do |k|
91
+ case k.operator.text_value
92
+ when '||'
93
+ base ||= k.rhs.value(ctx: ctx)
94
+ end
95
+ end
96
+
97
+ base
98
+ end
99
+ end
100
+
101
+ def _nt_logical
102
+ start_index = index
103
+ if node_cache[:logical].has_key?(index)
104
+ cached = node_cache[:logical][index]
105
+ if cached
106
+ node_cache[:logical][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
107
+ @index = cached.interval.end
108
+ end
109
+ return cached
110
+ end
111
+
112
+ i0, s0 = index, []
113
+ i1 = index
114
+ r2 = _nt_boolean_and
115
+ if r2
116
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
117
+ r1 = r2
118
+ else
119
+ r3 = _nt_additive
120
+ if r3
121
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
122
+ r1 = r3
123
+ else
124
+ @index = i1
125
+ r1 = nil
126
+ end
127
+ end
128
+ s0 << r1
129
+ if r1
130
+ r4 = _nt_space
131
+ s0 << r4
132
+ if r4
133
+ s5, i5 = [], index
134
+ loop do
135
+ i6, s6 = index, []
136
+ if (match_len = has_terminal?('||', false, index))
137
+ r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
138
+ @index += match_len
139
+ else
140
+ terminal_parse_failure('\'||\'')
141
+ r7 = nil
142
+ end
143
+ s6 << r7
144
+ if r7
145
+ r8 = _nt_space
146
+ s6 << r8
147
+ if r8
148
+ i9 = index
149
+ r10 = _nt_boolean_and
150
+ if r10
151
+ r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
152
+ r9 = r10
153
+ else
154
+ r11 = _nt_additive
155
+ if r11
156
+ r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
157
+ r9 = r11
158
+ else
159
+ @index = i9
160
+ r9 = nil
161
+ end
162
+ end
163
+ s6 << r9
164
+ if r9
165
+ r12 = _nt_space
166
+ s6 << r12
167
+ end
168
+ end
169
+ end
170
+ if s6.last
171
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
172
+ r6.extend(Logical0)
173
+ else
174
+ @index = i6
175
+ r6 = nil
176
+ end
177
+ if r6
178
+ s5 << r6
179
+ else
180
+ break
181
+ end
182
+ end
183
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
184
+ s0 << r5
185
+ end
186
+ end
187
+ if s0.last
188
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
189
+ r0.extend(Logical1)
190
+ r0.extend(Logical2)
191
+ else
192
+ @index = i0
193
+ r0 = nil
194
+ end
195
+
196
+ node_cache[:logical][start_index] = r0
197
+
198
+ r0
199
+ end
200
+
201
+ module BooleanAnd0
202
+ def operator
203
+ elements[0]
204
+ end
205
+
206
+ def space1
207
+ elements[1]
208
+ end
209
+
210
+ def rhs
211
+ elements[2]
212
+ end
213
+
214
+ def space2
215
+ elements[3]
216
+ end
217
+ end
218
+
219
+ module BooleanAnd1
220
+ def lhs
221
+ elements[0]
222
+ end
223
+
224
+ def space
225
+ elements[1]
226
+ end
227
+
228
+ def tail
229
+ elements[2]
230
+ end
231
+ end
232
+
233
+ module BooleanAnd2
234
+ def value(ctx:)
235
+ base = lhs.value(ctx: ctx)
236
+ tail.elements.each do |k|
237
+ case k.operator.text_value
238
+ when '&&'
239
+ base &&= k.rhs.value(ctx: ctx)
240
+ end
241
+ end
242
+
243
+ base
244
+ end
245
+ end
246
+
247
+ def _nt_boolean_and
248
+ start_index = index
249
+ if node_cache[:boolean_and].has_key?(index)
250
+ cached = node_cache[:boolean_and][index]
251
+ if cached
252
+ node_cache[:boolean_and][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
253
+ @index = cached.interval.end
254
+ end
255
+ return cached
256
+ end
257
+
258
+ i0, s0 = index, []
259
+ i1 = index
260
+ r2 = _nt_comparison
261
+ if r2
262
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
263
+ r1 = r2
264
+ else
265
+ r3 = _nt_additive
266
+ if r3
267
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
268
+ r1 = r3
269
+ else
270
+ @index = i1
271
+ r1 = nil
272
+ end
273
+ end
274
+ s0 << r1
275
+ if r1
276
+ r4 = _nt_space
277
+ s0 << r4
278
+ if r4
279
+ s5, i5 = [], index
280
+ loop do
281
+ i6, s6 = index, []
282
+ if (match_len = has_terminal?('&&', false, index))
283
+ r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
284
+ @index += match_len
285
+ else
286
+ terminal_parse_failure('\'&&\'')
287
+ r7 = nil
288
+ end
289
+ s6 << r7
290
+ if r7
291
+ r8 = _nt_space
292
+ s6 << r8
293
+ if r8
294
+ i9 = index
295
+ r10 = _nt_comparison
296
+ if r10
297
+ r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
298
+ r9 = r10
299
+ else
300
+ r11 = _nt_additive
301
+ if r11
302
+ r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
303
+ r9 = r11
304
+ else
305
+ @index = i9
306
+ r9 = nil
307
+ end
308
+ end
309
+ s6 << r9
310
+ if r9
311
+ r12 = _nt_space
312
+ s6 << r12
313
+ end
314
+ end
315
+ end
316
+ if s6.last
317
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
318
+ r6.extend(BooleanAnd0)
319
+ else
320
+ @index = i6
321
+ r6 = nil
322
+ end
323
+ if r6
324
+ s5 << r6
325
+ else
326
+ break
327
+ end
328
+ end
329
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
330
+ s0 << r5
331
+ end
332
+ end
333
+ if s0.last
334
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
335
+ r0.extend(BooleanAnd1)
336
+ r0.extend(BooleanAnd2)
337
+ else
338
+ @index = i0
339
+ r0 = nil
340
+ end
341
+
342
+ node_cache[:boolean_and][start_index] = r0
343
+
344
+ r0
345
+ end
346
+
347
+ module Comparison0
348
+ def lhs
349
+ elements[0]
350
+ end
351
+
352
+ def space1
353
+ elements[1]
354
+ end
355
+
356
+ def operator
357
+ elements[2]
358
+ end
359
+
360
+ def space2
361
+ elements[3]
362
+ end
363
+
364
+ def rhs
365
+ elements[4]
366
+ end
367
+
368
+ def space3
369
+ elements[5]
370
+ end
371
+ end
372
+
373
+ module Comparison1
374
+ def value(ctx:)
375
+ case operator.text_value
376
+ when 'in'
377
+ return rhs.value(ctx: ctx).include?(lhs.value(ctx: ctx))
378
+ when '<='
379
+ return lhs.value(ctx: ctx) <= rhs.value(ctx: ctx)
380
+ when '<'
381
+ return lhs.value(ctx: ctx) < rhs.value(ctx: ctx)
382
+ when '>='
383
+ return lhs.value(ctx: ctx) >= rhs.value(ctx: ctx)
384
+ when '>'
385
+ return lhs.value(ctx: ctx) > rhs.value(ctx: ctx)
386
+ when '=='
387
+ return lhs.value(ctx: ctx) == rhs.value(ctx: ctx)
388
+ when '!='
389
+ return lhs.value(ctx: ctx) != rhs.value(ctx: ctx)
390
+ when '=~'
391
+ expression = Regexp.new rhs.value(ctx: ctx)
392
+ return !(lhs.value(ctx: ctx) =~ expression).nil?
393
+ end
394
+ end
395
+ end
396
+
397
+ def _nt_comparison
398
+ start_index = index
399
+ if node_cache[:comparison].has_key?(index)
400
+ cached = node_cache[:comparison][index]
401
+ if cached
402
+ node_cache[:comparison][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
403
+ @index = cached.interval.end
404
+ end
405
+ return cached
406
+ end
407
+
408
+ i0, s0 = index, []
409
+ r1 = _nt_additive
410
+ s0 << r1
411
+ if r1
412
+ r2 = _nt_space
413
+ s0 << r2
414
+ if r2
415
+ i3 = index
416
+ if (match_len = has_terminal?('in', false, index))
417
+ r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
418
+ @index += match_len
419
+ else
420
+ terminal_parse_failure('\'in\'')
421
+ r4 = nil
422
+ end
423
+ if r4
424
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
425
+ r3 = r4
426
+ else
427
+ if (match_len = has_terminal?('<=', false, index))
428
+ r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
429
+ @index += match_len
430
+ else
431
+ terminal_parse_failure('\'<=\'')
432
+ r5 = nil
433
+ end
434
+ if r5
435
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
436
+ r3 = r5
437
+ else
438
+ if (match_len = has_terminal?('<', false, index))
439
+ r6 = true
440
+ @index += match_len
441
+ else
442
+ terminal_parse_failure('\'<\'')
443
+ r6 = nil
444
+ end
445
+ if r6
446
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
447
+ r3 = r6
448
+ else
449
+ if (match_len = has_terminal?('>=', false, index))
450
+ r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
451
+ @index += match_len
452
+ else
453
+ terminal_parse_failure('\'>=\'')
454
+ r7 = nil
455
+ end
456
+ if r7
457
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
458
+ r3 = r7
459
+ else
460
+ if (match_len = has_terminal?('>', false, index))
461
+ r8 = true
462
+ @index += match_len
463
+ else
464
+ terminal_parse_failure('\'>\'')
465
+ r8 = nil
466
+ end
467
+ if r8
468
+ r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
469
+ r3 = r8
470
+ else
471
+ if (match_len = has_terminal?('==', false, index))
472
+ r9 = instantiate_node(SyntaxNode,input, index...(index + match_len))
473
+ @index += match_len
474
+ else
475
+ terminal_parse_failure('\'==\'')
476
+ r9 = nil
477
+ end
478
+ if r9
479
+ r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
480
+ r3 = r9
481
+ else
482
+ if (match_len = has_terminal?('!=', false, index))
483
+ r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
484
+ @index += match_len
485
+ else
486
+ terminal_parse_failure('\'!=\'')
487
+ r10 = nil
488
+ end
489
+ if r10
490
+ r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
491
+ r3 = r10
492
+ else
493
+ if (match_len = has_terminal?('=~', false, index))
494
+ r11 = instantiate_node(SyntaxNode,input, index...(index + match_len))
495
+ @index += match_len
496
+ else
497
+ terminal_parse_failure('\'=~\'')
498
+ r11 = nil
499
+ end
500
+ if r11
501
+ r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
502
+ r3 = r11
503
+ else
504
+ @index = i3
505
+ r3 = nil
506
+ end
507
+ end
508
+ end
509
+ end
510
+ end
511
+ end
512
+ end
513
+ end
514
+ s0 << r3
515
+ if r3
516
+ r12 = _nt_space
517
+ s0 << r12
518
+ if r12
519
+ r13 = _nt_additive
520
+ s0 << r13
521
+ if r13
522
+ r14 = _nt_space
523
+ s0 << r14
524
+ end
525
+ end
526
+ end
527
+ end
528
+ end
529
+ if s0.last
530
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
531
+ r0.extend(Comparison0)
532
+ r0.extend(Comparison1)
533
+ else
534
+ @index = i0
535
+ r0 = nil
536
+ end
537
+
538
+ node_cache[:comparison][start_index] = r0
539
+
540
+ r0
541
+ end
542
+
543
+ module Additive0
544
+ def space1
545
+ elements[0]
546
+ end
547
+
548
+ def operator
549
+ elements[1]
550
+ end
551
+
552
+ def space2
553
+ elements[2]
554
+ end
555
+
556
+ def operand
557
+ elements[3]
558
+ end
559
+ end
560
+
561
+ module Additive1
562
+ def head
563
+ elements[0]
564
+ end
565
+
566
+ def tail
567
+ elements[1]
568
+ end
569
+ end
570
+
571
+ module Additive2
572
+ def value(ctx:)
573
+ base = head.value(ctx: ctx)
574
+ tail.elements.each do |k|
575
+ case k.operator.text_value
576
+ when '+'
577
+ base += k.operand.value(ctx: ctx)
578
+ when '-'
579
+ base -= k.operand.value(ctx: ctx)
580
+ end
581
+ end
582
+
583
+ base
584
+ end
585
+ end
586
+
587
+ def _nt_additive
588
+ start_index = index
589
+ if node_cache[:additive].has_key?(index)
590
+ cached = node_cache[:additive][index]
591
+ if cached
592
+ node_cache[:additive][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
593
+ @index = cached.interval.end
594
+ end
595
+ return cached
596
+ end
597
+
598
+ i0, s0 = index, []
599
+ r1 = _nt_multitive
600
+ s0 << r1
601
+ if r1
602
+ s2, i2 = [], index
603
+ loop do
604
+ i3, s3 = index, []
605
+ r4 = _nt_space
606
+ s3 << r4
607
+ if r4
608
+ i5 = index
609
+ if (match_len = has_terminal?('+', false, index))
610
+ r6 = true
611
+ @index += match_len
612
+ else
613
+ terminal_parse_failure('\'+\'')
614
+ r6 = nil
615
+ end
616
+ if r6
617
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
618
+ r5 = r6
619
+ else
620
+ if (match_len = has_terminal?('-', false, index))
621
+ r7 = true
622
+ @index += match_len
623
+ else
624
+ terminal_parse_failure('\'-\'')
625
+ r7 = nil
626
+ end
627
+ if r7
628
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
629
+ r5 = r7
630
+ else
631
+ @index = i5
632
+ r5 = nil
633
+ end
634
+ end
635
+ s3 << r5
636
+ if r5
637
+ r8 = _nt_space
638
+ s3 << r8
639
+ if r8
640
+ r9 = _nt_multitive
641
+ s3 << r9
642
+ end
643
+ end
644
+ end
645
+ if s3.last
646
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
647
+ r3.extend(Additive0)
648
+ else
649
+ @index = i3
650
+ r3 = nil
651
+ end
652
+ if r3
653
+ s2 << r3
654
+ else
655
+ break
656
+ end
657
+ end
658
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
659
+ s0 << r2
660
+ end
661
+ if s0.last
662
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
663
+ r0.extend(Additive1)
664
+ r0.extend(Additive2)
665
+ else
666
+ @index = i0
667
+ r0 = nil
668
+ end
669
+
670
+ node_cache[:additive][start_index] = r0
671
+
672
+ r0
673
+ end
674
+
675
+ module Multitive0
676
+ def space1
677
+ elements[0]
678
+ end
679
+
680
+ def operator
681
+ elements[1]
682
+ end
683
+
684
+ def space2
685
+ elements[2]
686
+ end
687
+
688
+ def operand
689
+ elements[3]
690
+ end
691
+ end
692
+
693
+ module Multitive1
694
+ def head
695
+ elements[0]
696
+ end
697
+
698
+ def tail
699
+ elements[1]
700
+ end
701
+ end
702
+
703
+ module Multitive2
704
+ def value(ctx:)
705
+ base = head.value(ctx: ctx)
706
+ tail.elements.each do |k|
707
+ case k.operator.text_value
708
+ when '*'
709
+ base *= k.operand.value(ctx: ctx)
710
+ when '/'
711
+ base /= k.operand.value(ctx: ctx)
712
+ end
713
+ end
714
+
715
+ base
716
+ end
717
+ end
718
+
719
+ def _nt_multitive
720
+ start_index = index
721
+ if node_cache[:multitive].has_key?(index)
722
+ cached = node_cache[:multitive][index]
723
+ if cached
724
+ node_cache[:multitive][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
725
+ @index = cached.interval.end
726
+ end
727
+ return cached
728
+ end
729
+
730
+ i0, s0 = index, []
731
+ r1 = _nt_standalone
732
+ s0 << r1
733
+ if r1
734
+ s2, i2 = [], index
735
+ loop do
736
+ i3, s3 = index, []
737
+ r4 = _nt_space
738
+ s3 << r4
739
+ if r4
740
+ i5 = index
741
+ if (match_len = has_terminal?('*', false, index))
742
+ r6 = true
743
+ @index += match_len
744
+ else
745
+ terminal_parse_failure('\'*\'')
746
+ r6 = nil
747
+ end
748
+ if r6
749
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
750
+ r5 = r6
751
+ else
752
+ if (match_len = has_terminal?('/', false, index))
753
+ r7 = true
754
+ @index += match_len
755
+ else
756
+ terminal_parse_failure('\'/\'')
757
+ r7 = nil
758
+ end
759
+ if r7
760
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
761
+ r5 = r7
762
+ else
763
+ @index = i5
764
+ r5 = nil
765
+ end
766
+ end
767
+ s3 << r5
768
+ if r5
769
+ r8 = _nt_space
770
+ s3 << r8
771
+ if r8
772
+ r9 = _nt_standalone
773
+ s3 << r9
774
+ end
775
+ end
776
+ end
777
+ if s3.last
778
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
779
+ r3.extend(Multitive0)
780
+ else
781
+ @index = i3
782
+ r3 = nil
783
+ end
784
+ if r3
785
+ s2 << r3
786
+ else
787
+ break
788
+ end
789
+ end
790
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
791
+ s0 << r2
792
+ end
793
+ if s0.last
794
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
795
+ r0.extend(Multitive1)
796
+ r0.extend(Multitive2)
797
+ else
798
+ @index = i0
799
+ r0 = nil
800
+ end
801
+
802
+ node_cache[:multitive][start_index] = r0
803
+
804
+ r0
805
+ end
806
+
807
+ def _nt_standalone
808
+ start_index = index
809
+ if node_cache[:standalone].has_key?(index)
810
+ cached = node_cache[:standalone][index]
811
+ if cached
812
+ node_cache[:standalone][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
813
+ @index = cached.interval.end
814
+ end
815
+ return cached
816
+ end
817
+
818
+ i0 = index
819
+ r1 = _nt_symbol
820
+ if r1
821
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
822
+ r0 = r1
823
+ else
824
+ r2 = _nt_method_call
825
+ if r2
826
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
827
+ r0 = r2
828
+ else
829
+ r3 = _nt_literals
830
+ if r3
831
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
832
+ r0 = r3
833
+ else
834
+ r4 = _nt_subexpression
835
+ if r4
836
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
837
+ r0 = r4
838
+ else
839
+ @index = i0
840
+ r0 = nil
841
+ end
842
+ end
843
+ end
844
+ end
845
+
846
+ node_cache[:standalone][start_index] = r0
847
+
848
+ r0
849
+ end
850
+
851
+ module Subexpression0
852
+ def expression
853
+ elements[1]
854
+ end
855
+
856
+ end
857
+
858
+ module Subexpression1
859
+ def value(ctx:)
860
+ expression.value(ctx: ctx)
861
+ end
862
+ end
863
+
864
+ def _nt_subexpression
865
+ start_index = index
866
+ if node_cache[:subexpression].has_key?(index)
867
+ cached = node_cache[:subexpression][index]
868
+ if cached
869
+ node_cache[:subexpression][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
870
+ @index = cached.interval.end
871
+ end
872
+ return cached
873
+ end
874
+
875
+ i0, s0 = index, []
876
+ if (match_len = has_terminal?('(', false, index))
877
+ r1 = true
878
+ @index += match_len
879
+ else
880
+ terminal_parse_failure('\'(\'')
881
+ r1 = nil
882
+ end
883
+ s0 << r1
884
+ if r1
885
+ r2 = _nt_expression
886
+ s0 << r2
887
+ if r2
888
+ if (match_len = has_terminal?(')', false, index))
889
+ r3 = true
890
+ @index += match_len
891
+ else
892
+ terminal_parse_failure('\')\'')
893
+ r3 = nil
894
+ end
895
+ s0 << r3
896
+ end
897
+ end
898
+ if s0.last
899
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
900
+ r0.extend(Subexpression0)
901
+ r0.extend(Subexpression1)
902
+ else
903
+ @index = i0
904
+ r0 = nil
905
+ end
906
+
907
+ node_cache[:subexpression][start_index] = r0
908
+
909
+ r0
910
+ end
911
+
912
+ module MethodCall0
913
+ end
914
+
915
+ module MethodCall1
916
+ def space1
917
+ elements[0]
918
+ end
919
+
920
+ def space2
921
+ elements[2]
922
+ end
923
+
924
+ def expression
925
+ elements[3]
926
+ end
927
+ end
928
+
929
+ module MethodCall2
930
+ def arg0
931
+ elements[0]
932
+ end
933
+
934
+ def space
935
+ elements[1]
936
+ end
937
+
938
+ def argN
939
+ elements[2]
940
+ end
941
+ end
942
+
943
+ module MethodCall3
944
+ def root
945
+ elements[0]
946
+ end
947
+
948
+ def space
949
+ elements[2]
950
+ end
951
+
952
+ def args
953
+ elements[3]
954
+ end
955
+
956
+ end
957
+
958
+ module MethodCall4
959
+ def value(ctx:)
960
+ arguments = []
961
+ arguments << args.arg0.value(ctx: ctx) if args.arg0.respond_to?(:value)
962
+ args.argN.elements.each{|argN|
963
+ arguments << argN.elements[3].value(ctx: ctx) if args.arg0.respond_to?(:value)
964
+ }
965
+
966
+ ctx.call(method: root.text_value, args: arguments)
967
+ end
968
+ end
969
+
970
+ def _nt_method_call
971
+ start_index = index
972
+ if node_cache[:method_call].has_key?(index)
973
+ cached = node_cache[:method_call][index]
974
+ if cached
975
+ node_cache[:method_call][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
976
+ @index = cached.interval.end
977
+ end
978
+ return cached
979
+ end
980
+
981
+ i0, s0 = index, []
982
+ i1, s1 = index, []
983
+ if has_terminal?(@regexps[gr = '\A[a-zA-Z]'] ||= Regexp.new(gr), :regexp, index)
984
+ r2 = true
985
+ @index += 1
986
+ else
987
+ terminal_parse_failure('[a-zA-Z]')
988
+ r2 = nil
989
+ end
990
+ s1 << r2
991
+ if r2
992
+ s3, i3 = [], index
993
+ loop do
994
+ if has_terminal?(@regexps[gr = '\A[a-zA-Z0-9_]'] ||= Regexp.new(gr), :regexp, index)
995
+ r4 = true
996
+ @index += 1
997
+ else
998
+ terminal_parse_failure('[a-zA-Z0-9_]')
999
+ r4 = nil
1000
+ end
1001
+ if r4
1002
+ s3 << r4
1003
+ else
1004
+ break
1005
+ end
1006
+ end
1007
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
1008
+ s1 << r3
1009
+ end
1010
+ if s1.last
1011
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
1012
+ r1.extend(MethodCall0)
1013
+ else
1014
+ @index = i1
1015
+ r1 = nil
1016
+ end
1017
+ s0 << r1
1018
+ if r1
1019
+ if (match_len = has_terminal?('(', false, index))
1020
+ r5 = true
1021
+ @index += match_len
1022
+ else
1023
+ terminal_parse_failure('\'(\'')
1024
+ r5 = nil
1025
+ end
1026
+ s0 << r5
1027
+ if r5
1028
+ r6 = _nt_space
1029
+ s0 << r6
1030
+ if r6
1031
+ i8, s8 = index, []
1032
+ r10 = _nt_expression
1033
+ if r10
1034
+ r9 = r10
1035
+ else
1036
+ r9 = instantiate_node(SyntaxNode,input, index...index)
1037
+ end
1038
+ s8 << r9
1039
+ if r9
1040
+ r11 = _nt_space
1041
+ s8 << r11
1042
+ if r11
1043
+ s12, i12 = [], index
1044
+ loop do
1045
+ i13, s13 = index, []
1046
+ r14 = _nt_space
1047
+ s13 << r14
1048
+ if r14
1049
+ if (match_len = has_terminal?(',', false, index))
1050
+ r15 = true
1051
+ @index += match_len
1052
+ else
1053
+ terminal_parse_failure('\',\'')
1054
+ r15 = nil
1055
+ end
1056
+ s13 << r15
1057
+ if r15
1058
+ r16 = _nt_space
1059
+ s13 << r16
1060
+ if r16
1061
+ r17 = _nt_expression
1062
+ s13 << r17
1063
+ end
1064
+ end
1065
+ end
1066
+ if s13.last
1067
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1068
+ r13.extend(MethodCall1)
1069
+ else
1070
+ @index = i13
1071
+ r13 = nil
1072
+ end
1073
+ if r13
1074
+ s12 << r13
1075
+ else
1076
+ break
1077
+ end
1078
+ end
1079
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
1080
+ s8 << r12
1081
+ end
1082
+ end
1083
+ if s8.last
1084
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
1085
+ r8.extend(MethodCall2)
1086
+ else
1087
+ @index = i8
1088
+ r8 = nil
1089
+ end
1090
+ if r8
1091
+ r7 = r8
1092
+ else
1093
+ r7 = instantiate_node(SyntaxNode,input, index...index)
1094
+ end
1095
+ s0 << r7
1096
+ if r7
1097
+ if (match_len = has_terminal?(')', false, index))
1098
+ r18 = true
1099
+ @index += match_len
1100
+ else
1101
+ terminal_parse_failure('\')\'')
1102
+ r18 = nil
1103
+ end
1104
+ s0 << r18
1105
+ end
1106
+ end
1107
+ end
1108
+ end
1109
+ if s0.last
1110
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1111
+ r0.extend(MethodCall3)
1112
+ r0.extend(MethodCall4)
1113
+ else
1114
+ @index = i0
1115
+ r0 = nil
1116
+ end
1117
+
1118
+ node_cache[:method_call][start_index] = r0
1119
+
1120
+ r0
1121
+ end
1122
+
1123
+ def _nt_literals
1124
+ start_index = index
1125
+ if node_cache[:literals].has_key?(index)
1126
+ cached = node_cache[:literals][index]
1127
+ if cached
1128
+ node_cache[:literals][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1129
+ @index = cached.interval.end
1130
+ end
1131
+ return cached
1132
+ end
1133
+
1134
+ i0 = index
1135
+ r1 = _nt_array_literal
1136
+ if r1
1137
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
1138
+ r0 = r1
1139
+ else
1140
+ r2 = _nt_nil_literal
1141
+ if r2
1142
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
1143
+ r0 = r2
1144
+ else
1145
+ r3 = _nt_boolean_literal
1146
+ if r3
1147
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
1148
+ r0 = r3
1149
+ else
1150
+ r4 = _nt_string_literal
1151
+ if r4
1152
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
1153
+ r0 = r4
1154
+ else
1155
+ r5 = _nt_range_literal
1156
+ if r5
1157
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
1158
+ r0 = r5
1159
+ else
1160
+ r6 = _nt_numeric_literal
1161
+ if r6
1162
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
1163
+ r0 = r6
1164
+ else
1165
+ @index = i0
1166
+ r0 = nil
1167
+ end
1168
+ end
1169
+ end
1170
+ end
1171
+ end
1172
+ end
1173
+
1174
+ node_cache[:literals][start_index] = r0
1175
+
1176
+ r0
1177
+ end
1178
+
1179
+ module StringLiteral0
1180
+ end
1181
+
1182
+ module StringLiteral1
1183
+ def string
1184
+ elements[1]
1185
+ end
1186
+
1187
+ end
1188
+
1189
+ module StringLiteral2
1190
+ def value(ctx:)
1191
+ string.text_value
1192
+ end
1193
+ end
1194
+
1195
+ def _nt_string_literal
1196
+ start_index = index
1197
+ if node_cache[:string_literal].has_key?(index)
1198
+ cached = node_cache[:string_literal][index]
1199
+ if cached
1200
+ node_cache[:string_literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1201
+ @index = cached.interval.end
1202
+ end
1203
+ return cached
1204
+ end
1205
+
1206
+ i0, s0 = index, []
1207
+ if (match_len = has_terminal?('"', false, index))
1208
+ r1 = true
1209
+ @index += match_len
1210
+ else
1211
+ terminal_parse_failure('\'"\'')
1212
+ r1 = nil
1213
+ end
1214
+ s0 << r1
1215
+ if r1
1216
+ s2, i2 = [], index
1217
+ loop do
1218
+ i3, s3 = index, []
1219
+ i4 = index
1220
+ if (match_len = has_terminal?('"', false, index))
1221
+ r5 = true
1222
+ @index += match_len
1223
+ else
1224
+ terminal_parse_failure('\'"\'')
1225
+ r5 = nil
1226
+ end
1227
+ if r5
1228
+ @index = i4
1229
+ r4 = nil
1230
+ terminal_parse_failure('\'"\'', true)
1231
+ else
1232
+ @terminal_failures.pop
1233
+ @index = i4
1234
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1235
+ end
1236
+ s3 << r4
1237
+ if r4
1238
+ if index < input_length
1239
+ r6 = true
1240
+ @index += 1
1241
+ else
1242
+ terminal_parse_failure("any character")
1243
+ r6 = nil
1244
+ end
1245
+ s3 << r6
1246
+ end
1247
+ if s3.last
1248
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
1249
+ r3.extend(StringLiteral0)
1250
+ else
1251
+ @index = i3
1252
+ r3 = nil
1253
+ end
1254
+ if r3
1255
+ s2 << r3
1256
+ else
1257
+ break
1258
+ end
1259
+ end
1260
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1261
+ s0 << r2
1262
+ if r2
1263
+ if (match_len = has_terminal?('"', false, index))
1264
+ r7 = true
1265
+ @index += match_len
1266
+ else
1267
+ terminal_parse_failure('\'"\'')
1268
+ r7 = nil
1269
+ end
1270
+ s0 << r7
1271
+ end
1272
+ end
1273
+ if s0.last
1274
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1275
+ r0.extend(StringLiteral1)
1276
+ r0.extend(StringLiteral2)
1277
+ else
1278
+ @index = i0
1279
+ r0 = nil
1280
+ end
1281
+
1282
+ node_cache[:string_literal][start_index] = r0
1283
+
1284
+ r0
1285
+ end
1286
+
1287
+ module NumericLiteral0
1288
+ end
1289
+
1290
+ module NumericLiteral1
1291
+ end
1292
+
1293
+ module NumericLiteral2
1294
+ def numeric
1295
+ elements[0]
1296
+ end
1297
+ end
1298
+
1299
+ module NumericLiteral3
1300
+ def value(ctx:)
1301
+ numeric.text_value.to_f
1302
+ end
1303
+ end
1304
+
1305
+ def _nt_numeric_literal
1306
+ start_index = index
1307
+ if node_cache[:numeric_literal].has_key?(index)
1308
+ cached = node_cache[:numeric_literal][index]
1309
+ if cached
1310
+ node_cache[:numeric_literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1311
+ @index = cached.interval.end
1312
+ end
1313
+ return cached
1314
+ end
1315
+
1316
+ i0, s0 = index, []
1317
+ i1, s1 = index, []
1318
+ if (match_len = has_terminal?('-', false, index))
1319
+ r3 = true
1320
+ @index += match_len
1321
+ else
1322
+ terminal_parse_failure('\'-\'')
1323
+ r3 = nil
1324
+ end
1325
+ if r3
1326
+ r2 = r3
1327
+ else
1328
+ r2 = instantiate_node(SyntaxNode,input, index...index)
1329
+ end
1330
+ s1 << r2
1331
+ if r2
1332
+ s4, i4 = [], index
1333
+ loop do
1334
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
1335
+ r5 = true
1336
+ @index += 1
1337
+ else
1338
+ terminal_parse_failure('[0-9]')
1339
+ r5 = nil
1340
+ end
1341
+ if r5
1342
+ s4 << r5
1343
+ else
1344
+ break
1345
+ end
1346
+ end
1347
+ if s4.empty?
1348
+ @index = i4
1349
+ r4 = nil
1350
+ else
1351
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1352
+ end
1353
+ s1 << r4
1354
+ if r4
1355
+ i7, s7 = index, []
1356
+ if (match_len = has_terminal?('.', false, index))
1357
+ r8 = true
1358
+ @index += match_len
1359
+ else
1360
+ terminal_parse_failure('\'.\'')
1361
+ r8 = nil
1362
+ end
1363
+ s7 << r8
1364
+ if r8
1365
+ s9, i9 = [], index
1366
+ loop do
1367
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
1368
+ r10 = true
1369
+ @index += 1
1370
+ else
1371
+ terminal_parse_failure('[0-9]')
1372
+ r10 = nil
1373
+ end
1374
+ if r10
1375
+ s9 << r10
1376
+ else
1377
+ break
1378
+ end
1379
+ end
1380
+ if s9.empty?
1381
+ @index = i9
1382
+ r9 = nil
1383
+ else
1384
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
1385
+ end
1386
+ s7 << r9
1387
+ end
1388
+ if s7.last
1389
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1390
+ r7.extend(NumericLiteral0)
1391
+ else
1392
+ @index = i7
1393
+ r7 = nil
1394
+ end
1395
+ if r7
1396
+ r6 = r7
1397
+ else
1398
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1399
+ end
1400
+ s1 << r6
1401
+ end
1402
+ end
1403
+ if s1.last
1404
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
1405
+ r1.extend(NumericLiteral1)
1406
+ else
1407
+ @index = i1
1408
+ r1 = nil
1409
+ end
1410
+ s0 << r1
1411
+ if s0.last
1412
+ r0 = instantiate_node(NumericLiteral,input, i0...index, s0)
1413
+ r0.extend(NumericLiteral2)
1414
+ r0.extend(NumericLiteral3)
1415
+ else
1416
+ @index = i0
1417
+ r0 = nil
1418
+ end
1419
+
1420
+ node_cache[:numeric_literal][start_index] = r0
1421
+
1422
+ r0
1423
+ end
1424
+
1425
+ module BooleanLiteral0
1426
+ def boolean
1427
+ elements[0]
1428
+ end
1429
+ end
1430
+
1431
+ module BooleanLiteral1
1432
+ def value(ctx:)
1433
+ boolean.text_value == "true"
1434
+ end
1435
+ end
1436
+
1437
+ def _nt_boolean_literal
1438
+ start_index = index
1439
+ if node_cache[:boolean_literal].has_key?(index)
1440
+ cached = node_cache[:boolean_literal][index]
1441
+ if cached
1442
+ node_cache[:boolean_literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1443
+ @index = cached.interval.end
1444
+ end
1445
+ return cached
1446
+ end
1447
+
1448
+ i0, s0 = index, []
1449
+ i1 = index
1450
+ if (match_len = has_terminal?("true", false, index))
1451
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
1452
+ @index += match_len
1453
+ else
1454
+ terminal_parse_failure('"true"')
1455
+ r2 = nil
1456
+ end
1457
+ if r2
1458
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
1459
+ r1 = r2
1460
+ else
1461
+ if (match_len = has_terminal?("false", false, index))
1462
+ r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
1463
+ @index += match_len
1464
+ else
1465
+ terminal_parse_failure('"false"')
1466
+ r3 = nil
1467
+ end
1468
+ if r3
1469
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
1470
+ r1 = r3
1471
+ else
1472
+ @index = i1
1473
+ r1 = nil
1474
+ end
1475
+ end
1476
+ s0 << r1
1477
+ if s0.last
1478
+ r0 = instantiate_node(BooleanLiteral,input, i0...index, s0)
1479
+ r0.extend(BooleanLiteral0)
1480
+ r0.extend(BooleanLiteral1)
1481
+ else
1482
+ @index = i0
1483
+ r0 = nil
1484
+ end
1485
+
1486
+ node_cache[:boolean_literal][start_index] = r0
1487
+
1488
+ r0
1489
+ end
1490
+
1491
+ module NilLiteral0
1492
+ def nil
1493
+ elements[0]
1494
+ end
1495
+ end
1496
+
1497
+ module NilLiteral1
1498
+ def value(ctx:)
1499
+ nil
1500
+ end
1501
+ end
1502
+
1503
+ def _nt_nil_literal
1504
+ start_index = index
1505
+ if node_cache[:nil_literal].has_key?(index)
1506
+ cached = node_cache[:nil_literal][index]
1507
+ if cached
1508
+ node_cache[:nil_literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1509
+ @index = cached.interval.end
1510
+ end
1511
+ return cached
1512
+ end
1513
+
1514
+ i0, s0 = index, []
1515
+ i1 = index
1516
+ if (match_len = has_terminal?('nil', false, index))
1517
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
1518
+ @index += match_len
1519
+ else
1520
+ terminal_parse_failure('\'nil\'')
1521
+ r2 = nil
1522
+ end
1523
+ if r2
1524
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
1525
+ r1 = r2
1526
+ else
1527
+ if (match_len = has_terminal?('null', false, index))
1528
+ r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
1529
+ @index += match_len
1530
+ else
1531
+ terminal_parse_failure('\'null\'')
1532
+ r3 = nil
1533
+ end
1534
+ if r3
1535
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
1536
+ r1 = r3
1537
+ else
1538
+ @index = i1
1539
+ r1 = nil
1540
+ end
1541
+ end
1542
+ s0 << r1
1543
+ if s0.last
1544
+ r0 = instantiate_node(NilLiteral,input, i0...index, s0)
1545
+ r0.extend(NilLiteral0)
1546
+ r0.extend(NilLiteral1)
1547
+ else
1548
+ @index = i0
1549
+ r0 = nil
1550
+ end
1551
+
1552
+ node_cache[:nil_literal][start_index] = r0
1553
+
1554
+ r0
1555
+ end
1556
+
1557
+ module ArrayLiteral0
1558
+ def space1
1559
+ elements[0]
1560
+ end
1561
+
1562
+ def space2
1563
+ elements[2]
1564
+ end
1565
+
1566
+ def element
1567
+ elements[3]
1568
+ end
1569
+ end
1570
+
1571
+ module ArrayLiteral1
1572
+ def elem0
1573
+ elements[0]
1574
+ end
1575
+
1576
+ def space
1577
+ elements[1]
1578
+ end
1579
+
1580
+ def elemN
1581
+ elements[2]
1582
+ end
1583
+ end
1584
+
1585
+ module ArrayLiteral2
1586
+ def space1
1587
+ elements[1]
1588
+ end
1589
+
1590
+ def space2
1591
+ elements[2]
1592
+ end
1593
+
1594
+ def elems
1595
+ elements[3]
1596
+ end
1597
+
1598
+ end
1599
+
1600
+ module ArrayLiteral3
1601
+ def value(ctx:)
1602
+ elements = []
1603
+ elements << elems.elem0.value(ctx: ctx) if elems.elem0.respond_to?(:value)
1604
+ elems.elemN.elements.each{|elemN|
1605
+ elements << elemN.element.value(ctx: ctx)
1606
+ }
1607
+
1608
+ elements
1609
+ end
1610
+ end
1611
+
1612
+ def _nt_array_literal
1613
+ start_index = index
1614
+ if node_cache[:array_literal].has_key?(index)
1615
+ cached = node_cache[:array_literal][index]
1616
+ if cached
1617
+ node_cache[:array_literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1618
+ @index = cached.interval.end
1619
+ end
1620
+ return cached
1621
+ end
1622
+
1623
+ i0, s0 = index, []
1624
+ if (match_len = has_terminal?('[', false, index))
1625
+ r1 = true
1626
+ @index += match_len
1627
+ else
1628
+ terminal_parse_failure('\'[\'')
1629
+ r1 = nil
1630
+ end
1631
+ s0 << r1
1632
+ if r1
1633
+ r2 = _nt_space
1634
+ s0 << r2
1635
+ if r2
1636
+ r3 = _nt_space
1637
+ s0 << r3
1638
+ if r3
1639
+ i5, s5 = index, []
1640
+ r7 = _nt_standalone
1641
+ if r7
1642
+ r6 = r7
1643
+ else
1644
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1645
+ end
1646
+ s5 << r6
1647
+ if r6
1648
+ r8 = _nt_space
1649
+ s5 << r8
1650
+ if r8
1651
+ s9, i9 = [], index
1652
+ loop do
1653
+ i10, s10 = index, []
1654
+ r11 = _nt_space
1655
+ s10 << r11
1656
+ if r11
1657
+ if (match_len = has_terminal?(',', false, index))
1658
+ r12 = true
1659
+ @index += match_len
1660
+ else
1661
+ terminal_parse_failure('\',\'')
1662
+ r12 = nil
1663
+ end
1664
+ s10 << r12
1665
+ if r12
1666
+ r13 = _nt_space
1667
+ s10 << r13
1668
+ if r13
1669
+ r14 = _nt_standalone
1670
+ s10 << r14
1671
+ end
1672
+ end
1673
+ end
1674
+ if s10.last
1675
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
1676
+ r10.extend(ArrayLiteral0)
1677
+ else
1678
+ @index = i10
1679
+ r10 = nil
1680
+ end
1681
+ if r10
1682
+ s9 << r10
1683
+ else
1684
+ break
1685
+ end
1686
+ end
1687
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
1688
+ s5 << r9
1689
+ end
1690
+ end
1691
+ if s5.last
1692
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
1693
+ r5.extend(ArrayLiteral1)
1694
+ else
1695
+ @index = i5
1696
+ r5 = nil
1697
+ end
1698
+ if r5
1699
+ r4 = r5
1700
+ else
1701
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1702
+ end
1703
+ s0 << r4
1704
+ if r4
1705
+ if (match_len = has_terminal?(']', false, index))
1706
+ r15 = true
1707
+ @index += match_len
1708
+ else
1709
+ terminal_parse_failure('\']\'')
1710
+ r15 = nil
1711
+ end
1712
+ s0 << r15
1713
+ end
1714
+ end
1715
+ end
1716
+ end
1717
+ if s0.last
1718
+ r0 = instantiate_node(ArrayLiteral,input, i0...index, s0)
1719
+ r0.extend(ArrayLiteral2)
1720
+ r0.extend(ArrayLiteral3)
1721
+ else
1722
+ @index = i0
1723
+ r0 = nil
1724
+ end
1725
+
1726
+ node_cache[:array_literal][start_index] = r0
1727
+
1728
+ r0
1729
+ end
1730
+
1731
+ module RangeLiteral0
1732
+ def start
1733
+ elements[0]
1734
+ end
1735
+
1736
+ def operator
1737
+ elements[1]
1738
+ end
1739
+
1740
+ def ending
1741
+ elements[2]
1742
+ end
1743
+ end
1744
+
1745
+ module RangeLiteral1
1746
+ def value(ctx:)
1747
+ Range.new(start.text_value.to_i, ending.text_value.to_i)
1748
+ end
1749
+ end
1750
+
1751
+ def _nt_range_literal
1752
+ start_index = index
1753
+ if node_cache[:range_literal].has_key?(index)
1754
+ cached = node_cache[:range_literal][index]
1755
+ if cached
1756
+ node_cache[:range_literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1757
+ @index = cached.interval.end
1758
+ end
1759
+ return cached
1760
+ end
1761
+
1762
+ i0, s0 = index, []
1763
+ r1 = _nt_numeric_literal
1764
+ s0 << r1
1765
+ if r1
1766
+ if (match_len = has_terminal?('..', false, index))
1767
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
1768
+ @index += match_len
1769
+ else
1770
+ terminal_parse_failure('\'..\'')
1771
+ r2 = nil
1772
+ end
1773
+ s0 << r2
1774
+ if r2
1775
+ r3 = _nt_numeric_literal
1776
+ s0 << r3
1777
+ end
1778
+ end
1779
+ if s0.last
1780
+ r0 = instantiate_node(RangeLiteral,input, i0...index, s0)
1781
+ r0.extend(RangeLiteral0)
1782
+ r0.extend(RangeLiteral1)
1783
+ else
1784
+ @index = i0
1785
+ r0 = nil
1786
+ end
1787
+
1788
+ node_cache[:range_literal][start_index] = r0
1789
+
1790
+ r0
1791
+ end
1792
+
1793
+ module Symbol0
1794
+ end
1795
+
1796
+ module Symbol1
1797
+ end
1798
+
1799
+ module Symbol2
1800
+ def root
1801
+ elements[1]
1802
+ end
1803
+
1804
+ def path
1805
+ elements[2]
1806
+ end
1807
+ end
1808
+
1809
+ module Symbol3
1810
+ def value(ctx:)
1811
+ ctx.get(identifier: root.text_value, path: path.elements)
1812
+ end
1813
+ end
1814
+
1815
+ def _nt_symbol
1816
+ start_index = index
1817
+ if node_cache[:symbol].has_key?(index)
1818
+ cached = node_cache[:symbol][index]
1819
+ if cached
1820
+ node_cache[:symbol][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1821
+ @index = cached.interval.end
1822
+ end
1823
+ return cached
1824
+ end
1825
+
1826
+ i0, s0 = index, []
1827
+ if (match_len = has_terminal?('$', false, index))
1828
+ r1 = true
1829
+ @index += match_len
1830
+ else
1831
+ terminal_parse_failure('\'$\'')
1832
+ r1 = nil
1833
+ end
1834
+ s0 << r1
1835
+ if r1
1836
+ i2, s2 = index, []
1837
+ if has_terminal?(@regexps[gr = '\A[a-zA-Z]'] ||= Regexp.new(gr), :regexp, index)
1838
+ r3 = true
1839
+ @index += 1
1840
+ else
1841
+ terminal_parse_failure('[a-zA-Z]')
1842
+ r3 = nil
1843
+ end
1844
+ s2 << r3
1845
+ if r3
1846
+ s4, i4 = [], index
1847
+ loop do
1848
+ if has_terminal?(@regexps[gr = '\A[a-zA-Z0-9_]'] ||= Regexp.new(gr), :regexp, index)
1849
+ r5 = true
1850
+ @index += 1
1851
+ else
1852
+ terminal_parse_failure('[a-zA-Z0-9_]')
1853
+ r5 = nil
1854
+ end
1855
+ if r5
1856
+ s4 << r5
1857
+ else
1858
+ break
1859
+ end
1860
+ end
1861
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1862
+ s2 << r4
1863
+ end
1864
+ if s2.last
1865
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1866
+ r2.extend(Symbol0)
1867
+ else
1868
+ @index = i2
1869
+ r2 = nil
1870
+ end
1871
+ s0 << r2
1872
+ if r2
1873
+ s6, i6 = [], index
1874
+ loop do
1875
+ i7, s7 = index, []
1876
+ if (match_len = has_terminal?('.', false, index))
1877
+ r8 = true
1878
+ @index += match_len
1879
+ else
1880
+ terminal_parse_failure('\'.\'')
1881
+ r8 = nil
1882
+ end
1883
+ s7 << r8
1884
+ if r8
1885
+ s9, i9 = [], index
1886
+ loop do
1887
+ if has_terminal?(@regexps[gr = '\A[a-zA-Z0-9_]'] ||= Regexp.new(gr), :regexp, index)
1888
+ r10 = true
1889
+ @index += 1
1890
+ else
1891
+ terminal_parse_failure('[a-zA-Z0-9_]')
1892
+ r10 = nil
1893
+ end
1894
+ if r10
1895
+ s9 << r10
1896
+ else
1897
+ break
1898
+ end
1899
+ end
1900
+ if s9.empty?
1901
+ @index = i9
1902
+ r9 = nil
1903
+ else
1904
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
1905
+ end
1906
+ s7 << r9
1907
+ end
1908
+ if s7.last
1909
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1910
+ r7.extend(Symbol1)
1911
+ else
1912
+ @index = i7
1913
+ r7 = nil
1914
+ end
1915
+ if r7
1916
+ s6 << r7
1917
+ else
1918
+ break
1919
+ end
1920
+ end
1921
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
1922
+ s0 << r6
1923
+ end
1924
+ end
1925
+ if s0.last
1926
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1927
+ r0.extend(Symbol2)
1928
+ r0.extend(Symbol3)
1929
+ else
1930
+ @index = i0
1931
+ r0 = nil
1932
+ end
1933
+
1934
+ node_cache[:symbol][start_index] = r0
1935
+
1936
+ r0
1937
+ end
1938
+
1939
+ def _nt_space
1940
+ start_index = index
1941
+ if node_cache[:space].has_key?(index)
1942
+ cached = node_cache[:space][index]
1943
+ if cached
1944
+ node_cache[:space][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1945
+ @index = cached.interval.end
1946
+ end
1947
+ return cached
1948
+ end
1949
+
1950
+ s0, i0 = [], index
1951
+ loop do
1952
+ if has_terminal?(@regexps[gr = '\A[ \\t\\n\\r]'] ||= Regexp.new(gr), :regexp, index)
1953
+ r1 = true
1954
+ @index += 1
1955
+ else
1956
+ terminal_parse_failure('[ \\t\\n\\r]')
1957
+ r1 = nil
1958
+ end
1959
+ if r1
1960
+ s0 << r1
1961
+ else
1962
+ break
1963
+ end
1964
+ end
1965
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1966
+
1967
+ node_cache[:space][start_index] = r0
1968
+
1969
+ r0
1970
+ end
1971
+
1972
+ end
1973
+
1974
+ class EquationParser < Treetop::Runtime::CompiledParser
1975
+ include Equation
1976
+ end
1977
+