-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatementLexer.rb
1319 lines (894 loc) · 27.4 KB
/
StatementLexer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
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
#!/usr/bin/env ruby
#
# Statement.g
# --
# Generated using ANTLR version: 3.5
# Ruby runtime library version: 1.10.0
# Input grammar file: Statement.g
# Generated at: 2014-10-07 12:11:50
#
# ~~~> start load path setup
this_directory = File.expand_path( File.dirname( __FILE__ ) )
$LOAD_PATH.unshift( this_directory ) unless $LOAD_PATH.include?( this_directory )
antlr_load_failed = proc do
load_path = $LOAD_PATH.map { |dir| ' - ' << dir }.join( $/ )
raise LoadError, <<-END.strip!
Failed to load the ANTLR3 runtime library (version 1.10.0):
Ensure the library has been installed on your system and is available
on the load path. If rubygems is available on your system, this can
be done with the command:
gem install antlr3
Current load path:
#{ load_path }
END
end
defined?( ANTLR3 ) or begin
# 1: try to load the ruby antlr3 runtime library from the system path
require 'antlr3'
rescue LoadError
# 2: try to load rubygems if it isn't already loaded
defined?( Gem ) or begin
require 'rubygems'
rescue LoadError
antlr_load_failed.call
end
# 3: try to activate the antlr3 gem
begin
defined?( gem ) and gem( 'antlr3', '~> 1.10.0' )
rescue Gem::LoadError
antlr_load_failed.call
end
require 'antlr3'
end
# <~~~ end load path setup
module Statement
# TokenData defines all of the token type integer values
# as constants, which will be included in all
# ANTLR-generated recognizers.
const_defined?( :TokenData ) or TokenData = ANTLR3::TokenScheme.new
module TokenData
# define the token constants
define_tokens( :EOF => -1, :T__11 => 11, :T__12 => 12, :T__13 => 13,
:T__14 => 14, :T__15 => 15, :T__16 => 16, :T__17 => 17,
:T__18 => 18, :T__19 => 19, :T__20 => 20, :T__21 => 21,
:T__22 => 22, :T__23 => 23, :T__24 => 24, :T__25 => 25,
:T__26 => 26, :T__27 => 27, :T__28 => 28, :DIGIT => 4,
:INT => 5, :NEWLINE => 6, :NUMBER => 7, :SPACE => 8,
:STRING => 9, :VARIABLE => 10 )
end
class Lexer < ANTLR3::Lexer
@grammar_home = Statement
include TokenData
begin
generated_using( "Statement.g", "3.5", "1.10.0" )
rescue NoMethodError => error
# ignore
end
RULE_NAMES = [ "T__11", "T__12", "T__13", "T__14", "T__15", "T__16",
"T__17", "T__18", "T__19", "T__20", "T__21", "T__22",
"T__23", "T__24", "T__25", "T__26", "T__27", "T__28",
"NEWLINE", "SPACE", "STRING", "NUMBER", "INT", "VARIABLE",
"DIGIT" ].freeze
RULE_METHODS = [ :t__11!, :t__12!, :t__13!, :t__14!, :t__15!, :t__16!,
:t__17!, :t__18!, :t__19!, :t__20!, :t__21!, :t__22!,
:t__23!, :t__24!, :t__25!, :t__26!, :t__27!, :t__28!,
:newline!, :space!, :string!, :number!, :int!, :variable!,
:digit! ].freeze
def initialize( input=nil, options = {} )
super( input, options )
end
# - - - - - - - - - - - lexer rules - - - - - - - - - - - -
# lexer rule t__11! (T__11)
# (in Statement.g)
def t__11!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 1 )
type = T__11
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 7:9: ')'
match( 0x29 )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 1 )
end
# lexer rule t__12! (T__12)
# (in Statement.g)
def t__12!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 2 )
type = T__12
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 8:9: ','
match( 0x2c )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 2 )
end
# lexer rule t__13! (T__13)
# (in Statement.g)
def t__13!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 3 )
type = T__13
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 9:9: '['
match( 0x5b )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 3 )
end
# lexer rule t__14! (T__14)
# (in Statement.g)
def t__14!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 4 )
type = T__14
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 10:9: ']'
match( 0x5d )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 4 )
end
# lexer rule t__15! (T__15)
# (in Statement.g)
def t__15!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 5 )
type = T__15
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 11:9: 'and('
match( "and(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 5 )
end
# lexer rule t__16! (T__16)
# (in Statement.g)
def t__16!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 6 )
type = T__16
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 12:9: 'between('
match( "between(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 6 )
end
# lexer rule t__17! (T__17)
# (in Statement.g)
def t__17!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 7 )
type = T__17
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 13:9: 'else'
match( "else" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 7 )
end
# lexer rule t__18! (T__18)
# (in Statement.g)
def t__18!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 8 )
type = T__18
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 14:9: 'elsif'
match( "elsif" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 8 )
end
# lexer rule t__19! (T__19)
# (in Statement.g)
def t__19!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 9 )
type = T__19
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 15:9: 'equal('
match( "equal(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 9 )
end
# lexer rule t__20! (T__20)
# (in Statement.g)
def t__20!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 10 )
type = T__20
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 16:9: 'greaterThan('
match( "greaterThan(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 10 )
end
# lexer rule t__21! (T__21)
# (in Statement.g)
def t__21!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 11 )
type = T__21
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 17:9: 'greaterThanEqual('
match( "greaterThanEqual(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 11 )
end
# lexer rule t__22! (T__22)
# (in Statement.g)
def t__22!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 12 )
type = T__22
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 18:9: 'if'
match( "if" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 12 )
end
# lexer rule t__23! (T__23)
# (in Statement.g)
def t__23!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 13 )
type = T__23
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 19:9: 'in('
match( "in(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 13 )
end
# lexer rule t__24! (T__24)
# (in Statement.g)
def t__24!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 14 )
type = T__24
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 20:9: 'lessThan('
match( "lessThan(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 14 )
end
# lexer rule t__25! (T__25)
# (in Statement.g)
def t__25!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 15 )
type = T__25
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 21:9: 'lessThanEqual('
match( "lessThanEqual(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 15 )
end
# lexer rule t__26! (T__26)
# (in Statement.g)
def t__26!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 16 )
type = T__26
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 22:9: 'not('
match( "not(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 16 )
end
# lexer rule t__27! (T__27)
# (in Statement.g)
def t__27!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 17 )
type = T__27
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 23:9: 'or('
match( "or(" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 17 )
end
# lexer rule t__28! (T__28)
# (in Statement.g)
def t__28!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 18 )
type = T__28
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 24:9: 'then'
match( "then" )
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 18 )
end
# lexer rule newline! (NEWLINE)
# (in Statement.g)
def newline!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 19 )
type = NEWLINE
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 90:15: '\\n'
match( 0xa )
# --> action
channel = HIDDEN
# <-- action
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 19 )
end
# lexer rule space! (SPACE)
# (in Statement.g)
def space!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 20 )
type = SPACE
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 91:15: ( ' ' )+
# at file 91:15: ( ' ' )+
match_count_1 = 0
while true
alt_1 = 2
look_1_0 = @input.peek( 1 )
if ( look_1_0 == 0x20 )
alt_1 = 1
end
case alt_1
when 1
# at line 91:15: ' '
match( 0x20 )
else
match_count_1 > 0 and break
eee = EarlyExit(1)
raise eee
end
match_count_1 += 1
end
# --> action
channel = HIDDEN
# <-- action
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 20 )
end
# lexer rule string! (STRING)
# (in Statement.g)
def string!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 21 )
type = STRING
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 92:13: ( '\\'' (~ ( '\\'' ) )* '\\'' | '\\\"' (~ ( '\\\"' ) )* '\\\"' )
alt_4 = 2
look_4_0 = @input.peek( 1 )
if ( look_4_0 == 0x27 )
alt_4 = 1
elsif ( look_4_0 == 0x22 )
alt_4 = 2
else
raise NoViableAlternative( "", 4, 0 )
end
case alt_4
when 1
# at line 92:15: '\\'' (~ ( '\\'' ) )* '\\''
match( 0x27 )
# at line 92:20: (~ ( '\\'' ) )*
while true # decision 2
alt_2 = 2
look_2_0 = @input.peek( 1 )
if ( look_2_0.between?( 0x0, 0x26 ) || look_2_0.between?( 0x28, 0xffff ) )
alt_2 = 1
end
case alt_2
when 1
# at line
if @input.peek( 1 ).between?( 0x0, 0x26 ) || @input.peek( 1 ).between?( 0x28, 0xffff )
@input.consume
else
mse = MismatchedSet( nil )
recover mse
raise mse
end
else
break # out of loop for decision 2
end
end # loop for decision 2
match( 0x27 )
when 2
# at line 93:15: '\\\"' (~ ( '\\\"' ) )* '\\\"'
match( 0x22 )
# at line 93:20: (~ ( '\\\"' ) )*
while true # decision 3
alt_3 = 2
look_3_0 = @input.peek( 1 )
if ( look_3_0.between?( 0x0, 0x21 ) || look_3_0.between?( 0x23, 0xffff ) )
alt_3 = 1
end
case alt_3
when 1
# at line
if @input.peek( 1 ).between?( 0x0, 0x21 ) || @input.peek( 1 ).between?( 0x23, 0xffff )
@input.consume
else
mse = MismatchedSet( nil )
recover mse
raise mse
end
else
break # out of loop for decision 3
end
end # loop for decision 3
match( 0x22 )
end
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 21 )
end
# lexer rule number! (NUMBER)
# (in Statement.g)
def number!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 22 )
type = NUMBER
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 95:15: ( '-' )? ( DIGIT )+ '.' ( DIGIT )+
# at line 95:15: ( '-' )?
alt_5 = 2
look_5_0 = @input.peek( 1 )
if ( look_5_0 == 0x2d )
alt_5 = 1
end
case alt_5
when 1
# at line 95:15: '-'
match( 0x2d )
end
# at file 95:20: ( DIGIT )+
match_count_6 = 0
while true
alt_6 = 2
look_6_0 = @input.peek( 1 )
if ( look_6_0.between?( 0x30, 0x39 ) )
alt_6 = 1
end
case alt_6
when 1
# at line
if @input.peek( 1 ).between?( 0x30, 0x39 )
@input.consume
else
mse = MismatchedSet( nil )
recover mse
raise mse
end
else
match_count_6 > 0 and break
eee = EarlyExit(6)
raise eee
end
match_count_6 += 1
end
match( 0x2e )
# at file 95:31: ( DIGIT )+
match_count_7 = 0
while true
alt_7 = 2
look_7_0 = @input.peek( 1 )
if ( look_7_0.between?( 0x30, 0x39 ) )
alt_7 = 1
end
case alt_7
when 1
# at line
if @input.peek( 1 ).between?( 0x30, 0x39 )
@input.consume
else
mse = MismatchedSet( nil )
recover mse
raise mse
end
else
match_count_7 > 0 and break
eee = EarlyExit(7)
raise eee
end
match_count_7 += 1
end
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 22 )
end
# lexer rule int! (INT)
# (in Statement.g)
def int!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 23 )
type = INT
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 96:15: ( '-' )? ( DIGIT )+
# at line 96:15: ( '-' )?
alt_8 = 2
look_8_0 = @input.peek( 1 )
if ( look_8_0 == 0x2d )
alt_8 = 1
end
case alt_8
when 1
# at line 96:15: '-'
match( 0x2d )
end
# at file 96:20: ( DIGIT )+
match_count_9 = 0
while true
alt_9 = 2
look_9_0 = @input.peek( 1 )
if ( look_9_0.between?( 0x30, 0x39 ) )
alt_9 = 1
end
case alt_9
when 1
# at line
if @input.peek( 1 ).between?( 0x30, 0x39 )
@input.consume
else
mse = MismatchedSet( nil )
recover mse
raise mse
end
else
match_count_9 > 0 and break
eee = EarlyExit(9)
raise eee
end
match_count_9 += 1
end
@state.type = type
@state.channel = channel
ensure
# -> uncomment the next line to manually enable rule tracing
# trace_out( __method__, 23 )
end
# lexer rule variable! (VARIABLE)
# (in Statement.g)
def variable!
# -> uncomment the next line to manually enable rule tracing
# trace_in( __method__, 24 )
type = VARIABLE
channel = ANTLR3::DEFAULT_CHANNEL
# - - - - label initialization - - - -
# - - - - main rule block - - - -
# at line 97:15: '$' ( DIGIT )+
match( 0x24 )
# at file 97:19: ( DIGIT )+
match_count_10 = 0