aboutsummaryrefslogtreecommitdiff
path: root/antlr-3.4/runtime/Ruby/lib/antlr3/template/group-file-parser.rb
blob: 247d0977aa47cde9291b20dea01088b7de77396e (plain)
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
#!/usr/bin/env ruby
#
# GroupFile.g
# 
# Generated using ANTLR version: 3.2.1-SNAPSHOT Jun 18, 2010 05:38:11
# Ruby runtime library version: 1.7.5
# Input grammar file: GroupFile.g
# Generated at: 2010-07-03 23:15:35
# 

# ~~~> 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.7.5):

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
    Gem.activate( 'antlr3', '~> 1.7.5' )
  rescue Gem::LoadError
    antlr_load_failed.call
  end
  
  require 'antlr3'
  
end
# <~~~ end load path setup

# - - - - - - begin action @parser::header - - - - - -
# GroupFile.g


module ANTLR3
module Template

# - - - - - - end action @parser::header - - - - - - -


module GroupFile
  # 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( :ID => 5, :EOF => -1, :T__19 => 19, :T__16 => 16, :WS => 9, 
                   :T__15 => 15, :T__18 => 18, :T__17 => 17, :T__12 => 12, 
                   :TEMPLATE => 6, :T__11 => 11, :T__14 => 14, :T__13 => 13, 
                   :T__10 => 10, :CONSTANT => 4, :COMMENT => 8, :STRING => 7 )

    # register the proper human-readable name or literal value
    # for each token type
    #
    # this is necessary because anonymous tokens, which are
    # created from literal values in the grammar, do not
    # have descriptive names
    register_names( "CONSTANT", "ID", "TEMPLATE", "STRING", "COMMENT", "WS", 
                    "'group'", "'::'", "';'", "'::='", "'('", "')'", "','", 
                    "'*'", "'&'", "'='" )
    
  end


  class Parser < ANTLR3::Parser
    @grammar_home = GroupFile

    RULE_METHODS = [ :group_spec, :group_name, :member, :parameter_declaration, 
                     :parameters, :parameter ].freeze


    include TokenData

    begin
      generated_using( "GroupFile.g", "3.2.1-SNAPSHOT Jun 18, 2010 05:38:11", "1.7.5" )
    rescue NoMethodError => error
      # ignore
    end

    def initialize( input, options = {} )
      super( input, options )


    end

      def fetch_group( namespace, name )
        if namespace.const_defined?( name )
          group = namespace.const_get( name )
          unless group.is_a?( ANTLR3::Template::Group )
          
          end
        else
          group = ANTLR3::Template::Group.new
          namespace.const_set( name, group )
        end
        return( group )
      end
      
      def unescape( text )
        text.gsub( /\\(?:([abefnrstv])|([0-7]{3})|x([0-9a-fA-F]{2})|(.))/ ) do
          if $1
            case $1[ 0 ]
            when ?a then "\a"
            when ?b then "\b"
            when ?e then "\e"
            when ?f then "\f"
            when ?n then "\n"
            when ?r then "\r"
            when ?s then "\s"
            when ?t then "\t"
            when ?v then "\v"
            end
          elsif $2 then $2.to_i( 8 ).chr
          elsif $3 then $3.to_i( 16 ).chr
          elsif $4 then $4
          end
        end
      end
      
      def extract_template( token )
        case token.type
        when TEMPLATE
          token.text.gsub( /\A<<<\r?\n?|\r?\n?>>>\Z/, '' )
        when STRING
          unescape( token.text[ 1...-1 ] )
        end
      end
      
      def group( namespace = ::Object )
        group_spec( namespace )
      end

    # - - - - - - - - - - - - Rules - - - - - - - - - - - - -

    # 
    # parser rule group_spec
    # 
    # (in GroupFile.g)
    # 79:1: group_spec[ namespace ] returns [ group ] : ( group_name[ $namespace ] | ) ( member[ $group ] )* ;
    # 
    def group_spec( namespace )
      # -> uncomment the next line to manually enable rule tracing
      # trace_in( __method__, 1 )
      group = nil
      group_name1 = nil

      begin
        # at line 80:5: ( group_name[ $namespace ] | ) ( member[ $group ] )*
        # at line 80:5: ( group_name[ $namespace ] | )
        alt_1 = 2
        look_1_0 = @input.peek( 1 )

        if ( look_1_0 == T__10 )
          alt_1 = 1
        elsif ( look_1_0 == EOF || look_1_0 == ID )
          alt_1 = 2
        else
          raise NoViableAlternative( "", 1, 0 )
        end
        case alt_1
        when 1
          # at line 80:7: group_name[ $namespace ]
          @state.following.push( TOKENS_FOLLOWING_group_name_IN_group_spec_85 )
          group_name1 = group_name( namespace )
          @state.following.pop
          # --> action
           group = group_name1 
          # <-- action

        when 2
          # at line 81:7: 
          # --> action
           group = ANTLR3::Template::Group.new 
          # <-- action

        end
        # at line 83:5: ( member[ $group ] )*
        while true # decision 2
          alt_2 = 2
          look_2_0 = @input.peek( 1 )

          if ( look_2_0 == ID )
            alt_2 = 1

          end
          case alt_2
          when 1
            # at line 83:5: member[ $group ]
            @state.following.push( TOKENS_FOLLOWING_member_IN_group_spec_108 )
            member( group )
            @state.following.pop

          else
            break # out of loop for decision 2
          end
        end # loop for decision 2

      rescue ANTLR3::Error::RecognitionError => re
        report_error( re )
        recover( re )

      ensure
        # -> uncomment the next line to manually enable rule tracing
        # trace_out( __method__, 1 )

      end
      
      return group
    end


    # 
    # parser rule group_name
    # 
    # (in GroupFile.g)
    # 86:1: group_name[ namespace ] returns [ group ] : 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )? ;
    # 
    def group_name( namespace )
      # -> uncomment the next line to manually enable rule tracing
      # trace_in( __method__, 2 )
      group = nil
      mod = nil
      name = nil

      begin
        # at line 87:5: 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )?
        match( T__10, TOKENS_FOLLOWING_T__10_IN_group_name_128 )
        # at line 88:5: (mod= CONSTANT '::' )*
        while true # decision 3
          alt_3 = 2
          look_3_0 = @input.peek( 1 )

          if ( look_3_0 == CONSTANT )
            look_3_1 = @input.peek( 2 )

            if ( look_3_1 == T__11 )
              alt_3 = 1

            end

          end
          case alt_3
          when 1
            # at line 89:7: mod= CONSTANT '::'
            mod = match( CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_144 )
            match( T__11, TOKENS_FOLLOWING_T__11_IN_group_name_146 )
            # --> action
             namespace = namespace.const_get( mod.text ) 
            # <-- action

          else
            break # out of loop for decision 3
          end
        end # loop for decision 3
        name = match( CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_169 )
        # --> action
         group = fetch_group( namespace, name.text ) 
        # <-- action
        # at line 93:5: ( ';' )?
        alt_4 = 2
        look_4_0 = @input.peek( 1 )

        if ( look_4_0 == T__12 )
          alt_4 = 1
        end
        case alt_4
        when 1
          # at line 93:5: ';'
          match( T__12, TOKENS_FOLLOWING_T__12_IN_group_name_177 )

        end

      rescue ANTLR3::Error::RecognitionError => re
        report_error( re )
        recover( re )

      ensure
        # -> uncomment the next line to manually enable rule tracing
        # trace_out( __method__, 2 )

      end
      
      return group
    end


    # 
    # parser rule member
    # 
    # (in GroupFile.g)
    # 96:1: member[ group ] : name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING ) ;
    # 
    def member( group )
      # -> uncomment the next line to manually enable rule tracing
      # trace_in( __method__, 3 )
      name = nil
      aliased = nil
      __TEMPLATE3__ = nil
      __STRING4__ = nil
      parameter_declaration2 = nil
      # - - - - @init action - - - -
       params = nil 

      begin
        # at line 98:5: name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING )
        name = match( ID, TOKENS_FOLLOWING_ID_IN_member_199 )
        # at line 98:13: ( parameter_declaration )?
        alt_5 = 2
        look_5_0 = @input.peek( 1 )

        if ( look_5_0 == ID || look_5_0 == T__14 || look_5_0.between?( T__17, T__18 ) )
          alt_5 = 1
        end
        case alt_5
        when 1
          # at line 98:15: parameter_declaration
          @state.following.push( TOKENS_FOLLOWING_parameter_declaration_IN_member_203 )
          parameter_declaration2 = parameter_declaration
          @state.following.pop
          # --> action
           params = parameter_declaration2 
          # <-- action

        end
        match( T__13, TOKENS_FOLLOWING_T__13_IN_member_210 )
        # at line 99:5: (aliased= ID | TEMPLATE | STRING )
        alt_6 = 3
        case look_6 = @input.peek( 1 )
        when ID then alt_6 = 1
        when TEMPLATE then alt_6 = 2
        when STRING then alt_6 = 3
        else
          raise NoViableAlternative( "", 6, 0 )
        end
        case alt_6
        when 1
          # at line 99:7: aliased= ID
          aliased = match( ID, TOKENS_FOLLOWING_ID_IN_member_220 )
          # --> action
           group.alias_template( name.text, aliased.text ) 
          # <-- action

        when 2
          # at line 100:7: TEMPLATE
          __TEMPLATE3__ = match( TEMPLATE, TOKENS_FOLLOWING_TEMPLATE_IN_member_230 )
          # --> action
           group.define_template( name.text, extract_template( __TEMPLATE3__ ), params ) 
          # <-- action

        when 3
          # at line 101:7: STRING
          __STRING4__ = match( STRING, TOKENS_FOLLOWING_STRING_IN_member_242 )
          # --> action
           group.define_template( name.text, extract_template( __STRING4__ ), params ) 
          # <-- action

        end

      rescue ANTLR3::Error::RecognitionError => re
        report_error( re )
        recover( re )

      ensure
        # -> uncomment the next line to manually enable rule tracing
        # trace_out( __method__, 3 )

      end
      
      return 
    end


    # 
    # parser rule parameter_declaration
    # 
    # (in GroupFile.g)
    # 105:1: parameter_declaration returns [ list ] : ( '(' ( parameters )? ')' | parameters );
    # 
    def parameter_declaration
      # -> uncomment the next line to manually enable rule tracing
      # trace_in( __method__, 4 )
      list = nil
      parameters5 = nil
      parameters6 = nil
      # - - - - @init action - - - -
       list = nil 

      begin
        # at line 107:3: ( '(' ( parameters )? ')' | parameters )
        alt_8 = 2
        look_8_0 = @input.peek( 1 )

        if ( look_8_0 == T__14 )
          alt_8 = 1
        elsif ( look_8_0 == ID || look_8_0.between?( T__17, T__18 ) )
          alt_8 = 2
        else
          raise NoViableAlternative( "", 8, 0 )
        end
        case alt_8
        when 1
          # at line 107:5: '(' ( parameters )? ')'
          match( T__14, TOKENS_FOLLOWING_T__14_IN_parameter_declaration_276 )
          # at line 107:9: ( parameters )?
          alt_7 = 2
          look_7_0 = @input.peek( 1 )

          if ( look_7_0 == ID || look_7_0.between?( T__17, T__18 ) )
            alt_7 = 1
          end
          case alt_7
          when 1
            # at line 107:11: parameters
            @state.following.push( TOKENS_FOLLOWING_parameters_IN_parameter_declaration_280 )
            parameters5 = parameters
            @state.following.pop
            # --> action
             list = parameters5 
            # <-- action

          end
          match( T__15, TOKENS_FOLLOWING_T__15_IN_parameter_declaration_287 )

        when 2
          # at line 108:5: parameters
          @state.following.push( TOKENS_FOLLOWING_parameters_IN_parameter_declaration_293 )
          parameters6 = parameters
          @state.following.pop
          # --> action
           list = parameters6 
          # <-- action

        end
      rescue ANTLR3::Error::RecognitionError => re
        report_error( re )
        recover( re )

      ensure
        # -> uncomment the next line to manually enable rule tracing
        # trace_out( __method__, 4 )

      end
      
      return list
    end


    # 
    # parser rule parameters
    # 
    # (in GroupFile.g)
    # 111:1: parameters returns [ list ] : parameter[ $list ] ( ',' parameter[ $list ] )* ;
    # 
    def parameters
      # -> uncomment the next line to manually enable rule tracing
      # trace_in( __method__, 5 )
      list = nil
      # - - - - @init action - - - -
       list = ANTLR3::Template::ParameterList.new 

      begin
        # at line 113:5: parameter[ $list ] ( ',' parameter[ $list ] )*
        @state.following.push( TOKENS_FOLLOWING_parameter_IN_parameters_317 )
        parameter( list )
        @state.following.pop
        # at line 113:24: ( ',' parameter[ $list ] )*
        while true # decision 9
          alt_9 = 2
          look_9_0 = @input.peek( 1 )

          if ( look_9_0 == T__16 )
            alt_9 = 1

          end
          case alt_9
          when 1
            # at line 113:26: ',' parameter[ $list ]
            match( T__16, TOKENS_FOLLOWING_T__16_IN_parameters_322 )
            @state.following.push( TOKENS_FOLLOWING_parameter_IN_parameters_324 )
            parameter( list )
            @state.following.pop

          else
            break # out of loop for decision 9
          end
        end # loop for decision 9

      rescue ANTLR3::Error::RecognitionError => re
        report_error( re )
        recover( re )

      ensure
        # -> uncomment the next line to manually enable rule tracing
        # trace_out( __method__, 5 )

      end
      
      return list
    end


    # 
    # parser rule parameter
    # 
    # (in GroupFile.g)
    # 116:1: parameter[ parameters ] : ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? );
    # 
    def parameter( parameters )
      # -> uncomment the next line to manually enable rule tracing
      # trace_in( __method__, 6 )
      name = nil
      v = nil

      begin
        # at line 117:3: ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? )
        alt_11 = 3
        case look_11 = @input.peek( 1 )
        when T__17 then alt_11 = 1
        when T__18 then alt_11 = 2
        when ID then alt_11 = 3
        else
          raise NoViableAlternative( "", 11, 0 )
        end
        case alt_11
        when 1
          # at line 117:5: '*' name= ID
          match( T__17, TOKENS_FOLLOWING_T__17_IN_parameter_342 )
          name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_346 )
          # --> action
           parameters.splat = name.text 
          # <-- action

        when 2
          # at line 118:5: '&' name= ID
          match( T__18, TOKENS_FOLLOWING_T__18_IN_parameter_354 )
          name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_358 )
          # --> action
           parameters.block = name.text 
          # <-- action

        when 3
          # at line 119:5: name= ID ( '=' v= STRING )?
          name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_368 )
          # --> action
           param = ANTLR3::Template::Parameter.new( name.text ) 
          # <-- action
          # at line 120:5: ( '=' v= STRING )?
          alt_10 = 2
          look_10_0 = @input.peek( 1 )

          if ( look_10_0 == T__19 )
            alt_10 = 1
          end
          case alt_10
          when 1
            # at line 120:7: '=' v= STRING
            match( T__19, TOKENS_FOLLOWING_T__19_IN_parameter_382 )
            v = match( STRING, TOKENS_FOLLOWING_STRING_IN_parameter_386 )
            # --> action
             param.default = v.text 
            # <-- action

          end
          # --> action
           parameters.add( param ) 
          # <-- action

        end
      rescue ANTLR3::Error::RecognitionError => re
        report_error( re )
        recover( re )

      ensure
        # -> uncomment the next line to manually enable rule tracing
        # trace_out( __method__, 6 )

      end
      
      return 
    end



    TOKENS_FOLLOWING_group_name_IN_group_spec_85 = Set[ 1, 5 ]
    TOKENS_FOLLOWING_member_IN_group_spec_108 = Set[ 1, 5 ]
    TOKENS_FOLLOWING_T__10_IN_group_name_128 = Set[ 4 ]
    TOKENS_FOLLOWING_CONSTANT_IN_group_name_144 = Set[ 11 ]
    TOKENS_FOLLOWING_T__11_IN_group_name_146 = Set[ 4 ]
    TOKENS_FOLLOWING_CONSTANT_IN_group_name_169 = Set[ 1, 12 ]
    TOKENS_FOLLOWING_T__12_IN_group_name_177 = Set[ 1 ]
    TOKENS_FOLLOWING_ID_IN_member_199 = Set[ 5, 13, 14, 17, 18 ]
    TOKENS_FOLLOWING_parameter_declaration_IN_member_203 = Set[ 13 ]
    TOKENS_FOLLOWING_T__13_IN_member_210 = Set[ 5, 6, 7 ]
    TOKENS_FOLLOWING_ID_IN_member_220 = Set[ 1 ]
    TOKENS_FOLLOWING_TEMPLATE_IN_member_230 = Set[ 1 ]
    TOKENS_FOLLOWING_STRING_IN_member_242 = Set[ 1 ]
    TOKENS_FOLLOWING_T__14_IN_parameter_declaration_276 = Set[ 5, 14, 15, 17, 18 ]
    TOKENS_FOLLOWING_parameters_IN_parameter_declaration_280 = Set[ 15 ]
    TOKENS_FOLLOWING_T__15_IN_parameter_declaration_287 = Set[ 1 ]
    TOKENS_FOLLOWING_parameters_IN_parameter_declaration_293 = Set[ 1 ]
    TOKENS_FOLLOWING_parameter_IN_parameters_317 = Set[ 1, 16 ]
    TOKENS_FOLLOWING_T__16_IN_parameters_322 = Set[ 5, 14, 17, 18 ]
    TOKENS_FOLLOWING_parameter_IN_parameters_324 = Set[ 1, 16 ]
    TOKENS_FOLLOWING_T__17_IN_parameter_342 = Set[ 5 ]
    TOKENS_FOLLOWING_ID_IN_parameter_346 = Set[ 1 ]
    TOKENS_FOLLOWING_T__18_IN_parameter_354 = Set[ 5 ]
    TOKENS_FOLLOWING_ID_IN_parameter_358 = Set[ 1 ]
    TOKENS_FOLLOWING_ID_IN_parameter_368 = Set[ 1, 19 ]
    TOKENS_FOLLOWING_T__19_IN_parameter_382 = Set[ 7 ]
    TOKENS_FOLLOWING_STRING_IN_parameter_386 = Set[ 1 ]

  end # class Parser < ANTLR3::Parser

end
# - - - - - - begin action @parser::footer - - - - - -
# GroupFile.g


end # module Template
end # module ANTLR3

# - - - - - - end action @parser::footer - - - - - - -


if __FILE__ == $0 and ARGV.first != '--'
  # - - - - - - begin action @parser::main - - - - - -
  # GroupFile.g


    defined?( ANTLR3::Template::GroupFile::Lexer ) or require 'antlr3/template/group-file'
    ANTLR3::Template::GroupFile::Parser.main( ARGV )

  # - - - - - - end action @parser::main - - - - - - -

end