Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new baseline git repository

  • Loading branch information...
commit 7bcba407e274b996c35038f54ecc56425887b958 0 parents
Kyle Yetter authored
Showing with 39,335 additions and 0 deletions.
  1. BIN  ._antlr-3.2
  2. +4,968 −0 .bzrignore
  3. +20 −0 .juju.log
  4. +17 −0 .project
  5. +3,236 −0 .quick-backup
  6. +180 −0 .tasks/antlr.rake
  7. +112 −0 .tasks/dist.rake
  8. BIN  .tdldb
  9. BIN  .tdldb.bak
  10. +26 −0 ANTLR-LICENSE.txt
  11. +66 −0 History.txt
  12. +51 −0 INSTALL.txt
  13. +88 −0 Manifest.txt
  14. +102 −0 README.txt
  15. +413 −0 Rakefile
  16. +254 −0 antlr3.kpf
  17. +33 −0 bin/antlr4ruby
  18. +87 −0 config/Manifest.txt
  19. +138 −0 config/antlr-project.rb
  20. +117 −0 config/irb.rb
  21. +111 −0 config/project.rb
  22. +14 −0 config/project.yaml
  23. +28 −0 config/test-codes.yaml
  24. +26 −0 dist/ANTLR-LICENSE.txt
  25. +4 −0 dist/History.txt
  26. +84 −0 dist/Manifest.txt
  27. +107 −0 dist/README.txt
  28. +56 −0 dist/Rakefile
  29. +29 −0 dist/bin/antlr4ruby
  30. +524 −0 dist/java/RubyTarget.java
  31. BIN  dist/java/antlr-full-3.2.jar
  32. +190 −0 dist/lib/antlr3.rb
  33. +88 −0 dist/lib/antlr3/constants.rb
  34. +687 −0 dist/lib/antlr3/debug.rb
  35. +210 −0 dist/lib/antlr3/debug/event-hub.rb
  36. +25 −0 dist/lib/antlr3/debug/record-event-listener.rb
  37. +55 −0 dist/lib/antlr3/debug/rule-tracer.rb
  38. +312 −0 dist/lib/antlr3/debug/socket.rb
  39. +92 −0 dist/lib/antlr3/debug/trace-event-listener.rb
  40. +247 −0 dist/lib/antlr3/dfa.rb
  41. +174 −0 dist/lib/antlr3/dot.rb
  42. +657 −0 dist/lib/antlr3/error.rb
  43. +649 −0 dist/lib/antlr3/main.rb
  44. +316 −0 dist/lib/antlr3/profile.rb
  45. +1,219 −0 dist/lib/antlr3/recognizers.rb
  46. +939 −0 dist/lib/antlr3/streams.rb
  47. +411 −0 dist/lib/antlr3/streams/rewrite.rb
  48. +51 −0 dist/lib/antlr3/test/call-stack.rb
  49. +23 −0 dist/lib/antlr3/test/config.rb
  50. +293 −0 dist/lib/antlr3/test/core-extensions.rb
  51. +165 −0 dist/lib/antlr3/test/diff.rb
  52. +210 −0 dist/lib/antlr3/test/functional.rb
  53. +324 −0 dist/lib/antlr3/test/grammar.rb
  54. +571 −0 dist/lib/antlr3/token.rb
  55. +1,411 −0 dist/lib/antlr3/tree.rb
  56. +163 −0 dist/lib/antlr3/tree/debug.rb
  57. +84 −0 dist/lib/antlr3/tree/visitor.rb
  58. +481 −0 dist/lib/antlr3/tree/wizard.rb
  59. +46 −0 dist/lib/core-ext/bound.rb
  60. +53 −0 dist/lib/core-ext/range.rb
  61. +744 −0 dist/samples/Cpp.g
  62. +1,023 −0 dist/samples/Java.g
  63. +419 −0 dist/templates/AST.stg
  64. +42 −0 dist/templates/ASTDbg.stg
  65. +134 −0 dist/templates/ASTParser.stg
  66. +248 −0 dist/templates/ASTTreeParser.stg
  67. +217 −0 dist/templates/Dbg.stg
  68. +1,374 −0 dist/templates/Ruby.stg
  69. +2 −0  dist/test/unit/sample-input/file-stream-1
  70. +2 −0  dist/test/unit/sample-input/teststreams.input2
  71. +55 −0 dist/test/unit/test-dfa.rb
  72. +47 −0 dist/test/unit/test-exceptions.rb
  73. +58 −0 dist/test/unit/test-recognizers.rb
  74. +65 −0 dist/test/unit/test-scheme.rb
  75. +453 −0 dist/test/unit/test-streams.rb
  76. +537 −0 dist/test/unit/test-tree-wizard.rb
  77. +857 −0 dist/test/unit/test-trees.rb
  78. +8 −0 doc-writing/.*.html
  79. BIN  doc-writing/.sass-cache/4e816f7531d28d1d334fcb7b23fc2066f2dcb123/ANTLR3.sassc
  80. +57 −0 doc-writing/History.txt
  81. +4 −0 doc-writing/antlr-basics.textile
  82. +82 −0 doc-writing/code-generation.textile
  83. +64 −0 doc-writing/conventions.textile
  84. BIN  doc-writing/images/TN.gif
  85. BIN  doc-writing/images/img01.gif
  86. BIN  doc-writing/images/img02.gif
  87. BIN  doc-writing/images/img03.gif
  88. BIN  doc-writing/images/img04.gif
  89. BIN  doc-writing/images/img05.gif
  90. BIN  doc-writing/images/img06.gif
  91. BIN  doc-writing/images/img07.gif
  92. BIN  doc-writing/images/img08.gif
  93. +184 −0 doc-writing/lexer.textile
  94. +6 −0 doc-writing/overview.textile
  95. +54 −0 doc-writing/parts/Arithmetic.g
  96. +664 −0 doc-writing/parts/Arithmetic.rb
  97. +21 −0 doc-writing/parts/Arithmetic.tokens
  98. +835 −0 doc-writing/parts/ArithmeticLexer.rb
  99. +602 −0 doc-writing/parts/ArithmeticParser.rb
  100. +58 −0 doc-writing/stylesheets/ANTLR3.css
  101. +109 −0 doc-writing/stylesheets/autumn.css.erb
  102. +97 −0 doc-writing/stylesheets/borland.css.erb
  103. +85 −0 doc-writing/stylesheets/bw.css.erb
  104. +52 −0 doc-writing/stylesheets/code-style.erb
  105. +163 −0 doc-writing/stylesheets/code.css
  106. +112 −0 doc-writing/stylesheets/colorful.css.erb
  107. +112 −0 doc-writing/stylesheets/default.css.erb
  108. +112 −0 doc-writing/stylesheets/emacs.css.erb
  109. +112 −0 doc-writing/stylesheets/friendly.css.erb
  110. +121 −0 doc-writing/stylesheets/fruity.css.erb
  111. +6 −0 doc-writing/stylesheets/general.css
  112. +112 −0 doc-writing/stylesheets/manni.css.erb
  113. +112 −0 doc-writing/stylesheets/murphy.css.erb
  114. +121 −0 doc-writing/stylesheets/native.css.erb
  115. +111 −0 doc-writing/stylesheets/pastie.css.erb
  116. +109 −0 doc-writing/stylesheets/perldoc.css.erb
  117. +146 −0 doc-writing/stylesheets/ruby-blue.css.erb
  118. +101 −0 doc-writing/stylesheets/ruby.css
  119. +121 −0 doc-writing/stylesheets/shell.css
  120. +103 −0 doc-writing/stylesheets/spectaular.css.erb
  121. +110 −0 doc-writing/stylesheets/trac.css.erb
  122. +107 −0 doc-writing/stylized/index.html
  123. +243 −0 doc-writing/stylized/license.txt
  124. +272 −0 doc-writing/stylized/screen.css
  125. 0  doc-writing/tutorial.textile
  126. +26 −0 doc-writing/using.textile
  127. +524 −0 java/RubyTarget.java
  128. BIN  java/antlr-full-3.1.3.jar
  129. BIN  java/antlr-full-3.2.jar
  130. +210 −0 lib/antlr3.rb
  131. +88 −0 lib/antlr3/constants.rb
  132. +689 −0 lib/antlr3/debug.rb
  133. +210 −0 lib/antlr3/debug/event-hub.rb
  134. +25 −0 lib/antlr3/debug/record-event-listener.rb
  135. +55 −0 lib/antlr3/debug/rule-tracer.rb
  136. +312 −0 lib/antlr3/debug/socket.rb
  137. +92 −0 lib/antlr3/debug/trace-event-listener.rb
  138. +247 −0 lib/antlr3/dfa.rb
  139. +174 −0 lib/antlr3/dot.rb
  140. +660 −0 lib/antlr3/error.rb
  141. +521 −0 lib/antlr3/main.rb
  142. +41 −0 lib/antlr3/modes/ast-builder.rb
  143. +56 −0 lib/antlr3/modes/filter.rb
  144. +322 −0 lib/antlr3/profile.rb
  145. +1,236 −0 lib/antlr3/recognizers.rb
  146. +954 −0 lib/antlr3/streams.rb
  147. +91 −0 lib/antlr3/streams/interactive.rb
