antlr3 1.6.3 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -624,7 +624,7 @@ def EarlyExit( decision, input = @input )
624
624
  end
625
625
 
626
626
  def FailedPredicate( rule, predicate, input = @input )
627
- FailedPredicate.new( input, rule_name, predicate )
627
+ FailedPredicate.new( input, rule, predicate )
628
628
  end
629
629
 
630
630
  def MismatchedTreeNode( expecting, input = @input )
@@ -444,8 +444,8 @@ class ParserMain < Main
444
444
  parser_options[ :log ] = @log
445
445
  end
446
446
  lexer = @lexer_class.new( in_stream )
447
- token_stream = CommonTokenStream.new( lexer )
448
- parser = @parser_class.new( token_stream, parser_options )
447
+ # token_stream = CommonTokenStream.new( lexer )
448
+ parser = @parser_class.new( lexer, parser_options )
449
449
  result = parser.send( @parser_rule ) and present( result )
450
450
  end
451
451
 
@@ -121,7 +121,8 @@ class RecognizerSharedState
121
121
  self.text = nil
122
122
  end
123
123
  end
124
- end
124
+
125
+ end # unless const_defined?( :RecognizerSharedState )
125
126
 
126
127
 
127
128
  =begin rdoc ANTLR3::Recognizer
@@ -336,8 +337,7 @@ class Recognizer
336
337
  return matched_symbol
337
338
  end
338
339
  raise( BacktrackingFailed ) if @state.backtracking > 0
339
- matched_symbol = recover_from_mismatched_token( type, follow )
340
- return matched_symbol
340
+ return recover_from_mismatched_token( type, follow )
341
341
  end
342
342
 
343
343
  # match anything -- i.e. wildcard match. Simply consume
@@ -574,23 +574,15 @@ class Recognizer
574
574
  def recover_from_mismatched_token( type, follow )
575
575
  if mismatch_is_unwanted_token?( type )
576
576
  err = UnwantedToken( type )
577
-
578
- resync do
579
- @input.consume
580
- end
581
-
577
+ resync { @input.consume }
582
578
  report_error( err )
583
579
 
584
- matched_symbol = current_symbol
585
- @input.consume
586
- return matched_symbol
580
+ return @input.consume
587
581
  end
588
582
 
589
583
  if mismatch_is_missing_token?( follow )
590
- inserted = missing_symbol( err, type, follow )
591
- err = MissingToken( type, inserted )
592
-
593
- report_error( err )
584
+ inserted = missing_symbol( nil, type, follow )
585
+ report_error( MissingToken( type, inserted ) )
594
586
  return inserted
595
587
  end
596
588
 
@@ -1135,7 +1127,7 @@ private
1135
1127
  case input
1136
1128
  when CharacterStream then input
1137
1129
  when ::String then StringStream.new( input, options )
1138
- when ::IO then FileStream.new( input, options )
1130
+ when ::IO, ARGF then FileStream.new( input, options )
1139
1131
  else input
1140
1132
  end
1141
1133
  end
@@ -646,6 +646,9 @@ class FileStream < StringStream
646
646
  when $stdin then
647
647
  data = $stdin.read
648
648
  @name = '(stdin)'
649
+ when ARGF
650
+ data = file.read
651
+ @name = file.path
649
652
  when ::File then
650
653
  file = file.clone
651
654
  file.reopen( file.path, 'r' )
@@ -831,6 +834,19 @@ class CommonTokenStream
831
834
  seek( marker )
832
835
  end
833
836
 
837
+ #
838
+ # saves the current stream position, yields to the block,
839
+ # and then ensures the stream's position is restored before
840
+ # returning the value of the block
841
+ #
842
+ def hold( pos = @position )
843
+ block_given? or return enum_for( :hold, pos )
844
+ begin
845
+ yield
846
+ ensure
847
+ seek( pos )
848
+ end
849
+ end
834
850
 
835
851
  ###### Stream Navigation ###########################################
836
852
 
@@ -937,6 +953,41 @@ class CommonTokenStream
937
953
  tokens( *args ).each { |token| yield( token ) }
938
954
  end
