Home | History | Annotate | Download | only in template
      1 #!/usr/bin/env ruby
      2 #
      3 # GroupFile.g
      4 # 
      5 # Generated using ANTLR version: 3.2.1-SNAPSHOT Jun 18, 2010 05:38:11
      6 # Ruby runtime library version: 1.7.5
      7 # Input grammar file: GroupFile.g
      8 # Generated at: 2010-07-03 23:15:35
      9 # 
     10 
     11 # ~~~> start load path setup
     12 this_directory = File.expand_path( File.dirname( __FILE__ ) )
     13 $LOAD_PATH.unshift( this_directory ) unless $LOAD_PATH.include?( this_directory )
     14 
     15 antlr_load_failed = proc do
     16   load_path = $LOAD_PATH.map { |dir| '  - ' << dir }.join( $/ )
     17   raise LoadError, <<-END.strip!
     18   
     19 Failed to load the ANTLR3 runtime library (version 1.7.5):
     20 
     21 Ensure the library has been installed on your system and is available
     22 on the load path. If rubygems is available on your system, this can
     23 be done with the command:
     24   
     25   gem install antlr3
     26 
     27 Current load path:
     28 #{ load_path }
     29 
     30   END
     31 end
     32 
     33 defined?( ANTLR3 ) or begin
     34   
     35   # 1: try to load the ruby antlr3 runtime library from the system path
     36   require 'antlr3'
     37   
     38 rescue LoadError
     39   
     40   # 2: try to load rubygems if it isn't already loaded
     41   defined?( Gem ) or begin
     42     require 'rubygems'
     43   rescue LoadError
     44     antlr_load_failed.call
     45   end
     46   
     47   # 3: try to activate the antlr3 gem
     48   begin
     49     Gem.activate( 'antlr3', '~> 1.7.5' )
     50   rescue Gem::LoadError
     51     antlr_load_failed.call
     52   end
     53   
     54   require 'antlr3'
     55   
     56 end
     57 # <~~~ end load path setup
     58 
     59 # - - - - - - begin action @parser::header - - - - - -
     60 # GroupFile.g
     61 
     62 
     63 module ANTLR3
     64 module Template
     65 
     66 # - - - - - - end action @parser::header - - - - - - -
     67 
     68 
     69 module GroupFile
     70   # TokenData defines all of the token type integer values
     71   # as constants, which will be included in all 
     72   # ANTLR-generated recognizers.
     73   const_defined?( :TokenData ) or TokenData = ANTLR3::TokenScheme.new
     74 
     75   module TokenData
     76 
     77     # define the token constants
     78     define_tokens( :ID => 5, :EOF => -1, :T__19 => 19, :T__16 => 16, :WS => 9, 
     79                    :T__15 => 15, :T__18 => 18, :T__17 => 17, :T__12 => 12, 
     80                    :TEMPLATE => 6, :T__11 => 11, :T__14 => 14, :T__13 => 13, 
     81                    :T__10 => 10, :CONSTANT => 4, :COMMENT => 8, :STRING => 7 )
     82 
     83     # register the proper human-readable name or literal value
     84     # for each token type
     85     #
     86     # this is necessary because anonymous tokens, which are
     87     # created from literal values in the grammar, do not
     88     # have descriptive names
     89     register_names( "CONSTANT", "ID", "TEMPLATE", "STRING", "COMMENT", "WS", 
     90                     "'group'", "'::'", "';'", "'::='", "'('", "')'", "','", 
     91                     "'*'", "'&'", "'='" )
     92     
     93   end
     94 
     95 
     96   class Parser < ANTLR3::Parser
     97     @grammar_home = GroupFile
     98 
     99     RULE_METHODS = [ :group_spec, :group_name, :member, :parameter_declaration, 
    100                      :parameters, :parameter ].freeze
    101 
    102 
    103     include TokenData
    104 
    105     begin
    106       generated_using( "GroupFile.g", "3.2.1-SNAPSHOT Jun 18, 2010 05:38:11", "1.7.5" )
    107     rescue NoMethodError => error
    108       # ignore
    109     end
    110 
    111     def initialize( input, options = {} )
    112       super( input, options )
    113 
    114 
    115     end
    116 
    117       def fetch_group( namespace, name )
    118         if namespace.const_defined?( name )
    119           group = namespace.const_get( name )
    120           unless group.is_a?( ANTLR3::Template::Group )
    121           
    122           end
    123         else
    124           group = ANTLR3::Template::Group.new
    125           namespace.const_set( name, group )
    126         end
    127         return( group )
    128       end
    129       
    130       def unescape( text )
    131         text.gsub( /\\(?:([abefnrstv])|([0-7]{3})|x([0-9a-fA-F]{2})|(.))/ ) do
    132           if $1
    133             case $1[ 0 ]
    134             when ?a then "\a"
    135             when ?b then "\b"
    136             when ?e then "\e"
    137             when ?f then "\f"
    138             when ?n then "\n"
    139             when ?r then "\r"
    140             when ?s then "\s"
    141             when ?t then "\t"
    142             when ?v then "\v"
    143             end
    144           elsif $2 then $2.to_i( 8 ).chr
    145           elsif $3 then $3.to_i( 16 ).chr
    146           elsif $4 then $4
    147           end
    148         end
    149       end
    150       
    151       def extract_template( token )
    152         case token.type
    153         when TEMPLATE
    154           token.text.gsub( /\A<<<\r?\n?|\r?\n?>>>\Z/, '' )
    155         when STRING
    156           unescape( token.text[ 1...-1 ] )
    157         end
    158       end
    159       
    160       def group( namespace = ::Object )
    161         group_spec( namespace )
    162       end
    163 
    164     # - - - - - - - - - - - - Rules - - - - - - - - - - - - -
    165 
    166     # 
    167     # parser rule group_spec
    168     # 
    169     # (in GroupFile.g)
    170     # 79:1: group_spec[ namespace ] returns [ group ] : ( group_name[ $namespace ] | ) ( member[ $group ] )* ;
    171     # 
    172     def group_spec( namespace )
    173       # -> uncomment the next line to manually enable rule tracing
    174       # trace_in( __method__, 1 )
    175       group = nil
    176       group_name1 = nil
    177 
    178       begin
    179         # at line 80:5: ( group_name[ $namespace ] | ) ( member[ $group ] )*
    180         # at line 80:5: ( group_name[ $namespace ] | )
    181         alt_1 = 2
    182         look_1_0 = @input.peek( 1 )
    183 
    184         if ( look_1_0 == T__10 )
    185           alt_1 = 1
    186         elsif ( look_1_0 == EOF || look_1_0 == ID )
    187           alt_1 = 2
    188         else
    189           raise NoViableAlternative( "", 1, 0 )
    190         end
    191         case alt_1
    192         when 1
    193           # at line 80:7: group_name[ $namespace ]
    194           @state.following.push( TOKENS_FOLLOWING_group_name_IN_group_spec_85 )
    195           group_name1 = group_name( namespace )
    196           @state.following.pop
    197           # --> action
    198            group = group_name1 
    199           # <-- action
    200 
    201         when 2
    202           # at line 81:7: 
    203           # --> action
    204            group = ANTLR3::Template::Group.new 
    205           # <-- action
    206 
    207         end
    208         # at line 83:5: ( member[ $group ] )*
    209         while true # decision 2
    210           alt_2 = 2
    211           look_2_0 = @input.peek( 1 )
    212 
    213           if ( look_2_0 == ID )
    214             alt_2 = 1
    215 
    216           end
    217           case alt_2
    218           when 1
    219             # at line 83:5: member[ $group ]
    220             @state.following.push( TOKENS_FOLLOWING_member_IN_group_spec_108 )
    221             member( group )
    222             @state.following.pop
    223 
    224           else
    225             break # out of loop for decision 2
    226           end
    227         end # loop for decision 2
    228 
    229       rescue ANTLR3::Error::RecognitionError => re
    230         report_error( re )
    231         recover( re )
    232 
    233       ensure
    234         # -> uncomment the next line to manually enable rule tracing
    235         # trace_out( __method__, 1 )
    236 
    237       end
    238       
    239       return group
    240     end
    241 
    242 
    243     # 
    244     # parser rule group_name
    245     # 
    246     # (in GroupFile.g)
    247     # 86:1: group_name[ namespace ] returns [ group ] : 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )? ;
    248     # 
    249     def group_name( namespace )
    250       # -> uncomment the next line to manually enable rule tracing
    251       # trace_in( __method__, 2 )
    252       group = nil
    253       mod = nil
    254       name = nil
    255 
    256       begin
    257         # at line 87:5: 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )?
    258         match( T__10, TOKENS_FOLLOWING_T__10_IN_group_name_128 )
    259         # at line 88:5: (mod= CONSTANT '::' )*
    260         while true # decision 3
    261           alt_3 = 2
    262           look_3_0 = @input.peek( 1 )
    263 
    264           if ( look_3_0 == CONSTANT )
    265             look_3_1 = @input.peek( 2 )
    266 
    267             if ( look_3_1 == T__11 )
    268               alt_3 = 1
    269 
    270             end
    271 
    272           end
    273           case alt_3
    274           when 1
    275             # at line 89:7: mod= CONSTANT '::'
    276             mod = match( CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_144 )
    277             match( T__11, TOKENS_FOLLOWING_T__11_IN_group_name_146 )
    278             # --> action
    279              namespace = namespace.const_get( mod.text ) 
    280             # <-- action
    281 
    282           else
    283             break # out of loop for decision 3
    284           end
    285         end # loop for decision 3
    286         name = match( CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_169 )
    287         # --> action
    288          group = fetch_group( namespace, name.text ) 
    289         # <-- action
    290         # at line 93:5: ( ';' )?
    291         alt_4 = 2
    292         look_4_0 = @input.peek( 1 )
    293 
    294         if ( look_4_0 == T__12 )
    295           alt_4 = 1
    296         end
    297         case alt_4
    298         when 1
    299           # at line 93:5: ';'
    300           match( T__12, TOKENS_FOLLOWING_T__12_IN_group_name_177 )
    301 
    302         end
    303 
    304       rescue ANTLR3::Error::RecognitionError => re
    305         report_error( re )
    306         recover( re )
    307 
    308       ensure
    309         # -> uncomment the next line to manually enable rule tracing
    310         # trace_out( __method__, 2 )
    311 
    312       end
    313       
    314       return group
    315     end
    316 
    317 
    318     # 
    319     # parser rule member
    320     # 
    321     # (in GroupFile.g)
    322     # 96:1: member[ group ] : name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING ) ;
    323     # 
    324     def member( group )
    325       # -> uncomment the next line to manually enable rule tracing
    326       # trace_in( __method__, 3 )
    327       name = nil
    328       aliased = nil
    329       __TEMPLATE3__ = nil
    330       __STRING4__ = nil
    331       parameter_declaration2 = nil
    332       # - - - - @init action - - - -
    333        params = nil 
    334 
    335       begin
    336         # at line 98:5: name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING )
    337         name = match( ID, TOKENS_FOLLOWING_ID_IN_member_199 )
    338         # at line 98:13: ( parameter_declaration )?
    339         alt_5 = 2
    340         look_5_0 = @input.peek( 1 )
    341 
    342         if ( look_5_0 == ID || look_5_0 == T__14 || look_5_0.between?( T__17, T__18 ) )
    343           alt_5 = 1
    344         end
    345         case alt_5
    346         when 1
    347           # at line 98:15: parameter_declaration
    348           @state.following.push( TOKENS_FOLLOWING_parameter_declaration_IN_member_203 )
    349           parameter_declaration2 = parameter_declaration
    350           @state.following.pop
    351           # --> action
    352            params = parameter_declaration2 
    353           # <-- action
    354 
    355         end
    356         match( T__13, TOKENS_FOLLOWING_T__13_IN_member_210 )
    357         # at line 99:5: (aliased= ID | TEMPLATE | STRING )
    358         alt_6 = 3
    359         case look_6 = @input.peek( 1 )
    360         when ID then alt_6 = 1
    361         when TEMPLATE then alt_6 = 2
    362         when STRING then alt_6 = 3
    363         else
    364           raise NoViableAlternative( "", 6, 0 )
    365         end
    366         case alt_6
    367         when 1
    368           # at line 99:7: aliased= ID
    369           aliased = match( ID, TOKENS_FOLLOWING_ID_IN_member_220 )
    370           # --> action
    371            group.alias_template( name.text, aliased.text ) 
    372           # <-- action
    373 
    374         when 2
    375           # at line 100:7: TEMPLATE
    376           __TEMPLATE3__ = match( TEMPLATE, TOKENS_FOLLOWING_TEMPLATE_IN_member_230 )
    377           # --> action
    378            group.define_template( name.text, extract_template( __TEMPLATE3__ ), params ) 
    379           # <-- action
    380 
    381         when 3
    382           # at line 101:7: STRING
    383           __STRING4__ = match( STRING, TOKENS_FOLLOWING_STRING_IN_member_242 )
    384           # --> action
    385            group.define_template( name.text, extract_template( __STRING4__ ), params ) 
    386           # <-- action
    387 
    388         end
    389 
    390       rescue ANTLR3::Error::RecognitionError => re
    391         report_error( re )
    392         recover( re )
    393 
    394       ensure
    395         # -> uncomment the next line to manually enable rule tracing
    396         # trace_out( __method__, 3 )
    397 
    398       end
    399       
    400       return 
    401     end
    402 
    403 
    404     # 
    405     # parser rule parameter_declaration
    406     # 
    407     # (in GroupFile.g)
    408     # 105:1: parameter_declaration returns [ list ] : ( '(' ( parameters )? ')' | parameters );
    409     # 
    410     def parameter_declaration
    411       # -> uncomment the next line to manually enable rule tracing
    412       # trace_in( __method__, 4 )
    413       list = nil
    414       parameters5 = nil
    415       parameters6 = nil
    416       # - - - - @init action - - - -
    417        list = nil 
    418 
    419       begin
    420         # at line 107:3: ( '(' ( parameters )? ')' | parameters )
    421         alt_8 = 2
    422         look_8_0 = @input.peek( 1 )
    423 
    424         if ( look_8_0 == T__14 )
    425           alt_8 = 1
    426         elsif ( look_8_0 == ID || look_8_0.between?( T__17, T__18 ) )
    427           alt_8 = 2
    428         else
    429           raise NoViableAlternative( "", 8, 0 )
    430         end
    431         case alt_8
    432         when 1
    433           # at line 107:5: '(' ( parameters )? ')'
    434           match( T__14, TOKENS_FOLLOWING_T__14_IN_parameter_declaration_276 )
    435           # at line 107:9: ( parameters )?
    436           alt_7 = 2
    437           look_7_0 = @input.peek( 1 )
    438 
    439           if ( look_7_0 == ID || look_7_0.between?( T__17, T__18 ) )
    440             alt_7 = 1
    441           end
    442           case alt_7
    443           when 1
    444             # at line 107:11: parameters
    445             @state.following.push( TOKENS_FOLLOWING_parameters_IN_parameter_declaration_280 )
    446             parameters5 = parameters
    447             @state.following.pop
    448             # --> action
    449              list = parameters5 
    450             # <-- action
    451 
    452           end
    453           match( T__15, TOKENS_FOLLOWING_T__15_IN_parameter_declaration_287 )
    454 
    455         when 2
    456           # at line 108:5: parameters
    457           @state.following.push( TOKENS_FOLLOWING_parameters_IN_parameter_declaration_293 )
    458           parameters6 = parameters
    459           @state.following.pop
    460           # --> action
    461            list = parameters6 
    462           # <-- action
    463 
    464         end
    465       rescue ANTLR3::Error::RecognitionError => re
    466         report_error( re )
    467         recover( re )
    468 
    469       ensure
    470         # -> uncomment the next line to manually enable rule tracing
    471         # trace_out( __method__, 4 )
    472 
    473       end
    474       
    475       return list
    476     end
    477 
    478 
    479     # 
    480     # parser rule parameters
    481     # 
    482     # (in GroupFile.g)
    483     # 111:1: parameters returns [ list ] : parameter[ $list ] ( ',' parameter[ $list ] )* ;
    484     # 
    485     def parameters
    486       # -> uncomment the next line to manually enable rule tracing
    487       # trace_in( __method__, 5 )
    488       list = nil
    489       # - - - - @init action - - - -
    490        list = ANTLR3::Template::ParameterList.new 
    491 
    492       begin
    493         # at line 113:5: parameter[ $list ] ( ',' parameter[ $list ] )*
    494         @state.following.push( TOKENS_FOLLOWING_parameter_IN_parameters_317 )
    495         parameter( list )
    496         @state.following.pop
    497         # at line 113:24: ( ',' parameter[ $list ] )*
    498         while true # decision 9
    499           alt_9 = 2
    500           look_9_0 = @input.peek( 1 )
    501 
    502           if ( look_9_0 == T__16 )
    503             alt_9 = 1
    504 
    505           end
    506           case alt_9
    507           when 1
    508             # at line 113:26: ',' parameter[ $list ]
    509             match( T__16, TOKENS_FOLLOWING_T__16_IN_parameters_322 )
    510             @state.following.push( TOKENS_FOLLOWING_parameter_IN_parameters_324 )
    511             parameter( list )
    512             @state.following.pop
    513 
    514           else
    515             break # out of loop for decision 9
    516           end
    517         end # loop for decision 9
    518 
    519       rescue ANTLR3::Error::RecognitionError => re
    520         report_error( re )
    521         recover( re )
    522 
    523       ensure
    524         # -> uncomment the next line to manually enable rule tracing
    525         # trace_out( __method__, 5 )
    526 
    527       end
    528       
    529       return list
    530     end
    531 
    532 
    533     # 
    534     # parser rule parameter
    535     # 
    536     # (in GroupFile.g)
    537     # 116:1: parameter[ parameters ] : ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? );
    538     # 
    539     def parameter( parameters )
    540       # -> uncomment the next line to manually enable rule tracing
    541       # trace_in( __method__, 6 )
    542       name = nil
    543       v = nil
    544 
    545       begin
    546         # at line 117:3: ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? )
    547         alt_11 = 3
    548         case look_11 = @input.peek( 1 )
    549         when T__17 then alt_11 = 1
    550         when T__18 then alt_11 = 2
    551         when ID then alt_11 = 3
    552         else
    553           raise NoViableAlternative( "", 11, 0 )
    554         end
    555         case alt_11
    556         when 1
    557           # at line 117:5: '*' name= ID
    558           match( T__17, TOKENS_FOLLOWING_T__17_IN_parameter_342 )
    559           name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_346 )
    560           # --> action
    561            parameters.splat = name.text 
    562           # <-- action
    563 
    564         when 2
    565           # at line 118:5: '&' name= ID
    566           match( T__18, TOKENS_FOLLOWING_T__18_IN_parameter_354 )
    567           name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_358 )
    568           # --> action
    569            parameters.block = name.text 
    570           # <-- action
    571 
    572         when 3
    573           # at line 119:5: name= ID ( '=' v= STRING )?
    574           name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_368 )
    575           # --> action
    576            param = ANTLR3::Template::Parameter.new( name.text ) 
    577           # <-- action
    578           # at line 120:5: ( '=' v= STRING )?
    579           alt_10 = 2
    580           look_10_0 = @input.peek( 1 )
    581 
    582           if ( look_10_0 == T__19 )
    583             alt_10 = 1
    584           end
    585           case alt_10
    586           when 1
    587             # at line 120:7: '=' v= STRING
    588             match( T__19, TOKENS_FOLLOWING_T__19_IN_parameter_382 )
    589             v = match( STRING, TOKENS_FOLLOWING_STRING_IN_parameter_386 )
    590             # --> action
    591              param.default = v.text 
    592             # <-- action
    593 
    594           end
    595           # --> action
    596            parameters.add( param ) 
    597           # <-- action
    598 
    599         end
    600       rescue ANTLR3::Error::RecognitionError => re
    601         report_error( re )
    602         recover( re )
    603 
    604       ensure
    605         # -> uncomment the next line to manually enable rule tracing
    606         # trace_out( __method__, 6 )
    607 
    608       end
    609       
    610       return 
    611     end
    612 
    613 
    614 
    615     TOKENS_FOLLOWING_group_name_IN_group_spec_85 = Set[ 1, 5 ]
    616     TOKENS_FOLLOWING_member_IN_group_spec_108 = Set[ 1, 5 ]
    617     TOKENS_FOLLOWING_T__10_IN_group_name_128 = Set[ 4 ]
    618     TOKENS_FOLLOWING_CONSTANT_IN_group_name_144 = Set[ 11 ]
    619     TOKENS_FOLLOWING_T__11_IN_group_name_146 = Set[ 4 ]
    620     TOKENS_FOLLOWING_CONSTANT_IN_group_name_169 = Set[ 1, 12 ]
    621     TOKENS_FOLLOWING_T__12_IN_group_name_177 = Set[ 1 ]
    622     TOKENS_FOLLOWING_ID_IN_member_199 = Set[ 5, 13, 14, 17, 18 ]
    623     TOKENS_FOLLOWING_parameter_declaration_IN_member_203 = Set[ 13 ]
    624     TOKENS_FOLLOWING_T__13_IN_member_210 = Set[ 5, 6, 7 ]
    625     TOKENS_FOLLOWING_ID_IN_member_220 = Set[ 1 ]
    626     TOKENS_FOLLOWING_TEMPLATE_IN_member_230 = Set[ 1 ]
    627     TOKENS_FOLLOWING_STRING_IN_member_242 = Set[ 1 ]
    628     TOKENS_FOLLOWING_T__14_IN_parameter_declaration_276 = Set[ 5, 14, 15, 17, 18 ]
    629     TOKENS_FOLLOWING_parameters_IN_parameter_declaration_280 = Set[ 15 ]
    630     TOKENS_FOLLOWING_T__15_IN_parameter_declaration_287 = Set[ 1 ]
    631     TOKENS_FOLLOWING_parameters_IN_parameter_declaration_293 = Set[ 1 ]
    632     TOKENS_FOLLOWING_parameter_IN_parameters_317 = Set[ 1, 16 ]
    633     TOKENS_FOLLOWING_T__16_IN_parameters_322 = Set[ 5, 14, 17, 18 ]
    634     TOKENS_FOLLOWING_parameter_IN_parameters_324 = Set[ 1, 16 ]
    635     TOKENS_FOLLOWING_T__17_IN_parameter_342 = Set[ 5 ]
    636     TOKENS_FOLLOWING_ID_IN_parameter_346 = Set[ 1 ]
    637     TOKENS_FOLLOWING_T__18_IN_parameter_354 = Set[ 5 ]
    638     TOKENS_FOLLOWING_ID_IN_parameter_358 = Set[ 1 ]
    639     TOKENS_FOLLOWING_ID_IN_parameter_368 = Set[ 1, 19 ]
    640     TOKENS_FOLLOWING_T__19_IN_parameter_382 = Set[ 7 ]
    641     TOKENS_FOLLOWING_STRING_IN_parameter_386 = Set[ 1 ]
    642 
    643   end # class Parser < ANTLR3::Parser
    644 
    645 end
    646 # - - - - - - begin action @parser::footer - - - - - -
    647 # GroupFile.g
    648 
    649 
    650 end # module Template
    651 end # module ANTLR3
    652 
    653 # - - - - - - end action @parser::footer - - - - - - -
    654 
    655 
    656 if __FILE__ == $0 and ARGV.first != '--'
    657   # - - - - - - begin action @parser::main - - - - - -
    658   # GroupFile.g
    659 
    660 
    661     defined?( ANTLR3::Template::GroupFile::Lexer ) or require 'antlr3/template/group-file'
    662     ANTLR3::Template::GroupFile::Parser.main( ARGV )
    663 
    664   # - - - - - - end action @parser::main - - - - - - -
    665 
    666 end
    667