Sorry, we could not display the entire diff because too many files (3,193) changed.
BIN  ._antlr-3.2
Binary file not shown
4,968 .bzrignore
4,968 additions, 0 deletions not shown
20 .juju.log
@@ -0,0 +1,20 @@
+I, [2009-04-25T21:56:18.900804 #20409] INFO -- : created directory bin
+I, [2009-04-25T21:56:18.903506 #20409] INFO -- : created directory config
+I, [2009-04-25T21:56:18.905911 #20409] INFO -- : created directory lib
+I, [2009-04-25T21:56:18.909046 #20409] INFO -- : created directory lib/antlr3
+I, [2009-04-25T21:56:18.911977 #20409] INFO -- : created directory lib/core-ext
+I, [2009-04-25T21:56:18.981219 #20409] INFO -- : created directory notes
+I, [2009-04-25T21:56:18.985403 #20409] INFO -- : created directory scratch
+I, [2009-04-25T21:56:18.989387 #20409] INFO -- : created directory scripts
+I, [2009-04-25T21:56:19.119579 #20409] INFO -- : created directory spec
+I, [2009-04-25T21:56:19.124989 #20409] INFO -- : created directory test
+I, [2009-04-25T21:56:19.167775 #20409] INFO -- : generated History.txt (history log)
+I, [2009-04-25T21:56:19.184657 #20409] INFO -- : generated bin/antlr3 (command line executable)
+I, [2009-04-25T21:56:19.185747 #20409] INFO -- : generated Rakefile (setup for rake tasks)
+I, [2009-04-25T21:56:19.202832 #20409] INFO -- : generated lib/antlr3.rb (project base library file)
+I, [2009-04-25T21:56:19.204919 #20409] INFO -- : generated README.txt (primary project documentation and liscence info)
+I, [2009-04-25T21:56:19.212054 #20409] INFO -- : generated config/project.yaml (experimental project config collection)
+I, [2009-04-25T21:56:19.213876 #20409] INFO -- : generated config/irb.rb (irb session configuration)
+I, [2009-04-25T21:56:19.302759 #20409] INFO -- : generated komodo project file antlr3.kpf
+I, [2009-04-25T21:56:19.303273 #20409] INFO -- : initializing bazaar repository
+I, [2009-04-25T21:56:28.731375 #20409] INFO -- : project created!
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ruby-antlr3</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.dltk.core.scriptbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.dltk.ruby.core.nature</nature>
+ </natures>
+</projectDescription>
3,236 .quick-backup
@@ -0,0 +1,3236 @@
+["qntest :Delete do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar Delete;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == ''
+end
+
+test :SingleToken do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end
+
+test :SingleTokenToNewNode do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNode;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID["x"];
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'x'
+end
+
+test :SingleTokenToNewNodeRoot do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNodeRoot;
+ options {language=Ruby;output=AST;}
+ a : ID -> ^(ID["x"] INT);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(x INT)'
+end
+
+test :SingleTokenToNewNode2 do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNode2;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID[ ];
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == 'ID'
+end
+
+test :SingleCharLiteral do
+ result = parse(<<-'END', :a, 'c')
+ grammar SingleCharLiteral;
+ options {language=Ruby;output=AST;}
+ a : 'c' -> 'c';
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'c'
+end
+
+test :SingleStringLiteral do
+ result = parse(<<-'END', :a, 'ick')
+ grammar SingleStringLiteral;
+ options {language=Ruby;output=AST;}
+ a : 'ick' -> 'ick';
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'ick'
+end
+
+test :SingleRule do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleRule;
+ options {language=Ruby;output=AST;}
+ a : b -> b;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end
+
+test :ReorderTokens do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar ReorderTokens;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> INT ID;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34 abc'
+end
+
+test :ReorderTokenAndRule do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar ReorderTokenAndRule;
+ options {language=Ruby;output=AST;}
+ a : b INT -> INT b;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34 abc'
+end
+
+test :TokenTree do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar TokenTree;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ^(INT ID);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(34 abc)'
+end
+
+test :TokenTreeAfterOtherStuff do
+ result = parse(<<-'END', :a, 'void abc 34')
+ grammar TokenTreeAfterOtherStuff;
+ options {language=Ruby;output=AST;}
+ a : 'void' ID INT -> 'void' ^(INT ID);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'void (34 abc)'
+end
+
+test :NestedTokenTreeWithOuterLoop do
+ result = parse(<<-'END', :a, 'a 1 b 2')
+ grammar NestedTokenTreeWithOuterLoop;
+ options {language=Ruby;output=AST;}
+ tokens {DUH;}
+ a : ID INT ID INT -> ^( DUH ID ^( DUH INT) )+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(DUH a (DUH 1)) (DUH b (DUH 2))'
+end
+
+test :OptionalSingleToken do
+ result = parse(<<-'END', :a, 'abc')
+ grammar OptionalSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID? ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end
+
+test :ClosureSingleToken do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ClosureSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID ID -> ID* ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :PositiveClosureSingleToken do
+ result = parse(<<-'END', :a, 'a b')
+ grammar PositiveClosureSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID ID -> ID+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :OptionalSingleRule do
+ result = parse(<<-'END', :a, 'abc')
+ grammar OptionalSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b -> b?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end
+
+test :ClosureSingleRule do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ClosureSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b b -> b*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :ClosureOfLabel do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ClosureOfLabel;
+ options {language=Ruby;output=AST;}
+ a : x+=b x+=b -> $x*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :OptionalLabelNoListLabel do
+ result = parse(<<-'END', :a, 'a')
+ grammar OptionalLabelNoListLabel;
+ options {language=Ruby;output=AST;}
+ a : (x=ID)? -> $x?;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a'
+end
+
+test :PositiveClosureSingleRule do
+ result = parse(<<-'END', :a, 'a b')
+ grammar PositiveClosureSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b b -> b+;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :SinglePredicateT do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SinglePredicateT;
+ options {language=Ruby;output=AST;}
+ a : ID -> {true}? ID -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end
+
+test :SinglePredicateF do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SinglePredicateF;
+ options {language=Ruby;output=AST;}
+ a : ID -> {false}? ID -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == ''
+end
+
+test :MultiplePredicate do
+ result = parse(<<-'END', :a, 'a 2')
+ grammar MultiplePredicate;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> {false}? ID
+ -> {true}? INT
+ ->
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '2'
+end
+
+test :MultiplePredicateTrees do
+ result = parse(<<-'END', :a, 'a 2')
+ grammar MultiplePredicateTrees;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> {false}? ^(ID INT)
+ -> {true}? ^(INT ID)
+ -> ID
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(2 a)'
+end
+
+test :SimpleTree do
+ result = parse(<<-'END', :a, '-34')
+ grammar SimpleTree;
+ options {language=Ruby;output=AST;}
+ a : op INT -> ^(op INT);
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(- 34)'
+end
+
+test :SimpleTree2 do
+ result = parse(<<-'END', :a, '+ 34')
+ grammar SimpleTree2;
+ options {language=Ruby;output=AST;}
+ a : op INT -> ^(INT op);
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(34 +)'
+end
+
+test :NestedTrees do
+ result = parse(<<-'END', :a, 'var a:int; b:float;')
+ grammar NestedTrees;
+ options {language=Ruby;output=AST;}
+ a : 'var' (ID ':' type ';')+ -> ^('var' ^(':' ID type)+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(var (: a int) (: b float))'
+end
+
+test :ImaginaryTokenCopy do
+ result = parse(<<-'END', :a, 'a,b,c')
+ grammar ImaginaryTokenCopy;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : ID (',' ID)*-> ^(VAR ID)+ ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(VAR a) (VAR b) (VAR c)'
+end
+
+test :TokenUnreferencedOnLeftButDefined do
+ result = parse(<<-'END', :a, 'a')
+ grammar TokenUnreferencedOnLeftButDefined;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : b -> ID ;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'ID'
+end
+
+test :ImaginaryTokenCopySetText do
+ result = parse(<<-'END', :a, 'a,b,c')
+ grammar ImaginaryTokenCopySetText;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : ID (',' ID)*-> ^(VAR["var"] ID)+ ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(var a) (var b) (var c)'
+end
+
+test :ImaginaryTokenNoCopyFromToken do
+ result = parse(<<-'END', :a, '{a b c}')
+ grammar ImaginaryTokenNoCopyFromToken;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '({ a b c)'
+end
+
+test :ImaginaryTokenNoCopyFromTokenSetText do
+ result = parse(<<-'END', :a, '{a b c}')
+ grammar ImaginaryTokenNoCopyFromTokenSetText;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : lc='{' ID+ '}' -> ^(BLOCK[$lc,"block"] ID+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(block a b c)'
+end
+
+test :MixedRewriteAndAutoAST do
+ result = parse(<<-'END', :a, 'a 1 2')
+ grammar MixedRewriteAndAutoAST;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b^ ; // 2nd b matches only an INT; can make it root
+ b : ID INT -> INT ID
+ | INT
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == '(2 1 a)'
+end
+
+test :SubruleWithRewrite do
+ result = parse(<<-'END', :a, 'a 1 2 3')
+ grammar SubruleWithRewrite;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b ;
+ b : (ID INT -> INT ID | INT INT -> INT+ )
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '1 a 2 3'
+end
+
+test :SubruleWithRewrite2 do
+ result = parse(<<-'END', :a, 'int a; int b=3;')
+ grammar SubruleWithRewrite2;
+ options {language=Ruby;output=AST;}
+ tokens {TYPE;}
+ a : b b ;
+ b : 'int'
+ ( ID -> ^(TYPE 'int' ID)
+ | ID '=' INT -> ^(TYPE 'int' ID INT)
+ )
+ ';'
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(TYPE int a) (TYPE int b 3)'
+end
+
+test :NestedRewriteShutsOffAutoAST do
+ result = parse(<<-'END', :a, 'a b c d; 42')
+ grammar NestedRewriteShutsOffAutoAST;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b ;
+ b : ID ( ID (last=ID -> $last)+ ) ';' // get last ID
+ | INT // should still get auto AST construction
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'd 42'
+end
+
+test :RewriteActions do
+ result = parse(<<-'END', :a, '3')
+ grammar RewriteActions;
+ options {language=Ruby;output=AST;}
+ a : atom -> ^({ @adaptor.create!(INT,"9") } atom) ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(9 3)'
+end
+
+test :RewriteActions2 do
+ result = parse(<<-'END', :a, '3')
+ grammar RewriteActions2;
+ options {language=Ruby;output=AST;}
+ a : atom -> { @adaptor.create!(INT,"9") } atom ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '9 3'
+end
+
+test :RefToOldValue do
+ result = parse(<<-'END', :a, '3+4+5')
+ grammar RefToOldValue;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : (atom -> atom) (op='+' r=atom -> ^($op $a $r) )* ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(+ (+ 3 4) 5)'
+end
+
+test :CopySemanticsForRules do
+ result = parse(<<-'END', :a, '3')
+ grammar CopySemanticsForRules;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : atom -> ^(atom atom) ; // NOT CYCLE! (dup atom)
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(3 3)'
+end
+
+test :CopySemanticsForRules2 do
+ result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar CopySemanticsForRules2;
+ options {language=Ruby;output=AST;}
+ a : type ID (',' ID)* ';' -> ^(type ID)+ ;
+ type : 'int' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a) (int b) (int c)'
+end
+
+test :CopySemanticsForRules3 do
+ result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules3;
+ options {language=Ruby;output=AST;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type modifier? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int public a) (int public b) (int public c)'
+end
+
+test :CopySemanticsForRules3Double do
+ result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules3Double;
+ options {language=Ruby;output=AST;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type modifier? ID)+ ^(type modifier? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int public a) (int public b) (int public c) (int public a) (int public b) (int public c)'
+end
+
+test :CopySemanticsForRules4 do
+ result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules4;
+ options {language=Ruby;output=AST;}
+ tokens {MOD;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type ^(MOD modifier)? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int (MOD public) a) (int (MOD public) b) (int (MOD public) c)'
+end
+
+test :CopySemanticsLists do
+ result = parse(<<-'END', :a, 'a,b,c;')
+ grammar CopySemanticsLists;
+ options {language=Ruby;output=AST;}
+ tokens {MOD;}
+ a : ID (',' ID)* ';' -> ID+ ID+ ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b c a b c'
+end
+
+test :CopyRuleLabel do
+ result = parse(<<-'END', :a, 'a')
+ grammar CopyRuleLabel;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> $x $x;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a a'
+end
+
+test :CopyRuleLabel2 do
+ result = parse(<<-'END', :a, 'a')
+ grammar CopyRuleLabel2;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> ^($x $x);
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(a a)'
+end
+
+test :QueueingOfTokens do
+ result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar QueueingOfTokens;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID (',' ID)* ';' -> ^('int' ID+) ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a b c)'
+end
+
+test :CopyOfTokens do
+ result = parse(<<-'END', :a, 'int a;')
+ grammar CopyOfTokens;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID ';' -> 'int' ID 'int' ID ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'int a int a'
+end
+
+test :TokenCopyInLoop do
+ result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar TokenCopyInLoop;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID (',' ID)* ';' -> ^('int' ID)+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a) (int b) (int c)'
+end
+
+test :TokenCopyInLoopAgainstTwoOthers do
+ result = parse(<<-'END', :a, 'int a:1,b:2,c:3;')
+ grammar TokenCopyInLoopAgainstTwoOthers;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID ':' INT (',' ID ':' INT)* ';' -> ^('int' ID INT)+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a 1) (int b 2) (int c 3)'
+end
+
+test :ListRefdOneAtATime do
+ result = parse(<<-'END', :a, 'a b c')
+ grammar ListRefdOneAtATime;
+ options {language=Ruby;output=AST;}
+ a : ID+ -> ID ID ID ; // works if 3 input IDs
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b c'
+end
+
+test :SplitListWithLabels do
+ result = parse(<<-'END', :a, 'a b c')
+ grammar SplitListWithLabels;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : first=ID others+=ID* -> $first VAR $others+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a VAR b c'
+end
+
+test :ComplicatedMelange do
+ result = parse(<<-'END', :a, 'a a b b b c c c d')
+ grammar ComplicatedMelange;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : A A b=B B b=B c+=C C c+=C D {s=$D.text} -> A+ B+ C+ D ;
+ type : 'int' | 'float' ;
+ A : 'a' ;
+ B : 'b' ;
+ C : 'c' ;
+ D : 'd' ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a a b b b c c c d'
+end
+
+test :RuleLabel do
+ result = parse(<<-'END', :a, 'a')
+ grammar RuleLabel;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> $x;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a'
+end
+
+test :AmbiguousRule do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar AmbiguousRule;
+ options {language=Ruby;output=AST;}
+ a : ID a -> a | INT ;
+ ID : 'a'..'z'+ ;
+ INT: '0'..'9'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34'
+end
+
+test :RuleListLabel do
+ result = parse(<<-'END', :a, 'a b')
+ grammar RuleListLabel;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x+=b x+=b -> $x+;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :RuleListLabel2 do
+ result = parse(<<-'END', :a, 'a b')
+ grammar RuleListLabel2;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x+=b x+=b -> $x $x*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :Optional do
+ result = parse(<<-'END', :a, 'a')
+ grammar Optional;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b (y=b)? -> $x $y?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a'
+end
+
+test :Optional2 do
+ result = parse(<<-'END', :a, 'a b')
+ grammar Optional2;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=ID (y=b)? -> $x $y?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :Optional3 do
+ result = parse(<<-'END', :a, 'a b')
+ grammar Optional3;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=ID (y=b)? -> ($x $y)?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end
+
+test :Optional4 do
+ result = parse(<<-'END', :a, 'a b')
+ grammar Optional4;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x+=ID (y=b)? -> ($x $y)?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == 'a b'
+end
+
+test :Optional5 do
+ result = parse(<<-'END', :a, 'a')
+ grammar Optional5;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : ID -> ID? ; // match an ID to optional ID
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a'
+end
+
+test :ArbitraryExprType do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ArbitraryExprType;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x+=b x+=b -> {ANTLR3::CommonTree.new(nil)};
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == ''
+end
+
+test :Set do
+ result = parse(<<-'END', :a, '2 a 34 de')
+ grammar SetT;
+ options {language=Ruby;output=AST;}
+ a: (INT|ID)+ -> INT+ ID+ ;
+ INT: '0'..'9'+;
+ ID : 'a'..'z'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '2 34 a de'
+end
+
+test :Set2 do
+ result = parse(<<-'END', :a, '2')
+ grammar Set2;
+ options {language=Ruby;output=AST;}
+ a: (INT|ID) -> INT? ID? ;
+ INT: '0'..'9'+;
+ ID : 'a'..'z'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '2'
+end
+
+test :SetWithLabel do
+ warn('test SetWithLabel officially broken')
+ #result = parse(<<-'END', :a, '2')
+ # grammar SetWithLabel;
+ # options {language=Ruby;output=AST;}
+ # a : x=(INT|ID) -> $x ;
+ # INT: '0'..'9'+;
+ # ID : 'a'..'z'+;
+ # WS : (' '|'\n') {$channel=HIDDEN;} ;
+ #
+ #END
+ #result.should == '2'
+end
+
+test :RewriteAction do
+ result = parse(<<-'END', :r, '25')
+ grammar RewriteAction;
+ options {language=Ruby;output=AST;}
+ tokens { FLOAT; }
+ r
+ : INT -> {ANTLR3::CommonTree.new(create_token(FLOAT, nil, "#{$INT.text}.0"))}
+ ;
+ INT : '0'..'9'+;
+ WS: (' ' | '\n' | '\t')+ {$channel = HIDDEN;};
+
+ END
+ result.should == '25.0'
+end
+
+test :OptionalSubruleWithoutRealElements do
+ result = parse(<<-'END', :modulo, 'modulo abc (x y #)')
+ grammar OptionalSubruleWithoutRealElements;
+ options {language=Ruby;output=AST;}
+ tokens {PARMS;}
+
+ modulo
+ : 'modulo' ID ('(' parms+ ')')? -> ^('modulo' ID ^(PARMS parms+)?)
+ ;
+ parms : '#'|ID;
+ ID : ('a'..'z' | 'A'..'Z')+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(modulo abc (PARMS x y #))'
+end
+
+test :Wildcard do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar Wildcard;
+ options {language=Ruby;output=AST;}
+ a : ID c=. -> $c;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34'
+end
+
+test :ExtraTokenInSimpleDecl do
+ result, errors = parse(<<-'END', :decl, 'int 34 x=1;', true)
+ grammar ExtraTokenInSimpleDecl;
+ options {language=Ruby;output=AST;}
+ tokens {EXPR;}
+ decl : type ID '=' INT ';' -> ^(EXPR type ID INT) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:4 extraneous input "34" expecting ID']
+ result.should == '(EXPR int x 1)'
+end
+
+test :MissingIDInSimpleDecl do
+ result, errors = parse(<<-'END', :decl, 'int =1;', true)
+ grammar MissingIDInSimpleDecl;
+ options {language=Ruby;output=AST;}
+ tokens {EXPR;}
+ decl : type ID '=' INT ';' -> ^(EXPR type ID INT) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:4 missing ID at "="']
+ result.should == '(EXPR int <missing ID> 1)'
+end
+
+test :MissingSetInSimpleDecl do
+ result, errors = parse(<<-'END', :decl, 'x=1;', true)
+ grammar MissingSetInSimpleDecl;
+ options {language=Ruby;output=AST;}
+ tokens {EXPR;}
+ decl : type ID '=' INT ';' -> ^(EXPR type ID INT) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:0 mismatched input "x" expecting set nil']
+ result.should == '(EXPR <error: x> x 1)'
+end
+
+test :MissingTokenGivesErrorNode do
+ require 'trace-event'
+ #Tracer.new do |event|
+ # puts(event.to_s + ' : %p' % event.__self__) if event.__self__.class.to_s =~ /CommonToken\b/
+ #end.trace do
+ result, errors = parse(<<-'END', :a, 'abc', true)
+ grammar MissingTokenGivesErrorNode;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ID INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ["line 0:-1 missing INT at \"<EOF>\""]
+ result.should == 'abc <missing INT>'
+ #end
+end
+
+test :ExtraTokenGivesErrorNode do
+ result, errors = parse(<<-'END', :a, 'abc ick 34', true)
+ grammar ExtraTokenGivesErrorNode;
+ options {language=Ruby;output=AST;}
+ a : b c -> b c;
+ b : ID -> ID ;
+ c : INT -> INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:4 extraneous input "ick" expecting INT']
+ result.should == 'abc 34'
+end
+
+test :MissingFirstTokenGivesErrorNode do
+ result, errors = parse(<<-'END', :a, '34', true)
+ grammar MissingFirstTokenGivesErrorNode;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ID INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:0 missing ID at "34"']
+ result.should == '<missing ID> 34'
+end
+
+test :MissingFirstTokenGivesErrorNode2 do
+ result, errors = parse(<<-'END', :a, '34', true)
+ grammar MissingFirstTokenGivesErrorNode2;
+ options {language=Ruby;output=AST;}
+ a : b c -> b c;
+ b : ID -> ID ;
+ c : INT -> INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:0 missing ID at "34"']
+ result.should == '<missing ID> 34'
+end
+
+test :NoViableAltGivesErrorNode do
+ result, errors = parse(<<-'END', :a, '*', true)
+ grammar NoViableAltGivesErrorNode;
+ options {language=Ruby;output=AST;}
+ a : b -> b | c -> c;
+ b : ID -> ID ;
+ c : INT -> INT ;
+ ID : 'a'..'z'+ ;
+ S : '*' ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ errors.should == ['line 1:0 no viable alternative at input "*"']
+ result.should == '<unexpected: 0 S["*"] @ line 1 col 0 (0..0), resync = *>'
+end
+
+test :Cardinality do
+ lambda do
+ parse(<<-'END', :a, "a b 3 4 5")
+ grammar Cardinality;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : ID ID INT INT INT -> (ID INT)+;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ end.should raise_error(ANTLR3::Error::RewriteCardinalityError)
+end
+test :Cardinality2 do
+ lambda do
+ parse(<<-'END', :a, "a b")
+ grammar Cardinality2;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : ID+ -> ID ID ID ; // only 2 input IDs
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ end.should raise_error(ANTLR3::Error::RewriteCardinalityError)
+end
+test :Cardinality3 do
+ lambda do
+ parse(<<-'END', :a, "3")
+ grammar Cardinality3;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : ID? INT -> ID INT ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ end.should raise_error(ANTLR3::Error::RewriteEmptyStream)
+end
+test :LoopCardinality do
+ lambda do
+ parse(<<-'END', :a, "3")
+ grammar LoopCardinality;
+ options {language=Ruby;output=AST;}
+ a : ID? INT -> ID+ INT ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ end.should raise_error(ANTLR3::Error::RewriteEarlyExit)
+end
+
+[XS:
+Block
+: full"�test :Delete do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar Delete;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == ''
+end: name" Delete: body"� result = parse(<<-'END', :a, 'abc 34')
+ grammar Delete;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == '': desc"5deletion by leaving the right side of `->' blank: problem0S;
+;"test :SingleToken do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end;"SingleToken;"� result = parse(<<-'END', :a, 'abc')
+ grammar SingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'; "2mapping a single token to a single token node;
+0S;
+;"test :SingleTokenToNewNode do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNode;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID["x"];
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'x'
+end;"SingleTokenToNewNode;"� result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNode;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID["x"];
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'x'; 0;
+0S;
+;".test :SingleTokenToNewNodeRoot do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNodeRoot;
+ options {language=Ruby;output=AST;}
+ a : ID -> ^(ID["x"] INT);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(x INT)'
+end;"SingleTokenToNewNodeRoot;" result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNodeRoot;
+ options {language=Ruby;output=AST;}
+ a : ID -> ^(ID["x"] INT);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(x INT)'; 0;
+0S;
+;"test :SingleTokenToNewNode2 do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNode2;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID[ ];
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == 'ID'
+end;"SingleTokenToNewNode2;"� result = parse(<<-'END', :a, 'abc')
+ grammar SingleTokenToNewNode2;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID[ ];
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == 'ID'; 0;
+0S;
+;"test :SingleCharLiteral do
+ result = parse(<<-'END', :a, 'c')
+ grammar SingleCharLiteral;
+ options {language=Ruby;output=AST;}
+ a : 'c' -> 'c';
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'c'
+end;"SingleCharLiteral;"� result = parse(<<-'END', :a, 'c')
+ grammar SingleCharLiteral;
+ options {language=Ruby;output=AST;}
+ a : 'c' -> 'c';
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'c'; 0;
+0S;
+;"test :SingleStringLiteral do
+ result = parse(<<-'END', :a, 'ick')
+ grammar SingleStringLiteral;
+ options {language=Ruby;output=AST;}
+ a : 'ick' -> 'ick';
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'ick'
+end;"SingleStringLiteral;"� result = parse(<<-'END', :a, 'ick')
+ grammar SingleStringLiteral;
+ options {language=Ruby;output=AST;}
+ a : 'ick' -> 'ick';
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'ick'; 0;
+0S;
+;" test :SingleRule do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SingleRule;
+ options {language=Ruby;output=AST;}
+ a : b -> b;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end;"SingleRule;"� result = parse(<<-'END', :a, 'abc')
+ grammar SingleRule;
+ options {language=Ruby;output=AST;}
+ a : b -> b;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'; 0;
+0S;
+;"test :ReorderTokens do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar ReorderTokens;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> INT ID;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34 abc'
+end;"ReorderTokens;"� result = parse(<<-'END', :a, 'abc 34')
+ grammar ReorderTokens;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> INT ID;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34 abc'; 0;
+0S;
+;"-test :ReorderTokenAndRule do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar ReorderTokenAndRule;
+ options {language=Ruby;output=AST;}
+ a : b INT -> INT b;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34 abc'
+end;"ReorderTokenAndRule;"  result = parse(<<-'END', :a, 'abc 34')
+ grammar ReorderTokenAndRule;
+ options {language=Ruby;output=AST;}
+ a : b INT -> INT b;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '34 abc'; 0;
+0S;
+;"test :TokenTree do
+ result = parse(<<-'END', :a, 'abc 34')
+ grammar TokenTree;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ^(INT ID);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(34 abc)'
+end;"TokenTree;"� result = parse(<<-'END', :a, 'abc 34')
+ grammar TokenTree;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> ^(INT ID);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(34 abc)'; 0;
+0S;
+;"Itest :TokenTreeAfterOtherStuff do
+ result = parse(<<-'END', :a, 'void abc 34')
+ grammar TokenTreeAfterOtherStuff;
+ options {language=Ruby;output=AST;}
+ a : 'void' ID INT -> 'void' ^(INT ID);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'void (34 abc)'
+end;"TokenTreeAfterOtherStuff;"# result = parse(<<-'END', :a, 'void abc 34')
+ grammar TokenTreeAfterOtherStuff;
+ options {language=Ruby;output=AST;}
+ a : 'void' ID INT -> 'void' ^(INT ID);
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'void (34 abc)'; 0;
+0S;
+;"ztest :NestedTokenTreeWithOuterLoop do
+ result = parse(<<-'END', :a, 'a 1 b 2')
+ grammar NestedTokenTreeWithOuterLoop;
+ options {language=Ruby;output=AST;}
+ tokens {DUH;}
+ a : ID INT ID INT -> ^( DUH ID ^( DUH INT) )+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(DUH a (DUH 1)) (DUH b (DUH 2))'
+end;"!NestedTokenTreeWithOuterLoop;"P result = parse(<<-'END', :a, 'a 1 b 2')
+ grammar NestedTokenTreeWithOuterLoop;
+ options {language=Ruby;output=AST;}
+ tokens {DUH;}
+ a : ID INT ID INT -> ^( DUH ID ^( DUH INT) )+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(DUH a (DUH 1)) (DUH b (DUH 2))'; 0;
+0S;
+;"test :OptionalSingleToken do
+ result = parse(<<-'END', :a, 'abc')
+ grammar OptionalSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID? ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end;"OptionalSingleToken;"� result = parse(<<-'END', :a, 'abc')
+ grammar OptionalSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID -> ID? ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'; 0;
+0S;
+;"test :ClosureSingleToken do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ClosureSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID ID -> ID* ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end;"ClosureSingleToken;"� result = parse(<<-'END', :a, 'a b')
+ grammar ClosureSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID ID -> ID* ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'; 0;
+0S;
+;"'test :PositiveClosureSingleToken do
+ result = parse(<<-'END', :a, 'a b')
+ grammar PositiveClosureSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID ID -> ID+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end;"PositiveClosureSingleToken;"� result = parse(<<-'END', :a, 'a b')
+ grammar PositiveClosureSingleToken;
+ options {language=Ruby;output=AST;}
+ a : ID ID -> ID+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'; 0;
+0S;
+;"test :OptionalSingleRule do
+ result = parse(<<-'END', :a, 'abc')
+ grammar OptionalSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b -> b?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end;"OptionalSingleRule;"� result = parse(<<-'END', :a, 'abc')
+ grammar OptionalSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b -> b?;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'; 0;
+0S;
+;"test :ClosureSingleRule do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ClosureSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b b -> b*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end;"ClosureSingleRule;"� result = parse(<<-'END', :a, 'a b')
+ grammar ClosureSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b b -> b*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'; 0;
+0S;
+;"test :ClosureOfLabel do
+ result = parse(<<-'END', :a, 'a b')
+ grammar ClosureOfLabel;
+ options {language=Ruby;output=AST;}
+ a : x+=b x+=b -> $x*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end;"ClosureOfLabel;" result = parse(<<-'END', :a, 'a b')
+ grammar ClosureOfLabel;
+ options {language=Ruby;output=AST;}
+ a : x+=b x+=b -> $x*;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'; 0;
+0S;
+;" test :OptionalLabelNoListLabel do
+ result = parse(<<-'END', :a, 'a')
+ grammar OptionalLabelNoListLabel;
+ options {language=Ruby;output=AST;}
+ a : (x=ID)? -> $x?;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a'
+end;"OptionalLabelNoListLabel;"� result = parse(<<-'END', :a, 'a')
+ grammar OptionalLabelNoListLabel;
+ options {language=Ruby;output=AST;}
+ a : (x=ID)? -> $x?;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a'; 0;
+0S;
+;".test :PositiveClosureSingleRule do
+ result = parse(<<-'END', :a, 'a b')
+ grammar PositiveClosureSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b b -> b+;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'
+end;"PositiveClosureSingleRule;" result = parse(<<-'END', :a, 'a b')
+ grammar PositiveClosureSingleRule;
+ options {language=Ruby;output=AST;}
+ a : b b -> b+;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b'; 0;
+0S;
+;"test :SinglePredicateT do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SinglePredicateT;
+ options {language=Ruby;output=AST;}
+ a : ID -> {true}? ID -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'
+end;"SinglePredicateT;"� result = parse(<<-'END', :a, 'abc')
+ grammar SinglePredicateT;
+ options {language=Ruby;output=AST;}
+ a : ID -> {true}? ID -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'abc'; 0;
+0S;
+;"test :SinglePredicateF do
+ result = parse(<<-'END', :a, 'abc')
+ grammar SinglePredicateF;
+ options {language=Ruby;output=AST;}
+ a : ID -> {false}? ID -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == ''
+end;"SinglePredicateF;"� result = parse(<<-'END', :a, 'abc')
+ grammar SinglePredicateF;
+ options {language=Ruby;output=AST;}
+ a : ID -> {false}? ID -> ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == ''; 0;
+0S;
+;"Stest :MultiplePredicate do
+ result = parse(<<-'END', :a, 'a 2')
+ grammar MultiplePredicate;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> {false}? ID
+ -> {true}? INT
+ ->
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '2'
+end;"MultiplePredicate;"4 result = parse(<<-'END', :a, 'a 2')
+ grammar MultiplePredicate;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> {false}? ID
+ -> {true}? INT
+ ->
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '2'; 0;
+0S;
+;"ptest :MultiplePredicateTrees do
+ result = parse(<<-'END', :a, 'a 2')
+ grammar MultiplePredicateTrees;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> {false}? ^(ID INT)
+ -> {true}? ^(INT ID)
+ -> ID
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(2 a)'
+end;"MultiplePredicateTrees;"L result = parse(<<-'END', :a, 'a 2')
+ grammar MultiplePredicateTrees;
+ options {language=Ruby;output=AST;}
+ a : ID INT -> {false}? ^(ID INT)
+ -> {true}? ^(INT ID)
+ -> ID
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(2 a)'; 0;
+0S;
+;"#test :SimpleTree do
+ result = parse(<<-'END', :a, '-34')
+ grammar SimpleTree;
+ options {language=Ruby;output=AST;}
+ a : op INT -> ^(op INT);
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(- 34)'
+end;"SimpleTree;"  result = parse(<<-'END', :a, '-34')
+ grammar SimpleTree;
+ options {language=Ruby;output=AST;}
+ a : op INT -> ^(op INT);
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(- 34)'; 0;
+0S;
+;"&test :SimpleTree2 do
+ result = parse(<<-'END', :a, '+ 34')
+ grammar SimpleTree2;
+ options {language=Ruby;output=AST;}
+ a : op INT -> ^(INT op);
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(34 +)'
+end;"SimpleTree2;"  result = parse(<<-'END', :a, '+ 34')
+ grammar SimpleTree2;
+ options {language=Ruby;output=AST;}
+ a : op INT -> ^(INT op);
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(34 +)'; 0;
+0S;
+;"vtest :NestedTrees do
+ result = parse(<<-'END', :a, 'var a:int; b:float;')
+ grammar NestedTrees;
+ options {language=Ruby;output=AST;}
+ a : 'var' (ID ':' type ';')+ -> ^('var' ^(':' ID type)+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(var (: a int) (: b float))'
+end;"NestedTrees;"] result = parse(<<-'END', :a, 'var a:int; b:float;')
+ grammar NestedTrees;
+ options {language=Ruby;output=AST;}
+ a : 'var' (ID ':' type ';')+ -> ^('var' ^(':' ID type)+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(var (: a int) (: b float))'; 0;
+0S;
+;"itest :ImaginaryTokenCopy do
+ result = parse(<<-'END', :a, 'a,b,c')
+ grammar ImaginaryTokenCopy;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : ID (',' ID)*-> ^(VAR ID)+ ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(VAR a) (VAR b) (VAR c)'
+end;"ImaginaryTokenCopy;"I result = parse(<<-'END', :a, 'a,b,c')
+ grammar ImaginaryTokenCopy;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : ID (',' ID)*-> ^(VAR ID)+ ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(VAR a) (VAR b) (VAR c)'; 0;
+0S;
+;"Ltest :TokenUnreferencedOnLeftButDefined do
+ result = parse(<<-'END', :a, 'a')
+ grammar TokenUnreferencedOnLeftButDefined;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : b -> ID ;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'ID'
+end;"&TokenUnreferencedOnLeftButDefined;" result = parse(<<-'END', :a, 'a')
+ grammar TokenUnreferencedOnLeftButDefined;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : b -> ID ;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'ID'; 0;
+0S;
+;"~test :ImaginaryTokenCopySetText do
+ result = parse(<<-'END', :a, 'a,b,c')
+ grammar ImaginaryTokenCopySetText;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : ID (',' ID)*-> ^(VAR["var"] ID)+ ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(var a) (var b) (var c)'
+end;"ImaginaryTokenCopySetText;"W result = parse(<<-'END', :a, 'a,b,c')
+ grammar ImaginaryTokenCopySetText;
+ options {language=Ruby;output=AST;}
+ tokens {VAR;}
+ a : ID (',' ID)*-> ^(VAR["var"] ID)+ ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(var a) (var b) (var c)'; 0;
+0S;
+;"test :ImaginaryTokenNoCopyFromToken do
+ result = parse(<<-'END', :a, '{a b c}')
+ grammar ImaginaryTokenNoCopyFromToken;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '({ a b c)'
+end;""ImaginaryTokenNoCopyFromToken;"T result = parse(<<-'END', :a, '{a b c}')
+ grammar ImaginaryTokenNoCopyFromToken;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '({ a b c)'; 0;
+0S;
+;"�test :ImaginaryTokenNoCopyFromTokenSetText do
+ result = parse(<<-'END', :a, '{a b c}')
+ grammar ImaginaryTokenNoCopyFromTokenSetText;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : lc='{' ID+ '}' -> ^(BLOCK[$lc,"block"] ID+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(block a b c)'
+end;")ImaginaryTokenNoCopyFromTokenSetText;"g result = parse(<<-'END', :a, '{a b c}')
+ grammar ImaginaryTokenNoCopyFromTokenSetText;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : lc='{' ID+ '}' -> ^(BLOCK[$lc,"block"] ID+) ;
+ type : 'int' | 'float' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(block a b c)'; 0;
+0S;
+;"�test :MixedRewriteAndAutoAST do
+ result = parse(<<-'END', :a, 'a 1 2')
+ grammar MixedRewriteAndAutoAST;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b^ ; // 2nd b matches only an INT; can make it root
+ b : ID INT -> INT ID
+ | INT
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == '(2 1 a)'
+end;"MixedRewriteAndAutoAST;"h result = parse(<<-'END', :a, 'a 1 2')
+ grammar MixedRewriteAndAutoAST;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b^ ; // 2nd b matches only an INT; can make it root
+ b : ID INT -> INT ID
+ | INT
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+ END
+ result.should == '(2 1 a)'; 0;
+0S;
+;"`test :SubruleWithRewrite do
+ result = parse(<<-'END', :a, 'a 1 2 3')
+ grammar SubruleWithRewrite;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b ;
+ b : (ID INT -> INT ID | INT INT -> INT+ )
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '1 a 2 3'
+end;"SubruleWithRewrite;"@ result = parse(<<-'END', :a, 'a 1 2 3')
+ grammar SubruleWithRewrite;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b ;
+ b : (ID INT -> INT ID | INT INT -> INT+ )
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '1 a 2 3'; 0;
+0S;
+;"�test :SubruleWithRewrite2 do
+ result = parse(<<-'END', :a, 'int a; int b=3;')
+ grammar SubruleWithRewrite2;
+ options {language=Ruby;output=AST;}
+ tokens {TYPE;}
+ a : b b ;
+ b : 'int'
+ ( ID -> ^(TYPE 'int' ID)
+ | ID '=' INT -> ^(TYPE 'int' ID INT)
+ )
+ ';'
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(TYPE int a) (TYPE int b 3)'
+end;"SubruleWithRewrite2;"� result = parse(<<-'END', :a, 'int a; int b=3;')
+ grammar SubruleWithRewrite2;
+ options {language=Ruby;output=AST;}
+ tokens {TYPE;}
+ a : b b ;
+ b : 'int'
+ ( ID -> ^(TYPE 'int' ID)
+ | ID '=' INT -> ^(TYPE 'int' ID INT)
+ )
+ ';'
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(TYPE int a) (TYPE int b 3)'; 0;
+0S;
+;"�test :NestedRewriteShutsOffAutoAST do
+ result = parse(<<-'END', :a, 'a b c d; 42')
+ grammar NestedRewriteShutsOffAutoAST;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b ;
+ b : ID ( ID (last=ID -> $last)+ ) ';' // get last ID
+ | INT // should still get auto AST construction
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'd 42'
+end;"!NestedRewriteShutsOffAutoAST;"� result = parse(<<-'END', :a, 'a b c d; 42')
+ grammar NestedRewriteShutsOffAutoAST;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : b b ;
+ b : ID ( ID (last=ID -> $last)+ ) ';' // get last ID
+ | INT // should still get auto AST construction
+ ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'd 42'; 0;
+0S;
+;"Atest :RewriteActions do
+ result = parse(<<-'END', :a, '3')
+ grammar RewriteActions;
+ options {language=Ruby;output=AST;}
+ a : atom -> ^({ @adaptor.create!(INT,"9") } atom) ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(9 3)'
+end;"RewriteActions;"% result = parse(<<-'END', :a, '3')
+ grammar RewriteActions;
+ options {language=Ruby;output=AST;}
+ a : atom -> ^({ @adaptor.create!(INT,"9") } atom) ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(9 3)'; 0;
+0S;
+;">test :RewriteActions2 do
+ result = parse(<<-'END', :a, '3')
+ grammar RewriteActions2;
+ options {language=Ruby;output=AST;}
+ a : atom -> { @adaptor.create!(INT,"9") } atom ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '9 3'
+end;"RewriteActions2;"! result = parse(<<-'END', :a, '3')
+ grammar RewriteActions2;
+ options {language=Ruby;output=AST;}
+ a : atom -> { @adaptor.create!(INT,"9") } atom ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '9 3'; 0;
+0S;
+;"btest :RefToOldValue do
+ result = parse(<<-'END', :a, '3+4+5')
+ grammar RefToOldValue;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : (atom -> atom) (op='+' r=atom -> ^($op $a $r) )* ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(+ (+ 3 4) 5)'
+end;"RefToOldValue;"G result = parse(<<-'END', :a, '3+4+5')
+ grammar RefToOldValue;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : (atom -> atom) (op='+' r=atom -> ^($op $a $r) )* ;
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(+ (+ 3 4) 5)'; 0;
+0S;
+;"ctest :CopySemanticsForRules do
+ result = parse(<<-'END', :a, '3')
+ grammar CopySemanticsForRules;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : atom -> ^(atom atom) ; // NOT CYCLE! (dup atom)
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(3 3)'
+end;"CopySemanticsForRules;"@ result = parse(<<-'END', :a, '3')
+ grammar CopySemanticsForRules;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : atom -> ^(atom atom) ; // NOT CYCLE! (dup atom)
+ atom : INT ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(3 3)'; 0;
+0S;
+;"Ptest :CopySemanticsForRules2 do
+ result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar CopySemanticsForRules2;
+ options {language=Ruby;output=AST;}
+ a : type ID (',' ID)* ';' -> ^(type ID)+ ;
+ type : 'int' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a) (int b) (int c)'
+end;"CopySemanticsForRules2;", result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar CopySemanticsForRules2;
+ options {language=Ruby;output=AST;}
+ a : type ID (',' ID)* ';' -> ^(type ID)+ ;
+ type : 'int' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a) (int b) (int c)'; 0;
+0S;
+;"�test :CopySemanticsForRules3 do
+ result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules3;
+ options {language=Ruby;output=AST;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type modifier? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int public a) (int public b) (int public c)'
+end;"CopySemanticsForRules3;"v result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules3;
+ options {language=Ruby;output=AST;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type modifier? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int public a) (int public b) (int public c)'; 0;
+0S;
+;"�test :CopySemanticsForRules3Double do
+ result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules3Double;
+ options {language=Ruby;output=AST;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type modifier? ID)+ ^(type modifier? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int public a) (int public b) (int public c) (int public a) (int public b) (int public c)'
+end;"!CopySemanticsForRules3Double;"� result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules3Double;
+ options {language=Ruby;output=AST;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type modifier? ID)+ ^(type modifier? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int public a) (int public b) (int public c) (int public a) (int public b) (int public c)'; 0;
+0S;
+;"�test :CopySemanticsForRules4 do
+ result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules4;
+ options {language=Ruby;output=AST;}
+ tokens {MOD;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type ^(MOD modifier)? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int (MOD public) a) (int (MOD public) b) (int (MOD public) c)'
+end;"CopySemanticsForRules4;"� result = parse(<<-'END', :a, 'public int a,b,c;')
+ grammar CopySemanticsForRules4;
+ options {language=Ruby;output=AST;}
+ tokens {MOD;}
+ a : modifier? type ID (',' ID)* ';' -> ^(type ^(MOD modifier)? ID)+ ;
+ type : 'int' ;
+ modifier : 'public' ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int (MOD public) a) (int (MOD public) b) (int (MOD public) c)'; 0;
+0S;
+;".test :CopySemanticsLists do
+ result = parse(<<-'END', :a, 'a,b,c;')
+ grammar CopySemanticsLists;
+ options {language=Ruby;output=AST;}
+ tokens {MOD;}
+ a : ID (',' ID)* ';' -> ID+ ID+ ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b c a b c'
+end;"CopySemanticsLists;" result = parse(<<-'END', :a, 'a,b,c;')
+ grammar CopySemanticsLists;
+ options {language=Ruby;output=AST;}
+ tokens {MOD;}
+ a : ID (',' ID)* ';' -> ID+ ID+ ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b c a b c'; 0;
+0S;
+;"test :CopyRuleLabel do
+ result = parse(<<-'END', :a, 'a')
+ grammar CopyRuleLabel;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> $x $x;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a a'
+end;"CopyRuleLabel;"� result = parse(<<-'END', :a, 'a')
+ grammar CopyRuleLabel;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> $x $x;
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a a'; 0;
+0S;
+;"test :CopyRuleLabel2 do
+ result = parse(<<-'END', :a, 'a')
+ grammar CopyRuleLabel2;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> ^($x $x);
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(a a)'
+end;"CopyRuleLabel2;" result = parse(<<-'END', :a, 'a')
+ grammar CopyRuleLabel2;
+ options {language=Ruby;output=AST;}
+ tokens {BLOCK;}
+ a : x=b -> ^($x $x);
+ b : ID ;
+ ID : 'a'..'z'+ ;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(a a)'; 0;
+0S;
+;"Otest :QueueingOfTokens do
+ result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar QueueingOfTokens;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID (',' ID)* ';' -> ^('int' ID+) ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a b c)'
+end;"QueueingOfTokens;"1 result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar QueueingOfTokens;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID (',' ID)* ';' -> ^('int' ID+) ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a b c)'; 0;
+0S;
+;">test :CopyOfTokens do
+ result = parse(<<-'END', :a, 'int a;')
+ grammar CopyOfTokens;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID ';' -> 'int' ID 'int' ID ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'int a int a'
+end;"CopyOfTokens;"$ result = parse(<<-'END', :a, 'int a;')
+ grammar CopyOfTokens;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID ';' -> 'int' ID 'int' ID ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'int a int a'; 0;
+0S;
+;"Ytest :TokenCopyInLoop do
+ result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar TokenCopyInLoop;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID (',' ID)* ';' -> ^('int' ID)+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a) (int b) (int c)'
+end;"TokenCopyInLoop;"< result = parse(<<-'END', :a, 'int a,b,c;')
+ grammar TokenCopyInLoop;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID (',' ID)* ';' -> ^('int' ID)+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a) (int b) (int c)'; 0;
+0S;
+;"�test :TokenCopyInLoopAgainstTwoOthers do
+ result = parse(<<-'END', :a, 'int a:1,b:2,c:3;')
+ grammar TokenCopyInLoopAgainstTwoOthers;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID ':' INT (',' ID ':' INT)* ';' -> ^('int' ID INT)+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a 1) (int b 2) (int c 3)'
+end;"$TokenCopyInLoopAgainstTwoOthers;"l result = parse(<<-'END', :a, 'int a:1,b:2,c:3;')
+ grammar TokenCopyInLoopAgainstTwoOthers;
+ options {language=Ruby;output=AST;}
+ a : 'int' ID ':' INT (',' ID ':' INT)* ';' -> ^('int' ID INT)+ ;
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == '(int a 1) (int b 2) (int c 3)'; 0;
+0S;
+;"Itest :ListRefdOneAtATime do
+ result = parse(<<-'END', :a, 'a b c')
+ grammar ListRefdOneAtATime;
+ options {language=Ruby;output=AST;}
+ a : ID+ -> ID ID ID ; // works if 3 input IDs
+ op : '+'|'-' ;
+ ID : 'a'..'z'+ ;
+ INT : '0'..'9'+;
+ WS : (' '|'\n') {$channel=HIDDEN;} ;
+
+ END
+ result.should == 'a b c'
+end;"ListRefdOneAtATime;") result = parse(<<-'END', :a, 'a b c')