antlr3 1.9.2 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/samples/JavaScript.g CHANGED
@@ -49,47 +49,47 @@ tokens {
49
49
  scope InFor { active; }
50
50
 
51
51
  @parser::members {
52
-
52
+
53
53
  def auto_semicolon?( error )
54
54
  if NoViableAlternative === error
55
55
  return( @auto_semicolon = error ) unless same_line?
56
56
  end
57
57
  return false
58
58
  end
59
-
59
+
60
60
  def recover( error = $! )
61
61
  @auto_semicolon == error and return( @auto_semicolon = nil )
62
62
  super
63
63
  end
64
-
64
+
65
65
  def report_error( error = $! )
66
66
  auto_semicolon?( error ) and return
67
67
  super
68
68
  end
69
-
69
+
70
70
  def newline?( from = 1 )
71
71
  to = from == -1 ? 1 : from + 1
72
72
  start = @input.future?( from )
73
73
  stop = @input.future?( to )
74
-
74
+
75
75
  start.upto( stop ) do | i |
76
76
  @input.at( i ).type == NEWLINE and return( true )
77
77
  end
78
-
78
+
79
79
  return( false )
80
80
  end
81
-
81
+
82
82
  def same_line?
83
83
  stop = @input.future? || @input.length
84
84
  start = @input.past? || 0
85
-
85
+
86
86
  start.upto( stop ) do | i |
87
87
  @input.at( i ).type == NEWLINE and return( false )
88
88
  end
89
-
89
+
90
90
  return( true )
91
91
  end
92
-
92
+
93
93
  def prepend_tree( root, child )
94
94
  child = @adaptor.rule_post_processing( child )
95
95
  root.unshift( child )
@@ -101,14 +101,13 @@ scope InFor { active; }
101
101
 
102
102
  @lexer::members {
103
103
  attr_accessor :value_expected
104
-
104
+
105
105
  NO_VALUE_FOLLOWS = Set[
106
106
  ID, REGEX, STRING, NUMBER, THIS,
107
107
  TRUE, FALSE, NULL, UNDEFINED,
108
- RPAREN, RBRACK, RBRACE,
109
- IVAR, DOC, YAML, WORDS
108
+ RPAREN, RBRACK, RBRACE
110
109
  ]
111
-
110
+
112
111
  def next_token
113
112
  token = super
114
113
  unless token.hidden?
@@ -134,7 +133,7 @@ program
134
133
  : source_elements -> source_elements
135
134
  | -> ^( UNDEFINED )
136
135
  ;
137
-
136
+
138
137
  source_elements
139
138
  : statement ( statement )*
140
139
  ;
@@ -147,7 +146,7 @@ block
147
146
  statement_block
148
147
  : '{' statement_list? '}' -> ^( BLOCK statement_list? )
149
148
  ;
150
-
149
+
151
150
  statement_list
152
151
  : statement+ -> statement+
153
152
  ;
@@ -182,9 +181,9 @@ statement
182
181
  | try_statement
183
182
  ;
184
183
 
185
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186
185
  // Simple Statements
187
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
188
187
 
189
188
  empty_statement
190
189
  : ';' ->
@@ -208,9 +207,9 @@ blank
208
207
  : -> ^( UNDEFINED )
209
208
  ;
210
209
 
211
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212
211
  // Block-ish Statements
213
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
214
213
 
215
214
  try_statement
216
215
  : 'try'
@@ -235,9 +234,9 @@ with_statement
235
234
  : 'with' clause block -> ^( 'with' clause block )
236
235
  ;
237
236
 
238
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
237
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
239
238
  // Variable Declarations
240
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
239
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
241
240
 
242
241
  variable_statement
243
242
  : 'var'^ variable_declaration_list statement_end!
@@ -264,39 +263,39 @@ declaration_target
264
263
  | '{' declaration_key ( ',' declaration_key )* '}' -> ^( OBJECT declaration_key+ )
265
264
  | variable_name -> variable_name
266
265
  ;
267
-
266
+
268
267
  declaration_key
269
268
  : property_name ':'^ declaration_target
270
269
  ;
271
270
 
272
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
271
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
273
272
  // Branching Statements
274
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
273
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275
274
 
276
275
  if_statement
277
276
  : 'if'^ clause block ( 'else'! block )?
278
277
  ;
279
278
 
280
279
  switch_statement
281
- : 'switch' '(' expression_list ')'
280
+ : 'switch' '(' expression_list ')'
282
281
  '{'
283
282
  ( case_clause )*
284
- ( default_clause ( case_clause )* )?
283
+ ( default_clause ( case_clause )* )?
285
284
  '}'
286
285
  -> ^( 'switch' expression_list case_clause* default_clause? )
287
286
  ;
288
-
287
+
289
288
  case_clause
290
289
  : 'case'^ expression_list ':'! statement_list?
291
290
  ;
292
-
291
+
293
292
  default_clause
294
293
  : 'default'^ ':'! statement_list?
295
294
  ;
296
295
 
297
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
296
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
298
297
  // While Loops
299
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
298
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
300
299
 
301
300
  do_while_statement
302
301
  : 'do' block 'while' clause statement_end
@@ -307,9 +306,9 @@ while_statement
307
306
  : 'while'^ clause block
308
307
  ;
309
308
 
310
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
309
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
311
310
  // For Loops
312
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
311
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
313
312
 
314
313
  for_loop
315
314
  : { @input.peek( 2 ) == EACH }?=> for_each_in_statement
@@ -326,7 +325,7 @@ for_statement
326
325
  ')'!
327
326
  block
328
327
  ;
329
-
328
+
330
329
  for_statement_initialiser_part
331
330
  scope InFor;
332
331
  @before { $InFor::active = true }
@@ -339,12 +338,12 @@ for_each_in_statement
339
338
  : 'for' 'each' '(' for_in_statement_initialiser_part 'in' expression ')' block
340
339
  -> ^( 'each' for_in_statement_initialiser_part expression block )
341
340
  ;
342
-
341
+
343
342
  for_in_statement
344
343
  : f='for' '(' for_in_statement_initialiser_part 'in' expression ')' block
345
344
  -> ^( FOR_IN[ $f ] for_in_statement_initialiser_part expression block )
346
345
  ;
347
-
346
+
348
347
  for_in_statement_initialiser_part
349
348
  scope InFor;
350
349
  @before { $InFor::active = true }
@@ -353,9 +352,9 @@ for_in_statement_initialiser_part
353
352
  | member
354
353
  ;
355
354
 
356
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
355
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
357
356
  // Flow Control
358
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
357
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
359
358
 
360
359
  continue_statement
361
360
  : 'continue'^ ( { same_line? }?=> ID )? statement_end!
@@ -372,7 +371,7 @@ return_statement
372
371
  yield_statement
373
372
  : 'yield'^ ( { same_line? }?=> expression_list )? statement_end!
374
373
  ;
375
-
374
+
376
375
  throw_statement
377
376
  : 'throw'^ ( { same_line? }?=> expression_list )? statement_end!
378
377
  ;
@@ -430,9 +429,9 @@ bit_and
430
429
  ;
431
430
 
432
431
  equality
433
- : relation
434
- (
435
- ( '=='^ | '!='^ | '==='^ | '!=='^ )
432
+ : relation
433
+ (
434
+ ( '=='^ | '!='^ | '==='^ | '!=='^ )
436
435
  relation
437
436
  )*
438
437
  ;
@@ -440,7 +439,7 @@ equality
440
439
  relation
441
440
  : shift ( relation_op^ shift )*
442
441
  ;
443
-
442
+
444
443
  relation_op
445
444
  : '<'
446
445
  | '>'
@@ -485,9 +484,9 @@ postfix
485
484
  )
486
485
  ;
487
486
 
488
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
487
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
489
488
  // Atomic Expressions
490
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
489
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
491
490
 
492
491
  member
493
492
  : ( receiver -> receiver )
@@ -495,7 +494,7 @@ member
495
494
  | arguments -> ^( CALL $member arguments )
496
495
  )*
497
496
  ;
498
-
497
+
499
498
  accessor
500
499
  : '[' expression ']' -> ^( AREF[ '[' ] expression ) //]
501
500
  | '.' property_name -> ^( '.' property_name )
@@ -517,14 +516,14 @@ arguments
517
516
  : '(' ( expression ( ',' expression )* )? ')' -> ^( ARGUMENTS expression* )
518
517
  ;
519
518
 
520
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
519
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
521
520
  // Functions / Blocks
522
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
521
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
523
522
 
524
523
  function
525
524
  : 'function'^ variable_name? function_parameters statement_block
526
525
  ;
527
-
526
+
528
527
  function_parameters
529
528
  : '(' parameters? ')' -> ^( PARAMS parameters? )
530
529
  ;
@@ -533,9 +532,9 @@ parameters
533
532
  : variable_name ( ',' variable_name )* -> variable_name+
534
533
  ;
535
534
 
536
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
535
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
537
536
  // Literals
538
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
537
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
539
538
 
540
539
  primary
541
540
  : 'this'^
@@ -556,12 +555,12 @@ array_literal
556
555
  : '[' ']' -> ^( ARRAY )
557
556
  | '[' list_item ( ',' list_item )* ']' -> ^( ARRAY list_item* )
558
557
  ;
559
-
558
+
560
559
  list_item
561
560
  : ( ',' )=> -> ^( UNDEFINED )
562
561
  | expression -> expression
563
562
  ;
564
-
563
+
565
564
  object_literal
566
565
  : '{' '}' -> ^( OBJECT )
567
566
  | '{' property_definition ( ',' property_definition )* '}'
@@ -574,9 +573,9 @@ property_definition
574
573
  | property_name ':'^ expression
575
574
  ;
576
575
 
577
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
576
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
578
577
  // Names and Words
579
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
578
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
580
579
 
581
580
  property_name
582
581
  : ID
@@ -598,10 +597,10 @@ pseudokeyword
598
597
 
599
598
  reserved
600
599
  : 'break' | 'do' | 'function' | 'new' | 'throw' | 'until'
601
- | 'case' | 'each' | 'get' | 'null' | 'true' | 'var'
602
- | 'catch' | 'else' | 'if' | 'return' | 'try' | 'void'
600
+ | 'case' | 'each' | 'get' | 'null' | 'true' | 'var'
601
+ | 'catch' | 'else' | 'if' | 'return' | 'try' | 'void'
603
602
  | 'continue' | 'false' | 'in' | 'set' | 'typeof' | 'while'
604
- | 'default' | 'finally' | 'instanceof' | 'switch' | 'undefined' | 'with'
603
+ | 'default' | 'finally' | 'instanceof' | 'switch' | 'undefined' | 'with'
605
604
  | 'delete' | 'for' | 'let' | 'this' | 'unless' | 'yield'
606
605
  ;
607
606
 
@@ -639,5 +638,3 @@ ID
639
638
  WS // Tab, vertical tab, form feed, space, non-breaking space and any other unicode "space separator".
640
639
  : ( '\t' | '\f' | ' ' | '\u00A0' )+ { $channel = HIDDEN }
641
640
  ;
642
-
643
-
data/templates/Ruby.stg CHANGED
@@ -59,7 +59,7 @@ placeAction(scope, name) ::= <<
59
59
  <endif>
60
60
  >>
61
61
 
62
- runtimeLibraryVersion() ::= "1.9.2"
62
+ runtimeLibraryVersion() ::= "1.10.0"
63
63
 
64
64
  /** The overall file structure of a recognizer; stores methods
65
65
  * for rules and cyclic DFAs plus support code.
@@ -71,6 +71,7 @@ class TestMainUtility < ANTLR3::Test::Functional
71
71
  END
72
72
 
73
73
  LexerMainFromStdIO::Lexer.main( [], :input => input, :output => output )
74
+
74
75
  lines = output.string.split( /\n/ )
75
76
  lines.should have( 3 ).things
76
77
  end
@@ -87,12 +88,13 @@ class TestMainUtility < ANTLR3::Test::Functional
87
88
 
88
89
  output = StringIO.new
89
90
  input = StringIO.new( 'yada yada' )
90
-
91
- MainForCombined::Parser.main(
91
+
92
+ MainForCombined::Parser.main(
92
93
  %w(--rule r --lexer-name MainForCombined::Lexer),
93
94
  :input => input, :output => output )
94
- lines = output.string.split( "\n" )
95
- lines.should have( 4 ).things
95
+
96
+ text_out = output.string
97
+ text_out.should include(%q[res="yada yada"])
96
98
  end
97
99
 
98
100
  example 'using built-in main to inspect AST constructed by an AST-building parser' do
@@ -123,7 +123,7 @@ class TestRuleVisibility < ANTLR3::Test::Functional
123
123
  END
124
124
 
125
125
  example 'using visibility modifiers on rules' do
126
- mname = RUBY_VERSION =~ /^1\.9/ ? proc { | n | n.to_sym } : proc { | n | n.to_s }
126
+ mname = RUBY_VERSION >= "1.9" ? proc { | n | n.to_sym } : proc { | n | n.to_s }
127
127
 
128
128
  RuleVisibility::Parser.public_instance_methods.should include( mname[ 'a' ] )
129
129
  RuleVisibility::Parser.protected_instance_methods.should include( mname[ 'c' ] )
@@ -31,7 +31,7 @@ class TestStringStream < Test::Unit::TestCase
31
31
  @stream.index.should == 2
32
32
  @stream.column.should == 2
33
33
  @stream.line.should == 1
34
-
34
+
35
35
  @stream.consume # \n
36
36
  @stream.index.should == 3
37
37
  @stream.column.should == 0
@@ -103,13 +103,9 @@ shared_examples_for "template groups" do
103
103
  for name in TEMPLATE_NAMES
104
104
  @group.should respond_to( name )
105
105
  @group.should respond_to( "#{ name }!" )
106
- if RUBY_VERSION =~ /^1\.9/
107
- @group.private_instance_methods.should include name.to_sym
108
- @group.private_instance_methods.should include :"#{ name }!"
109
- else
110
- @group.private_instance_methods.should include name.to_s
111
- @group.private_instance_methods.should include "#{ name }!"
112
- end
106
+ private_method_names = @group.private_instance_methods.map { | m | m.to_s }
107
+ private_method_names.should include name.to_s
108
+ private_method_names.should include "#{ name }!"
113
109
  end
114
110
  end
115
111