939
955
 
956
+
957
+ #
958
+ # yields each token in the stream with the given channel value
959
+ # If no channel value is given, the stream's tuned channel value will be used.
960
+ # If no block is given, an enumerator will be returned.
961
+ #
962
+ def each_on_channel( channel = @channel )
963
+ block_given? or return enum_for( :each_on_channel, channel )
964
+ for token in @tokens
965
+ token.channel == channel and yield( token )
966
+ end
967
+ end
968
+
969
+ #
970
+ # iterates through the token stream, yielding each on channel token along the way.
971
+ # After iteration has completed, the stream's position will be restored to where
972
+ # it was before #walk was called. While #each or #each_on_channel does not change
973
+ # the positions stream during iteration, #walk advances through the stream. This
974
+ # makes it possible to look ahead and behind the current token during iteration.
975
+ # If no block is given, an enumerator will be returned.
976
+ #
977
+ def walk
978
+ block_given? or return enum_for( :walk )
979
+ initial_position = @position
980
+ begin
981
+ while token = look and token.type != EOF
982
+ consume
983
+ yield( token )
984
+ end
985
+ return self
986
+ ensure
987
+ @position = initial_position
988
+ end
989
+ end
990
+
940
991
  #
941
992
  # returns a copy of the token buffer. If +start+ and +stop+ are provided, tokens
942
993
  # returns a slice of the token buffer from <tt>start..stop</tt>. The parameters
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'antlr3'
5
+ require 'rake'
5
6
  require 'rake/tasklib'
6
7
  require 'shellwords'
7
8
 
@@ -84,9 +84,12 @@ private
84
84
 
85
85
  end
86
86
 
87
+
88
+ autoload :GroupFile, 'antlr3/template/group-file'
89
+
87
90
  class Group < Module
88
- autoload :Lexer, 'antlr3/template/group-lexer'
89
- autoload :Parser, 'antlr3/template/group-parser'
91
+ autoload :Lexer, 'antlr3/template/group-file'
92
+ autoload :Parser, 'antlr3/template/group-file'
90
93
 
91
94
  def self.parse( source, options = {} )
92
95
  namespace = options.fetch( :namespace, ::Object )
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Group.g
3
+ # GroupFile.g
4
4
  #
5
5
  # Generated using ANTLR version: 3.2.1-SNAPSHOT Dec 18, 2009 04:29:28
6
- # Ruby runtime library version: 1.5.0
7
- # Input grammar file: Group.g
8
- # Generated at: 2010-01-27 10:24:01
6
+ # Ruby runtime library version: 1.6.3
7
+ # Input grammar file: GroupFile.g
8
+ # Generated at: 2010-03-19 19:43:54
9
9
  #
10
10
 
11
11
  # ~~~> start load path setup
@@ -16,7 +16,7 @@ antlr_load_failed = proc do
16
16
  load_path = $LOAD_PATH.map { |dir| ' - ' << dir }.join( $/ )
17
17
  raise LoadError, <<-END.strip!
18
18
 
19
- Failed to load the ANTLR3 runtime library (version 1.5.0):
19
+ Failed to load the ANTLR3 runtime library (version 1.6.3):
20
20
 
21
21
  Ensure the library has been installed on your system and is available
22
22
  on the load path. If rubygems is available on your system, this can
@@ -46,7 +46,7 @@ rescue LoadError
46
46
 
47
47
  # 3: try to activate the antlr3 gem
48
48
  begin
49
- Gem.activate( 'antlr3', '~> 1.5.0' )
49
+ Gem.activate( 'antlr3', '~> 1.6.3' )
50
50
  rescue Gem::LoadError
51
51
  antlr_load_failed.call
52
52
  end
@@ -57,7 +57,7 @@ end
57
57
  # <~~~ end load path setup
58
58
 
59
59
  # - - - - - - begin action @lexer::header - - - - - -
60
- # Group.g
60
+ # GroupFile.g
61
61
 
62
62
 
63
63
  module ANTLR3
@@ -66,7 +66,7 @@ module Template
66
66
  # - - - - - - end action @lexer::header - - - - - - -
