antlr3 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,627 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Group.g
4
+ #
5
+ # Generated using ANTLR version: 3.2.1-SNAPSHOT Dec 18, 2009 04:29:28
6
+ # Ruby runtime library version: 1.3.1
7
+ # Input grammar file: Group.g
8
+ # Generated at: 2010-01-17 06:59:16
9
+ #
10
+
11
+ # ~~~> start load path setup
12
+ this_directory = File.expand_path( File.dirname( __FILE__ ) )
13
+ $:.unshift( this_directory ) unless $:.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.3.1):
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.3.1' )
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
+ # Group.g
61
+
62
+
63
+ module ANTLR3
64
+ module Template
65
+
66
+ # - - - - - - end action @parser::header - - - - - - -
67
+
68
+
69
+ class Group
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 = Group
98
+
99
+ RULE_METHODS = [:group_spec, :group_name, :member, :parameter_declaration,
100
+ :parameters, :parameter].freeze
101
+
102
+
103
+ include TokenData
104
+
105
+ generated_using( "Group.g", "3.2.1-SNAPSHOT Dec 18, 2009 04:29:28", "1.3.1" )
106
+
107
+ def initialize(input, options = {})
108
+ super(input, options)
109
+
110
+
111
+ end
112
+
113
+ def fetch_group( namespace, name )
114
+ if namespace.const_defined?( name )
115
+ group = namespace.const_get( name )
116
+ unless group.is_a?( ANTLR3::Template::Group )
117
+
118
+ end
119
+ else
120
+ group = ANTLR3::Template::Group.new
121
+ namespace.const_set( name, group )
122
+ end
123
+ return( group )
124
+ end
125
+
126
+ def extract_template( token )
127
+ case token.type
128
+ when TEMPLATE
129
+ token.text.gsub( /\A<<<\r?\n?|\r?\n?>>>\Z/, '' )
130
+ end
131
+ end
132
+
133
+ def group( namespace = ::Object )
134
+ group_spec( namespace )
135
+ end
136
+
137
+ # - - - - - - - - - - - - Rules - - - - - - - - - - - - -
138
+
139
+ # parser rule group_spec
140
+ #
141
+ # (in Group.g)
142
+ # 58:1: group_spec[ namespace ] returns [ group ] : ( group_name[ $namespace ] | ) ( member[ $group ] )* ;
143
+ def group_spec(namespace)
144
+ # -> uncomment the next line to manually enable rule tracing
145
+ # trace_in(__method__, 1)
146
+ group = nil
147
+ group_name1 = nil
148
+
149
+ begin
150
+ # at line 59:5: ( group_name[ $namespace ] | ) ( member[ $group ] )*
151
+ # at line 59:5: ( group_name[ $namespace ] | )
152
+ alt_1 = 2
153
+ look_1_0 = @input.peek(1)
154
+
155
+ if (look_1_0 == T__10)
156
+ alt_1 = 1
157
+ elsif (look_1_0 == EOF || look_1_0 == ID)
158
+ alt_1 = 2
159
+ else
160
+ nvae = NoViableAlternative("", 1, 0)
161
+ raise nvae
162
+ end
163
+ case alt_1
164
+ when 1
165
+ # at line 59:7: group_name[ $namespace ]
166
+ @state.following.push(TOKENS_FOLLOWING_group_name_IN_group_spec_87)
167
+ group_name1 = group_name(namespace)
168
+ @state.following.pop
169
+ # --> action
170
+ group = group_name1
171
+ # <-- action
172
+
173
+ when 2
174
+ # at line 60:7:
175
+ # --> action
176
+ group = ANTLR3::Template::Group.new
177
+ # <-- action
178
+
179
+ end
180
+ # at line 62:5: ( member[ $group ] )*
181
+ loop do # decision 2
182
+ alt_2 = 2
183
+ look_2_0 = @input.peek(1)
184
+
185
+ if (look_2_0 == ID)
186
+ alt_2 = 1
187
+
188
+ end
189
+ case alt_2
190
+ when 1
191
+ # at line 62:5: member[ $group ]
192
+ @state.following.push(TOKENS_FOLLOWING_member_IN_group_spec_110)
193
+ member(group)
194
+ @state.following.pop
195
+
196
+ else
197
+ break # out of loop for decision 2
198
+ end
199
+ end # loop for decision 2
200
+
201
+ rescue ANTLR3::Error::RecognitionError => re
202
+ report_error(re)
203
+ recover(re)
204
+
205
+ ensure
206
+ # -> uncomment the next line to manually enable rule tracing
207
+ # trace_out(__method__, 1)
208
+
209
+ end
210
+
211
+ return group
212
+ end
213
+
214
+
215
+ # parser rule group_name
216
+ #
217
+ # (in Group.g)
218
+ # 65:1: group_name[ namespace ] returns [ group ] : 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )? ;
219
+ def group_name(namespace)
220
+ # -> uncomment the next line to manually enable rule tracing
221
+ # trace_in(__method__, 2)
222
+ group = nil
223
+ mod = nil
224
+ name = nil
225
+
226
+ begin
227
+ # at line 66:5: 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )?
228
+ match(T__10, TOKENS_FOLLOWING_T__10_IN_group_name_130)
229
+ # at line 67:5: (mod= CONSTANT '::' )*
230
+ loop do # decision 3
231
+ alt_3 = 2
232
+ look_3_0 = @input.peek(1)
233
+
234
+ if (look_3_0 == CONSTANT)
235
+ look_3_1 = @input.peek(2)
236
+
237
+ if (look_3_1 == T__11)
238
+ alt_3 = 1
239
+
240
+ end
241
+
242
+ end
243
+ case alt_3
244
+ when 1
245
+ # at line 68:7: mod= CONSTANT '::'
246
+ mod = match(CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_146)
247
+ match(T__11, TOKENS_FOLLOWING_T__11_IN_group_name_148)
248
+ # --> action
249
+ namespace = namespace.const_get( mod.text )
250
+ # <-- action
251
+
252
+ else
253
+ break # out of loop for decision 3
254
+ end
255
+ end # loop for decision 3
256
+ name = match(CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_171)
257
+ # --> action
258
+ group = fetch_group( namespace, name.text )
259
+ # <-- action
260
+ # at line 72:5: ( ';' )?
261
+ alt_4 = 2
262
+ look_4_0 = @input.peek(1)
263
+
264
+ if (look_4_0 == T__12)
265
+ alt_4 = 1
266
+ end
267
+ case alt_4
268
+ when 1
269
+ # at line 72:5: ';'
270
+ match(T__12, TOKENS_FOLLOWING_T__12_IN_group_name_179)
271
+
272
+ end
273
+
274
+ rescue ANTLR3::Error::RecognitionError => re
275
+ report_error(re)
276
+ recover(re)
277
+
278
+ ensure
279
+ # -> uncomment the next line to manually enable rule tracing
280
+ # trace_out(__method__, 2)
281
+
282
+ end
283
+
284
+ return group
285
+ end
286
+
287
+
288
+ # parser rule member
289
+ #
290
+ # (in Group.g)
291
+ # 75:1: member[ group ] : name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING ) ;
292
+ def member(group)
293
+ # -> uncomment the next line to manually enable rule tracing
294
+ # trace_in(__method__, 3)
295
+ name = nil
296
+ aliased = nil
297
+ __TEMPLATE3__ = nil
298
+ parameter_declaration2 = nil
299
+ # - - - - @init action - - - -
300
+ params = nil
301
+
302
+ begin
303
+ # at line 77:5: name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING )
304
+ name = match(ID, TOKENS_FOLLOWING_ID_IN_member_201)
305
+ # at line 77:13: ( parameter_declaration )?
306
+ alt_5 = 2
307
+ look_5_0 = @input.peek(1)
308
+
309
+ if (look_5_0 == ID || look_5_0 == T__14 || look_5_0.between?(T__17, T__18))
310
+ alt_5 = 1
311
+ end
312
+ case alt_5
313
+ when 1
314
+ # at line 77:15: parameter_declaration
315
+ @state.following.push(TOKENS_FOLLOWING_parameter_declaration_IN_member_205)
316
+ parameter_declaration2 = parameter_declaration
317
+ @state.following.pop
318
+ # --> action
319
+ params = parameter_declaration2
320
+ # <-- action
321
+
322
+ end
323
+ match(T__13, TOKENS_FOLLOWING_T__13_IN_member_212)
324
+ # at line 78:5: (aliased= ID | TEMPLATE | STRING )
325
+ alt_6 = 3
326
+ case look_6 = @input.peek(1)
327
+ when ID then alt_6 = 1
328
+ when TEMPLATE then alt_6 = 2
329
+ when STRING then alt_6 = 3
330
+ else
331
+ nvae = NoViableAlternative("", 6, 0)
332
+ raise nvae
333
+ end
334
+ case alt_6
335
+ when 1
336
+ # at line 78:7: aliased= ID
337
+ aliased = match(ID, TOKENS_FOLLOWING_ID_IN_member_222)
338
+ # --> action
339
+ group.alias_template( aliased.text, name.text )
340
+ # <-- action
341
+
342
+ when 2
343
+ # at line 79:7: TEMPLATE
344
+ __TEMPLATE3__ = match(TEMPLATE, TOKENS_FOLLOWING_TEMPLATE_IN_member_232)
345
+ # --> action
346
+ group.define_template( name.text, extract_template( __TEMPLATE3__ ), params )
347
+ # <-- action
348
+
349
+ when 3
350
+ # at line 80:7: STRING
351
+ match(STRING, TOKENS_FOLLOWING_STRING_IN_member_244)
352
+
353
+ end
354
+
355
+ rescue ANTLR3::Error::RecognitionError => re
356
+ report_error(re)
357
+ recover(re)
358
+
359
+ ensure
360
+ # -> uncomment the next line to manually enable rule tracing
361
+ # trace_out(__method__, 3)
362
+
363
+ end
364
+
365
+ return
366
+ end
367
+
368
+
369
+ # parser rule parameter_declaration
370
+ #
371
+ # (in Group.g)
372
+ # 84:1: parameter_declaration returns [ list ] : ( '(' ( parameters )? ')' | parameters );
373
+ def parameter_declaration
374
+ # -> uncomment the next line to manually enable rule tracing
375
+ # trace_in(__method__, 4)
376
+ list = nil
377
+ parameters4 = nil
378
+ parameters5 = nil
379
+ # - - - - @init action - - - -
380
+ list = nil
381
+
382
+ begin
383
+ # at line 86:3: ( '(' ( parameters )? ')' | parameters )
384
+ alt_8 = 2
385
+ look_8_0 = @input.peek(1)
386
+
387
+ if (look_8_0 == T__14)
388
+ alt_8 = 1
389
+ elsif (look_8_0 == ID || look_8_0.between?(T__17, T__18))
390
+ alt_8 = 2
391
+ else
392
+ nvae = NoViableAlternative("", 8, 0)
393
+ raise nvae
394
+ end
395
+ case alt_8
396
+ when 1
397
+ # at line 86:5: '(' ( parameters )? ')'
398
+ match(T__14, TOKENS_FOLLOWING_T__14_IN_parameter_declaration_272)
399
+ # at line 86:9: ( parameters )?
400
+ alt_7 = 2
401
+ look_7_0 = @input.peek(1)
402
+
403
+ if (look_7_0 == ID || look_7_0.between?(T__17, T__18))
404
+ alt_7 = 1
405
+ end
406
+ case alt_7
407
+ when 1
408
+ # at line 86:11: parameters
409
+ @state.following.push(TOKENS_FOLLOWING_parameters_IN_parameter_declaration_276)
410
+ parameters4 = parameters
411
+ @state.following.pop
412
+ # --> action
413
+ list = parameters4
414
+ # <-- action
415
+
416
+ end
417
+ match(T__15, TOKENS_FOLLOWING_T__15_IN_parameter_declaration_283)
418
+
419
+ when 2
420
+ # at line 87:5: parameters
421
+ @state.following.push(TOKENS_FOLLOWING_parameters_IN_parameter_declaration_289)
422
+ parameters5 = parameters
423
+ @state.following.pop
424
+ # --> action
425
+ list = parameters5
426
+ # <-- action
427
+
428
+ end
429
+ rescue ANTLR3::Error::RecognitionError => re
430
+ report_error(re)
431
+ recover(re)
432
+
433
+ ensure
434
+ # -> uncomment the next line to manually enable rule tracing
435
+ # trace_out(__method__, 4)
436
+
437
+ end
438
+
439
+ return list
440
+ end
441
+
442
+
443
+ # parser rule parameters
444
+ #
445
+ # (in Group.g)
446
+ # 90:1: parameters returns [ list ] : parameter[ $list ] ( ',' parameter[ $list ] )* ;
447
+ def parameters
448
+ # -> uncomment the next line to manually enable rule tracing
449
+ # trace_in(__method__, 5)
450
+ list = nil
451
+ # - - - - @init action - - - -
452
+ list = ANTLR3::Template::ParameterList.new
453
+
454
+ begin
455
+ # at line 92:5: parameter[ $list ] ( ',' parameter[ $list ] )*
456
+ @state.following.push(TOKENS_FOLLOWING_parameter_IN_parameters_313)
457
+ parameter(list)
458
+ @state.following.pop
459
+ # at line 92:24: ( ',' parameter[ $list ] )*
460
+ loop do # decision 9
461
+ alt_9 = 2
462
+ look_9_0 = @input.peek(1)
463
+
464
+ if (look_9_0 == T__16)
465
+ alt_9 = 1
466
+
467
+ end
468
+ case alt_9
469
+ when 1
470
+ # at line 92:26: ',' parameter[ $list ]
471
+ match(T__16, TOKENS_FOLLOWING_T__16_IN_parameters_318)
472
+ @state.following.push(TOKENS_FOLLOWING_parameter_IN_parameters_320)
473
+ parameter(list)
474
+ @state.following.pop
475
+
476
+ else
477
+ break # out of loop for decision 9
478
+ end
479
+ end # loop for decision 9
480
+
481
+ rescue ANTLR3::Error::RecognitionError => re
482
+ report_error(re)
483
+ recover(re)
484
+
485
+ ensure
486
+ # -> uncomment the next line to manually enable rule tracing
487
+ # trace_out(__method__, 5)
488
+
489
+ end
490
+
491
+ return list
492
+ end
493
+
494
+
495
+ # parser rule parameter
496
+ #
497
+ # (in Group.g)
498
+ # 95:1: parameter[ parameters ] : ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? );
499
+ def parameter(parameters)
500
+ # -> uncomment the next line to manually enable rule tracing
501
+ # trace_in(__method__, 6)
502
+ name = nil
503
+ v = nil
504
+
505
+ begin
506
+ # at line 96:3: ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? )
507
+ alt_11 = 3
508
+ case look_11 = @input.peek(1)
509
+ when T__17 then alt_11 = 1
510
+ when T__18 then alt_11 = 2
511
+ when ID then alt_11 = 3
512
+ else
513
+ nvae = NoViableAlternative("", 11, 0)
514
+ raise nvae
515
+ end
516
+ case alt_11
517
+ when 1
518
+ # at line 96:5: '*' name= ID
519
+ match(T__17, TOKENS_FOLLOWING_T__17_IN_parameter_338)
520
+ name = match(ID, TOKENS_FOLLOWING_ID_IN_parameter_342)
521
+ # --> action
522
+ parameters.splat = name.text
523
+ # <-- action
524
+
525
+ when 2
526
+ # at line 97:5: '&' name= ID
527
+ match(T__18, TOKENS_FOLLOWING_T__18_IN_parameter_350)
528
+ name = match(ID, TOKENS_FOLLOWING_ID_IN_parameter_354)
529
+ # --> action
530
+ parameters.block = name.text
531
+ # <-- action
532
+
533
+ when 3
534
+ # at line 98:5: name= ID ( '=' v= STRING )?
535
+ name = match(ID, TOKENS_FOLLOWING_ID_IN_parameter_364)
536
+ # --> action
537
+ param = ANTLR3::Template::Parameter.new( name.text )
538
+ # <-- action
539
+ # at line 99:5: ( '=' v= STRING )?
540
+ alt_10 = 2
541
+ look_10_0 = @input.peek(1)
542
+
543
+ if (look_10_0 == T__19)
544
+ alt_10 = 1
545
+ end
546
+ case alt_10
547
+ when 1
548
+ # at line 99:7: '=' v= STRING
549
+ match(T__19, TOKENS_FOLLOWING_T__19_IN_parameter_378)
550
+ v = match(STRING, TOKENS_FOLLOWING_STRING_IN_parameter_382)
551
+ # --> action
552
+ param.default = v.text
553
+ # <-- action
554
+
555
+ end
556
+ # --> action
557
+ parameters.add( param )
558
+ # <-- action
559
+
560
+ end
561
+ rescue ANTLR3::Error::RecognitionError => re
562
+ report_error(re)
563
+ recover(re)
564
+
565
+ ensure
566
+ # -> uncomment the next line to manually enable rule tracing
567
+ # trace_out(__method__, 6)
568
+
569
+ end
570
+
571
+ return
572
+ end
573
+
574
+
575
+
576
+ TOKENS_FOLLOWING_group_name_IN_group_spec_87 = Set[1, 5]
577
+ TOKENS_FOLLOWING_member_IN_group_spec_110 = Set[1, 5]
578
+ TOKENS_FOLLOWING_T__10_IN_group_name_130 = Set[4]
579
+ TOKENS_FOLLOWING_CONSTANT_IN_group_name_146 = Set[11]
580
+ TOKENS_FOLLOWING_T__11_IN_group_name_148 = Set[4]
581
+ TOKENS_FOLLOWING_CONSTANT_IN_group_name_171 = Set[1, 12]
582
+ TOKENS_FOLLOWING_T__12_IN_group_name_179 = Set[1]
583
+ TOKENS_FOLLOWING_ID_IN_member_201 = Set[5, 13, 14, 17, 18]
584
+ TOKENS_FOLLOWING_parameter_declaration_IN_member_205 = Set[13]
585
+ TOKENS_FOLLOWING_T__13_IN_member_212 = Set[5, 6, 7]
586
+ TOKENS_FOLLOWING_ID_IN_member_222 = Set[1]
587
+ TOKENS_FOLLOWING_TEMPLATE_IN_member_232 = Set[1]
588
+ TOKENS_FOLLOWING_STRING_IN_member_244 = Set[1]
589
+ TOKENS_FOLLOWING_T__14_IN_parameter_declaration_272 = Set[5, 14, 15, 17, 18]
590
+ TOKENS_FOLLOWING_parameters_IN_parameter_declaration_276 = Set[15]
591
+ TOKENS_FOLLOWING_T__15_IN_parameter_declaration_283 = Set[1]
592
+ TOKENS_FOLLOWING_parameters_IN_parameter_declaration_289 = Set[1]
593
+ TOKENS_FOLLOWING_parameter_IN_parameters_313 = Set[1, 16]
594
+ TOKENS_FOLLOWING_T__16_IN_parameters_318 = Set[5, 14, 17, 18]
595
+ TOKENS_FOLLOWING_parameter_IN_parameters_320 = Set[1, 16]
596
+ TOKENS_FOLLOWING_T__17_IN_parameter_338 = Set[5]
597
+ TOKENS_FOLLOWING_ID_IN_parameter_342 = Set[1]
598
+ TOKENS_FOLLOWING_T__18_IN_parameter_350 = Set[5]
599
+ TOKENS_FOLLOWING_ID_IN_parameter_354 = Set[1]
600
+ TOKENS_FOLLOWING_ID_IN_parameter_364 = Set[1, 19]
601
+ TOKENS_FOLLOWING_T__19_IN_parameter_378 = Set[7]
602
+ TOKENS_FOLLOWING_STRING_IN_parameter_382 = Set[1]
603
+
604
+ end # class Parser < ANTLR3::Parser
605
+
606
+ end
607
+ # - - - - - - begin action @parser::footer - - - - - -
608
+ # Group.g
609
+
610
+
611
+ end # module Template
612
+ end # module ANTLR3
613
+
614
+ # - - - - - - end action @parser::footer - - - - - - -
615
+
616
+
617
+ if __FILE__ == $0 and ARGV.first != '--'
618
+ # - - - - - - begin action @parser::main - - - - - -
619
+ # Group.g
620
+
621
+
622
+ defined?(ANTLR3::Template::Group::Lexer) or require 'antlr3/template/group-lexer'
623
+ ANTLR3::Template::Group::Parser.main( ARGV )
624
+
625
+ # - - - - - - end action @parser::main - - - - - - -
626
+
627
+ end