67
67
 
68
68
 
69
- class Group
69
+ module GroupFile
70
70
  # TokenData defines all of the token type integer values
71
71
  # as constants, which will be included in all
72
72
  # ANTLR-generated recognizers.
@@ -84,11 +84,11 @@ class Group
84
84
 
85
85
 
86
86
  class Lexer < ANTLR3::Lexer
87
- @grammar_home = Group
87
+ @grammar_home = GroupFile
88
88
  include TokenData
89
89
 
90
90
  begin
91
- generated_using( "Group.g", "3.2.1-SNAPSHOT Dec 18, 2009 04:29:28", "1.5.0" )
91
+ generated_using( "GroupFile.g", "3.2.1-SNAPSHOT Dec 18, 2009 04:29:28", "1.6.3" )
92
92
  rescue NoMethodError => error
93
93
  error.name.to_sym == :generated_using or raise
94
94
  end
@@ -108,7 +108,7 @@ class Group
108
108
 
109
109
  # - - - - - - - - - - - lexer rules - - - - - - - - - - - -
110
110
  # lexer rule t__10! (T__10)
111
- # (in Group.g)
111
+ # (in GroupFile.g)
112
112
  def t__10!
113
113
  # -> uncomment the next line to manually enable rule tracing
114
114
  # trace_in(__method__, 1)
@@ -132,7 +132,7 @@ class Group
132
132
  end
133
133
 
134
134
  # lexer rule t__11! (T__11)
135
- # (in Group.g)
135
+ # (in GroupFile.g)
136
136
  def t__11!
137
137
  # -> uncomment the next line to manually enable rule tracing
138
138
  # trace_in(__method__, 2)
@@ -156,7 +156,7 @@ class Group
156
156
  end
157
157
 
158
158
  # lexer rule t__12! (T__12)
159
- # (in Group.g)
159
+ # (in GroupFile.g)
160
160
  def t__12!
161
161
  # -> uncomment the next line to manually enable rule tracing
162
162
  # trace_in(__method__, 3)
@@ -180,7 +180,7 @@ class Group
180
180
  end
181
181
 
182
182
  # lexer rule t__13! (T__13)
183
- # (in Group.g)
183
+ # (in GroupFile.g)
184
184
  def t__13!
185
185
  # -> uncomment the next line to manually enable rule tracing
186
186
  # trace_in(__method__, 4)
@@ -204,7 +204,7 @@ class Group
204
204
  end
205
205
 
206
206
  # lexer rule t__14! (T__14)
207
- # (in Group.g)
207
+ # (in GroupFile.g)
208
208
  def t__14!
209
209
  # -> uncomment the next line to manually enable rule tracing
210
210
  # trace_in(__method__, 5)
@@ -228,7 +228,7 @@ class Group
228
228
  end
229
229
 
230
230
  # lexer rule t__15! (T__15)
231
- # (in Group.g)
231
+ # (in GroupFile.g)
232
232
  def t__15!
233
233
  # -> uncomment the next line to manually enable rule tracing
234
234
  # trace_in(__method__, 6)
@@ -252,7 +252,7 @@ class Group
252
252
  end
253
253
 
254
254
  # lexer rule t__16! (T__16)
255
- # (in Group.g)
255
+ # (in GroupFile.g)
256
256
  def t__16!
257
257
  # -> uncomment the next line to manually enable rule tracing
258
258
  # trace_in(__method__, 7)
@@ -276,7 +276,7 @@ class Group
276
276
  end
277
277
 
278
278
  # lexer rule t__17! (T__17)
279
- # (in Group.g)
279
+ # (in GroupFile.g)
280
280
  def t__17!
281
281
  # -> uncomment the next line to manually enable rule tracing
282
282
  # trace_in(__method__, 8)
@@ -300,7 +300,7 @@ class Group
300
300
  end
301
301
 
302
302
  # lexer rule t__18! (T__18)
303
- # (in Group.g)
303
+ # (in GroupFile.g)
304
304
  def t__18!
305
305
  # -> uncomment the next line to manually enable rule tracing
306
306
  # trace_in(__method__, 9)
@@ -324,7 +324,7 @@ class Group
324
324
  end
325
325
 
326
326
  # lexer rule t__19! (T__19)
327
- # (in Group.g)
327
+ # (in GroupFile.g)
328
328
  def t__19!
329
329
  # -> uncomment the next line to manually enable rule tracing
330
330
  # trace_in(__method__, 10)
@@ -348,7 +348,7 @@ class Group
348
348
  end
349
349
 
350
350
  # lexer rule constant! (CONSTANT)
351
- # (in Group.g)
351
+ # (in GroupFile.g)
352
352
  def constant!
353
353
  # -> uncomment the next line to manually enable rule tracing
354
354
  # trace_in(__method__, 11)
@@ -358,9 +358,9 @@ class Group
358
358
 
359
359
 
360
360
  # - - - - main rule block - - - -
361
- # at line 127:5: 'A' .. 'Z' ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
361
+ # at line 125:5: 'A' .. 'Z' ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
362
362
  match_range(?A, ?Z)
363
- # at line 127:14: ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
363
+ # at line 125:14: ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
364
364
  while true # decision 1
365
365
  alt_1 = 2
366
366
  look_1_0 = @input.peek(1)
@@ -398,7 +398,7 @@ class Group
398
398
  end
399
399
 
400
400
  # lexer rule id! (ID)
401
- # (in Group.g)
401
+ # (in GroupFile.g)
402
402
  def id!
403
403
  # -> uncomment the next line to manually enable rule tracing
404
404
  # trace_in(__method__, 12)
@@ -408,7 +408,7 @@ class Group
408
408
 
409
409
 
410
410
  # - - - - main rule block - - - -
411
- # at line 131:5: ( 'a' .. 'z' | '_' ) ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
411
+ # at line 129:5: ( 'a' .. 'z' | '_' ) ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
412
412
  if @input.peek(1) == ?_ || @input.peek(1).between?(?a, ?z)
413
413
  @input.consume
414
414
  else
@@ -418,7 +418,7 @@ class Group
418
418
  end
419
419
 
420
420
 
421
- # at line 132:5: ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
421
+ # at line 130:5: ( 'a' .. 'z' | '_' | 'A' .. 'Z' | '0' .. '9' )*
422
422
  while true # decision 2
423
423
  alt_2 = 2
424
424
  look_2_0 = @input.peek(1)
@@ -456,7 +456,7 @@ class Group
456
456
  end
457
457
 
458
458
  # lexer rule template! (TEMPLATE)
459
- # (in Group.g)
459
+ # (in GroupFile.g)
460
460
  def template!
461
461
  # -> uncomment the next line to manually enable rule tracing
462
462
  # trace_in(__method__, 13)
@@ -466,9 +466,9 @@ class Group
466
466
 
467
467
 
468
468
  # - - - - main rule block - - - -
469
- # at line 136:5: '<<<' ( options {greedy=false; } : '\\\\' . | . )* '>>>'
469
+ # at line 134:5: '<<<' ( options {greedy=false; } : '\\\\' . | . )* '>>>'
470
470
  match("<<<")
471
- # at line 137:5: ( options {greedy=false; } : '\\\\' . | . )*
471
+ # at line 135:5: ( options {greedy=false; } : '\\\\' . | . )*
472
472
  while true # decision 3
473
473
  alt_3 = 3
474
474
  look_3_0 = @input.peek(1)
@@ -506,12 +506,12 @@ class Group
506
506
  end
507
507
  case alt_3
508
508
  when 1
509
- # at line 137:35: '\\\\' .
509
+ # at line 135:35: '\\\\' .
510
510
  match(?\\)
511
511
  match_any
512
512
 
513
513
  when 2
514
- # at line 137:44: .
514
+ # at line 135:44: .
515
515
  match_any
516
516
 
517
517
  else
@@ -531,7 +531,7 @@ class Group
531
531
  end
532
532
 
533
533
  # lexer rule string! (STRING)
534
- # (in Group.g)
534
+ # (in GroupFile.g)
535
535
  def string!
536
536
  # -> uncomment the next line to manually enable rule tracing
537
537
  # trace_in(__method__, 14)
@@ -541,7 +541,7 @@ class Group
541
541
 
542
542
 
543
543
  # - - - - main rule block - - - -
544
- # at line 142:3: ( '\"' (~ ( '\\\\' | '\"' ) | '\\\\' . )* '\"' | '\\'' (~ ( '\\\\' | '\\'' ) | '\\\\' . )* '\\'' )
544
+ # at line 140:3: ( '\"' (~ ( '\\\\' | '\"' ) | '\\\\' . )* '\"' | '\\'' (~ ( '\\\\' | '\\'' ) | '\\\\' . )* '\\'' )
545
545
  alt_6 = 2
546
546
  look_6_0 = @input.peek(1)
547
547
 
@@ -555,9 +555,9 @@ class Group
555
555
  end
556
556
  case alt_6
557
557
  when 1
558
- # at line 142:5: '\"' (~ ( '\\\\' | '\"' ) | '\\\\' . )* '\"'
558
+ # at line 140:5: '\"' (~ ( '\\\\' | '\"' ) | '\\\\' . )* '\"'
559
559
  match(?")
560
- # at line 142:10: (~ ( '\\\\' | '\"' ) | '\\\\' . )*
560
+ # at line 140:10: (~ ( '\\\\' | '\"' ) | '\\\\' . )*
561
561
  while true # decision 4
562
562
  alt_4 = 3
563
563
  look_4_0 = @input.peek(1)
@@ -570,7 +570,7 @@ class Group
570
570
  end
571
571
  case alt_4
572
572
  when 1
573
- # at line 142:12: ~ ( '\\\\' | '\"' )
573
+ # at line 140:12: ~ ( '\\\\' | '\"' )
574
574
  if @input.peek(1).between?(0x0000, ?!) || @input.peek(1).between?(?#, ?[) || @input.peek(1).between?(?], 0x00FF)
575
575
  @input.consume
576
576
  else
@@ -582,7 +582,7 @@ class Group
582
582
 
583
583
 
584
584
  when 2
585
- # at line 142:31: '\\\\' .
585
+ # at line 140:31: '\\\\' .
586
586
  match(?\\)
587
587
  match_any
588
588
 
@@ -593,9 +593,9 @@ class Group
593
593
  match(?")
594
594
 
595
595
  when 2
596
- # at line 143:5: '\\'' (~ ( '\\\\' | '\\'' ) | '\\\\' . )* '\\''
596
+ # at line 141:5: '\\'' (~ ( '\\\\' | '\\'' ) | '\\\\' . )* '\\''
597
597
  match(?\')
598
- # at line 143:10: (~ ( '\\\\' | '\\'' ) | '\\\\' . )*
598
+ # at line 141:10: (~ ( '\\\\' | '\\'' ) | '\\\\' . )*
599
599
  while true # decision 5
600
600
  alt_5 = 3
601
601
  look_5_0 = @input.peek(1)
@@ -608,7 +608,7 @@ class Group
608
608
  end
609
609
  case alt_5
610
610
  when 1
611
- # at line 143:12: ~ ( '\\\\' | '\\'' )
611
+ # at line 141:12: ~ ( '\\\\' | '\\'' )
612
612
  if @input.peek(1).between?(0x0000, ?&) || @input.peek(1).between?(?(, ?[) || @input.peek(1).between?(?], 0x00FF)
613
613
  @input.consume
614
614
  else
@@ -620,7 +620,7 @@ class Group
620
620
 
621
621
 
622
622
  when 2
623
- # at line 143:31: '\\\\' .
623
+ # at line 141:31: '\\\\' .
624
624
  match(?\\)
625
625
  match_any
626
626
 
@@ -642,7 +642,7 @@ class Group
642
642
  end
643
643
 
644
644
  # lexer rule comment! (COMMENT)
645
- # (in Group.g)
645
+ # (in GroupFile.g)
646
646
  def comment!
647
647
  # -> uncomment the next line to manually enable rule tracing
648
648
  # trace_in(__method__, 15)
@@ -652,7 +652,7 @@ class Group
652
652
 
653
653
 
654
654
  # - - - - main rule block - - - -
655
- # at line 148:3: ( ( '#' | '//' ) (~ '\\n' )* | '/*' ( . )* '*/' )
655
+ # at line 146:3: ( ( '#' | '//' ) (~ '\\n' )* | '/*' ( . )* '*/' )
656
656
  alt_10 = 2
657
657
  look_10_0 = @input.peek(1)
658
658
 
@@ -675,8 +675,8 @@ class Group
675
675
  end
676
676
  case alt_10
677
677
  when 1
678
- # at line 148:5: ( '#' | '//' ) (~ '\\n' )*
679
- # at line 148:5: ( '#' | '//' )
678
+ # at line 146:5: ( '#' | '//' ) (~ '\\n' )*
679
+ # at line 146:5: ( '#' | '//' )
680
680
  alt_7 = 2
681
681
  look_7_0 = @input.peek(1)
682
682
 
@@ -690,15 +690,15 @@ class Group
690
690
  end
691
691
  case alt_7
692
692
  when 1
693
- # at line 148:7: '#'
693
+ # at line 146:7: '#'
694
694
  match(?#)
695
695
 
696
696
  when 2
697
- # at line 148:13: '//'
697
+ # at line 146:13: '//'
698
698
  match("//")
699
699
 
700
700
  end
701
- # at line 148:20: (~ '\\n' )*
701
+ # at line 146:20: (~ '\\n' )*
702
702
  while true # decision 8
703
703
  alt_8 = 2
704
704
  look_8_0 = @input.peek(1)
@@ -709,7 +709,7 @@ class Group
709
709
  end
710
710
  case alt_8
711
711
  when 1
712
- # at line 148:20: ~ '\\n'
712
+ # at line 146:20: ~ '\\n'
713
713
  if @input.peek(1).between?(0x0000, ?\t) || @input.peek(1).between?(0x000B, 0x00FF)
714
714
  @input.consume
715
715
  else
@@ -726,9 +726,9 @@ class Group
726
726
  end # loop for decision 8
727
727
 
728
728
  when 2
729
- # at line 149:5: '/*' ( . )* '*/'
729
+ # at line 147:5: '/*' ( . )* '*/'
730
730
  match("/*")
731
- # at line 149:10: ( . )*
731
+ # at line 147:10: ( . )*
732
732
  while true # decision 9
733
733
  alt_9 = 2
734
734
  look_9_0 = @input.peek(1)
@@ -748,7 +748,7 @@ class Group
748
748
  end
749
749
  case alt_9
750
750
  when 1
751
- # at line 149:10: .
751
+ # at line 147:10: .
752
752
  match_any
753
753
 
754
754
  else
@@ -771,7 +771,7 @@ class Group
771
771
  end
772
772
 
773
773
  # lexer rule ws! (WS)
774
- # (in Group.g)
774
+ # (in GroupFile.g)
775
775
  def ws!
776
776
  # -> uncomment the next line to manually enable rule tracing
777
777
  # trace_in(__method__, 16)
@@ -781,13 +781,13 @@ class Group
781
781
 
782
782
 
783
783
  # - - - - main rule block - - - -
784
- # at line 153:5: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+
785
- # at file 153:5: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+
784
+ # at line 151:5: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+
785
+ # at file 151:5: ( ' ' | '\\t' | '\\n' | '\\r' | '\\f' )+
786
786
  match_count_11 = 0
787
787
  while true
788
788
  alt_11 = 2
789
789
  look_11_0 = @input.peek(1)
790
-
790
+
791
791
  if (look_11_0.between?(?\t, ?\n) || look_11_0.between?(?\f, ?\r) || look_11_0 == ?\s)
792
792
  alt_11 = 1
793
793
 
@@ -981,7 +981,7 @@ class Group
981
981
  at_exit { Lexer.main(ARGV) } if __FILE__ == $0
982
982
  end
983
983
  # - - - - - - begin action @lexer::footer - - - - - -
984
- # Group.g
984
+ # GroupFile.g
985
985
 
986
986
 
987
987
  end # module Template