antlr3 1.8.0 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/History.txt +35 -0
  2. data/Manifest.txt +73 -0
  3. data/README.txt +6 -13
  4. data/java/RubyTarget.java +43 -19
  5. data/java/antlr-full-3.2.1.jar +0 -0
  6. data/lib/antlr3/debug.rb +2 -0
  7. data/lib/antlr3/debug/event-hub.rb +55 -55
  8. data/lib/antlr3/debug/record-event-listener.rb +2 -2
  9. data/lib/antlr3/debug/rule-tracer.rb +14 -14
  10. data/lib/antlr3/debug/socket.rb +47 -47
  11. data/lib/antlr3/debug/trace-event-listener.rb +8 -8
  12. data/lib/antlr3/main.rb +29 -9
  13. data/lib/antlr3/modes/ast-builder.rb +7 -7
  14. data/lib/antlr3/modes/filter.rb +19 -17
  15. data/lib/antlr3/profile.rb +34 -6
  16. data/lib/antlr3/recognizers.rb +50 -1
  17. data/lib/antlr3/streams.rb +19 -15
  18. data/lib/antlr3/streams/rewrite.rb +241 -229
  19. data/lib/antlr3/template/group-file-lexer.rb +6 -8
  20. data/lib/antlr3/template/group-file-parser.rb +16 -16
  21. data/lib/antlr3/template/group-file.rb +1 -1
  22. data/lib/antlr3/test/call-stack.rb +13 -13
  23. data/lib/antlr3/test/core-extensions.rb +69 -69
  24. data/lib/antlr3/test/functional.rb +0 -4
  25. data/lib/antlr3/test/grammar.rb +70 -70
  26. data/lib/antlr3/token.rb +41 -17
  27. data/lib/antlr3/tree.rb +11 -14
  28. data/lib/antlr3/tree/debug.rb +53 -53
  29. data/lib/antlr3/tree/visitor.rb +11 -11
  30. data/lib/antlr3/tree/wizard.rb +35 -35
  31. data/lib/antlr3/util.rb +18 -0
  32. data/lib/antlr3/version.rb +1 -1
  33. data/rakefile +1 -0
  34. data/samples/ANTLRv3Grammar.g +3 -3
  35. data/samples/JavaScript.g +702 -0
  36. data/samples/standard/C/C.g +543 -0
  37. data/samples/standard/C/C.tokens +175 -0
  38. data/samples/standard/C/C__testrig.st +0 -0
  39. data/samples/standard/C/c.rb +12 -0
  40. data/samples/standard/C/input +3479 -0
  41. data/samples/standard/C/output +171 -0
  42. data/samples/standard/LL-star/LLStar.g +101 -0
  43. data/samples/standard/LL-star/input +12 -0
  44. data/samples/standard/LL-star/ll-star.rb +12 -0
  45. data/samples/standard/LL-star/output +2 -0
  46. data/samples/standard/calc/Calculator.g +47 -0
  47. data/samples/standard/calc/Calculator.py +16 -0
  48. data/samples/standard/calc/Calculator.rb +28 -0
  49. data/samples/standard/cminus/CMinus.g +141 -0
  50. data/samples/standard/cminus/bytecode.group +80 -0
  51. data/samples/standard/cminus/cminus.rb +16 -0
  52. data/samples/standard/cminus/input +9 -0
  53. data/samples/standard/cminus/java.group +91 -0
  54. data/samples/standard/cminus/output +11 -0
  55. data/samples/standard/cminus/python.group +48 -0
  56. data/samples/standard/dynamic-scope/DynamicScopes.g +50 -0
  57. data/samples/standard/dynamic-scope/dynamic-scopes.rb +12 -0
  58. data/samples/standard/dynamic-scope/input +7 -0
  59. data/samples/standard/dynamic-scope/output +4 -0
  60. data/samples/standard/fuzzy/FuzzyJava.g +89 -0
  61. data/samples/standard/fuzzy/fuzzy.py +11 -0
  62. data/samples/standard/fuzzy/fuzzy.rb +9 -0
  63. data/samples/standard/fuzzy/input +13 -0
  64. data/samples/standard/fuzzy/output +12 -0
  65. data/samples/standard/hoisted-predicates/HoistedPredicates.g +40 -0
  66. data/samples/standard/hoisted-predicates/hoisted-predicates.rb +13 -0
  67. data/samples/standard/hoisted-predicates/input +1 -0
  68. data/samples/standard/hoisted-predicates/output +1 -0
  69. data/samples/standard/island-grammar/Javadoc.g +46 -0
  70. data/samples/standard/island-grammar/Simple.g +104 -0
  71. data/samples/standard/island-grammar/input +11 -0
  72. data/samples/standard/island-grammar/island.rb +12 -0
  73. data/samples/standard/island-grammar/output +16 -0
  74. data/samples/standard/java/Java.g +827 -0
  75. data/samples/standard/java/input +80 -0
  76. data/samples/standard/java/java.rb +13 -0
  77. data/samples/standard/java/output +1 -0
  78. data/samples/standard/python/Python.g +718 -0
  79. data/samples/standard/python/PythonTokenSource.rb +107 -0
  80. data/samples/standard/python/input +210 -0
  81. data/samples/standard/python/output +24 -0
  82. data/samples/standard/python/python.rb +14 -0
  83. data/samples/standard/rakefile +18 -0
  84. data/samples/standard/scopes/SymbolTable.g +66 -0
  85. data/samples/standard/scopes/input +12 -0
  86. data/samples/standard/scopes/output +3 -0
  87. data/samples/standard/scopes/scopes.rb +12 -0
  88. data/samples/standard/simplecTreeParser/SimpleC.g +113 -0
  89. data/samples/standard/simplecTreeParser/SimpleCWalker.g +64 -0
  90. data/samples/standard/simplecTreeParser/input +12 -0
  91. data/samples/standard/simplecTreeParser/output +1 -0
  92. data/samples/standard/simplecTreeParser/simplec.rb +18 -0
  93. data/samples/standard/treeparser/Lang.g +24 -0
  94. data/samples/standard/treeparser/LangDumpDecl.g +17 -0
  95. data/samples/standard/treeparser/input +1 -0
  96. data/samples/standard/treeparser/output +2 -0
  97. data/samples/standard/treeparser/treeparser.rb +18 -0
  98. data/samples/standard/tweak/Tweak.g +68 -0
  99. data/samples/standard/tweak/input +9 -0
  100. data/samples/standard/tweak/output +16 -0
  101. data/samples/standard/tweak/tweak.rb +13 -0
  102. data/samples/standard/xml/README +16 -0
  103. data/samples/standard/xml/XML.g +123 -0
  104. data/samples/standard/xml/input +21 -0
  105. data/samples/standard/xml/output +39 -0
  106. data/samples/standard/xml/xml.rb +9 -0
  107. data/templates/Ruby.stg +4 -4
  108. data/test/functional/ast-output/auto-ast.rb +0 -5
  109. data/test/functional/ast-output/rewrites.rb +4 -4
  110. data/test/unit/test-scope.rb +45 -0
  111. metadata +96 -8
@@ -0,0 +1,21 @@
1
+ <?xml version='1.0'?>
2
+ <!DOCTYPE component [
3
+ <!ELEMENT component (PCDATA|sub)*>
4
+ <!ATTLIST component
5
+ attr CDATA #IMPLIED
6
+ attr2 CDATA #IMPLIED
7
+ >
8
+ <!ELMENT sub EMPTY>
9
+
10
+ ]>
11
+ <component attr="val'ue" attr2='val"ue'>
12
+ <!-- This is a comment -->
13
+ Text
14
+ <![CDATA[huhu]]>
15
+ abcdef
16
+ &amp;
17
+ &lt;
18
+ <?xtal cursor='11'?>
19
+ <sub/>
20
+ <sub></sub>
21
+ </component>
@@ -0,0 +1,39 @@
1
+ XML declaration
2
+ Attr: version = '1.0'
3
+ ROOTELEMENT: component
4
+ INTERNAL DTD: [
5
+ <!ELEMENT component (PCDATA|sub)*>
6
+ <!ATTLIST component
7
+ attr CDATA #IMPLIED
8
+ attr2 CDATA #IMPLIED
9
+ >
10
+ <!ELMENT sub EMPTY>
11
+
12
+ ]
13
+ Start Tag: component
14
+ Attr: attr = "val'ue"
15
+ Attr: attr2 = 'val"ue'
16
+ PCDATA: "
17
+ "
18
+ Comment: "<!-- This is a comment -->"
19
+ PCDATA: "
20
+ Text
21
+ "
22
+ CDATA: "<![CDATA[huhu]]>"
23
+ PCDATA: "
24
+ abcdef
25
+ &amp;
26
+ &lt;
27
+ "
28
+ PI: xtal
29
+ Attr: cursor = '11'
30
+ PCDATA: "
31
+ "
32
+ Empty Element: sub
33
+ PCDATA: "
34
+ "
35
+ Start Tag: sub
36
+ End Tag: sub
37
+ PCDATA: "
38
+ "
39
+ End Tag: component
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+ $:.unshift( File.dirname( __FILE__ ) )
4
+ require 'XML'
5
+
6
+ for file in ARGV
7
+ input = ANTLR3::FileStream.new( file )
8
+ XML::Lexer.new( input ).to_a
9
+ end
@@ -15,7 +15,7 @@ outputFile(LEXER, PARSER, TREE_PARSER, actionScope, actions, docComment, recogni
15
15
  #!/usr/bin/env ruby
16
16
  #
17
17
  # <fileName>
18
- #
18
+ # --
19
19
  # Generated using ANTLR version: <ANTLRVersion>
20
20
  # Ruby runtime library version: <runtimeLibraryVersion()>
21
21
  # Input grammar file: <fileName>
@@ -369,7 +369,7 @@ element() ::= <<
369
369
  execForcedAction(action) ::= "<action>"
370
370
 
371
371
  globalAttributeScopeClass(scope) ::= <<
372
- <if(scope.attributes)>@@<scope.name> = Struct.new( <scope.attributes:{:<it.decl>}; separator=", "> )<\n><endif>
372
+ <if(scope.attributes)>@@<scope.name> = Scope( <scope.attributes:{<it.decl; format="rubyString">}; separator=", "> )<\n><endif>
373
373
  >>
374
374
 
375
375
  globalAttributeScopeStack(scope) ::= <<
@@ -1342,7 +1342,7 @@ filteringNextToken() ::= ""
1342
1342
  filteringActionGate() ::= "@state.backtracking == 1"
1343
1343
 
1344
1344
  /** Match a string literal */
1345
- lexerStringRef(string,label) ::= <<
1345
+ lexerStringRef(string,label,elementIndex) ::= <<
1346
1346
  <if(label)>
1347
1347
  <label; format="label">_start = self.character_index
1348
1348
  match( <string> )
@@ -1459,4 +1459,4 @@ placeAction(scope, name) ::= <<
1459
1459
  <endif>
1460
1460
  >>
1461
1461
 
1462
- runtimeLibraryVersion() ::= "1.8.0"
1462
+ runtimeLibraryVersion() ::= "1.8.2"
@@ -470,8 +470,6 @@ class TestAutoAST < ANTLR3::Test::Functional
470
470
  result.should == '(34 55)'
471
471
  end
472
472
 
473
- # FIXME: no label actually in the grammar
474
-
475
473
  example "hoisting a `~' inverted token-type set to root using `^' (with label)" do
476
474
  result = parse( <<-'END', :a, '34 55' )
477
475
  grammar NotSetRootWithLabel;
@@ -484,8 +482,6 @@ class TestAutoAST < ANTLR3::Test::Functional
484
482
  result.should == '(34 55)'
485
483
  end
486
484
 
487
- # FIXME: no label here either
488
-
489
485
  example "hoisting a `~' inverted token-type set to root using `^' (with list += label)" do
490
486
  result = parse( <<-'END', :a, '34 55' )
491
487
  grammar NotSetRootWithListLabel;
@@ -494,7 +490,6 @@ class TestAutoAST < ANTLR3::Test::Functional
494
490
  ID : 'a'..'z'+ ;
495
491
  INT : '0'..'9'+;
496
492
  WS : (' '|'\n') {$channel=HIDDEN;} ;
497
-
498
493
  END
499
494
  result.should == '(34 55)'
500
495
  end
@@ -619,7 +619,7 @@ class TestASTViaRewriteRules < ANTLR3::Test::Functional
619
619
  result = parse( <<-'END', :a, '3' )
620
620
  grammar RewriteActions;
621
621
  options {language=Ruby;output=AST;}
622
- a : atom -> ^({ @adaptor.create!(INT,"9") } atom) ;
622
+ a : atom -> ^({ @adaptor.create( INT, "9" ) } atom) ;
623
623
  atom : INT ;
624
624
  ID : 'a'..'z'+ ;
625
625
  INT : '0'..'9'+;
@@ -634,11 +634,11 @@ class TestASTViaRewriteRules < ANTLR3::Test::Functional
634
634
  result = parse( <<-'END', :a, '3' )
635
635
  grammar RewriteActions2;
636
636
  options {language=Ruby;output=AST;}
637
- a : atom -> { @adaptor.create!(INT,"9") } atom ;
637
+ a : atom -> { @adaptor.create( INT, "9" ) } atom ;
638
638
  atom : INT ;
639
639
  ID : 'a'..'z'+ ;
640
640
  INT : '0'..'9'+;
641
- WS : (' '|'\n') {$channel=HIDDEN;} ;
641
+ WS : (' '|'\n') { $channel = HIDDEN } ;
642
642
 
643
643
  END
644
644
  result.should == '9 3'
@@ -1087,7 +1087,7 @@ class TestASTViaRewriteRules < ANTLR3::Test::Functional
1087
1087
  options {language=Ruby;output=AST;}
1088
1088
  tokens { FLOAT; }
1089
1089
  r
1090
- : INT -> {ANTLR3::CommonTree.new(create_token(FLOAT, nil, "#{$INT.text}.0"))}
1090
+ : INT -> { ANTLR3::CommonTree.new( create_token( FLOAT, nil, "#{$INT.text}.0" ) ) }
1091
1091
  ;
1092
1092
  INT : '0'..'9'+;
1093
1093
  WS: (' ' | '\n' | '\t')+ {$channel = HIDDEN;};
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+
4
+ require 'antlr3'
5
+ require 'test/unit'
6
+ require 'spec'
7
+
8
+ class TestDFA < Test::Unit::TestCase
9
+ def setup
10
+ @A = ANTLR3::Scope.new( :a, :b )
11
+ @B = ANTLR3::Scope.new( 'count = 3' )
12
+ @C = ANTLR3::Scope.new( 'a', 'b = 0', 'c = {}' )
13
+ end
14
+
15
+ def test_members
16
+ @A.members.map( &:to_s ).should == %w( a b )
17
+ @B.members.map( &:to_s ).should == %w( count )
18
+ @C.members.map( &:to_s ).should == %w( a b c )
19
+ end
20
+
21
+ def test_defaults_without_arguments
22
+ @A.new.to_a.should == [ nil, nil ]
23
+ @B.new.to_a.should == [ 3 ]
24
+ @C.new.to_a.should == [ nil, 0, {} ]
25
+ end
26
+
27
+ def test_C_defaults_with_arguments
28
+ c = @C.new( Object )
29
+ c.a.should == Object
30
+ c.b.should == 0
31
+ c.c.should == {}
32
+ end
33
+
34
+ def test_B_defaults_with_arguments
35
+ b = @B.new( 7000 )
36
+ b.count.should == 7000
37
+ end
38
+
39
+ def test_A_defaults_with_arguments
40
+ a = @A.new( "apple", :orange )
41
+ a.a.should == 'apple'
42
+ a.b.should == :orange
43
+ end
44
+
45
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antlr3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ hash: 51
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 8
9
+ - 2
10
+ version: 1.8.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Kyle Yetter
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-07-04 00:00:00 -04:00
18
+ date: 2010-10-02 00:00:00 -04:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -19,7 +25,7 @@ description: |-
19
25
  ANTLR (ANother Tool for Language Recognition) is a tool that is used to generate
20
26
  code for performing a variety of language recognition tasks: lexing, parsing,
21
27
  abstract syntax tree construction and manipulation, tree structure recognition,
22
- and input translation. The tool operates simillarly to other parser generators,
28
+ and input translation. The tool operates similarly to other parser generators,
23
29
  taking in a grammar specification written in the special ANTLR metalanguage and
24
30
  producing source code that implements the recognition functionality.
25
31
 
@@ -42,11 +48,11 @@ description: |-
42
48
  java code and templates for producing fully featured language recognition
43
49
  in ruby code
44
50
 
45
- * a ruby runtime library that collects classes used throughout the code that
51
+ * a ruby run-time library that collects classes used throughout the code that
46
52
  ANTLR generates
47
53
 
48
54
  * a wrapper script, `antlr4ruby', which executes the ANTLR command line tool
49
- after ensuring the ANTLR jar is java's class path
55
+ after ensuring the ANTLR jar is Java's class path
50
56
  email: kcy5b@yahoo.com
51
57
  executables:
52
58
  - antlr4ruby
@@ -101,6 +107,7 @@ files:
101
107
  - test/unit/test-recognizers.rb
102
108
  - test/unit/test-trees.rb
103
109
  - test/unit/test-exceptions.rb
110
+ - test/unit/test-scope.rb
104
111
  - test/unit/test-scheme.rb
105
112
  - test/unit/test-template.rb
106
113
  - test/functional/delegation/import.rb
@@ -143,6 +150,78 @@ files:
143
150
  - templates/ASTTreeParser.stg
144
151
  - samples/CPP.g
145
152
  - samples/ANTLRv3Grammar.g
153
+ - samples/JavaScript.g
154
+ - samples/standard/island-grammar/island.rb
155
+ - samples/standard/island-grammar/Simple.g
156
+ - samples/standard/island-grammar/Javadoc.g
157
+ - samples/standard/island-grammar/input
158
+ - samples/standard/island-grammar/output
159
+ - samples/standard/tweak/tweak.rb
160
+ - samples/standard/tweak/input
161
+ - samples/standard/tweak/output
162
+ - samples/standard/tweak/Tweak.g
163
+ - samples/standard/scopes/input
164
+ - samples/standard/scopes/output
165
+ - samples/standard/scopes/SymbolTable.g
166
+ - samples/standard/scopes/scopes.rb
167
+ - samples/standard/dynamic-scope/DynamicScopes.g
168
+ - samples/standard/dynamic-scope/dynamic-scopes.rb
169
+ - samples/standard/dynamic-scope/input
170
+ - samples/standard/dynamic-scope/output
171
+ - samples/standard/hoisted-predicates/hoisted-predicates.rb
172
+ - samples/standard/hoisted-predicates/HoistedPredicates.g
173
+ - samples/standard/hoisted-predicates/input
174
+ - samples/standard/hoisted-predicates/output
175
+ - samples/standard/fuzzy/fuzzy.rb
176
+ - samples/standard/fuzzy/input
177
+ - samples/standard/fuzzy/output
178
+ - samples/standard/fuzzy/FuzzyJava.g
179
+ - samples/standard/fuzzy/fuzzy.py
180
+ - samples/standard/treeparser/LangDumpDecl.g
181
+ - samples/standard/treeparser/Lang.g
182
+ - samples/standard/treeparser/treeparser.rb
183
+ - samples/standard/treeparser/input
184
+ - samples/standard/treeparser/output
185
+ - samples/standard/LL-star/LLStar.g
186
+ - samples/standard/LL-star/input
187
+ - samples/standard/LL-star/output
188
+ - samples/standard/LL-star/ll-star.rb
189
+ - samples/standard/java/Java.g
190
+ - samples/standard/java/java.rb
191
+ - samples/standard/java/input
192
+ - samples/standard/java/output
193
+ - samples/standard/rakefile
194
+ - samples/standard/xml/README
195
+ - samples/standard/xml/xml.rb
196
+ - samples/standard/xml/XML.g
197
+ - samples/standard/xml/input
198
+ - samples/standard/xml/output
199
+ - samples/standard/calc/Calculator.g
200
+ - samples/standard/calc/Calculator.py
201
+ - samples/standard/calc/Calculator.rb
202
+ - samples/standard/C/C.g
203
+ - samples/standard/C/c.rb
204
+ - samples/standard/C/C__testrig.st
205
+ - samples/standard/C/input
206
+ - samples/standard/C/output
207
+ - samples/standard/C/C.tokens
208
+ - samples/standard/cminus/bytecode.group
209
+ - samples/standard/cminus/CMinus.g
210
+ - samples/standard/cminus/cminus.rb
211
+ - samples/standard/cminus/input
212
+ - samples/standard/cminus/python.group
213
+ - samples/standard/cminus/output
214
+ - samples/standard/cminus/java.group
215
+ - samples/standard/simplecTreeParser/SimpleC.g
216
+ - samples/standard/simplecTreeParser/SimpleCWalker.g
217
+ - samples/standard/simplecTreeParser/input
218
+ - samples/standard/simplecTreeParser/output
219
+ - samples/standard/simplecTreeParser/simplec.rb
220
+ - samples/standard/python/PythonTokenSource.rb
221
+ - samples/standard/python/python.rb
222
+ - samples/standard/python/Python.g
223
+ - samples/standard/python/input
224
+ - samples/standard/python/output
146
225
  - README.txt
147
226
  - ANTLR-LICENSE.txt
148
227
  - History.txt
@@ -160,21 +239,29 @@ rdoc_options: []
160
239
  require_paths:
161
240
  - lib
162
241
  required_ruby_version: !ruby/object:Gem::Requirement
242
+ none: false
163
243
  requirements:
164
244
  - - ">="
165
245
  - !ruby/object:Gem::Version
246
+ hash: 57
247
+ segments:
248
+ - 1
249
+ - 8
250
+ - 7
166
251
  version: 1.8.7
167
- version:
168
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
+ none: false
169
254
  requirements:
170
255
  - - ">="
171
256
  - !ruby/object:Gem::Version
257
+ hash: 3
258
+ segments:
259
+ - 0
172
260
  version: "0"
173
- version:
174
261
  requirements:
175
262
  - java
176
263
  rubyforge_project: antlr3
177
- rubygems_version: 1.3.5
264
+ rubygems_version: 1.3.7
178
265
  signing_key:
179
266
  specification_version: 3
180
267
  summary: Fully-featured ruby parser generation for ANTLR version 3.
@@ -185,6 +272,7 @@ test_files:
185
272
  - test/unit/test-recognizers.rb
186
273
  - test/unit/test-trees.rb
187
274
  - test/unit/test-exceptions.rb
275
+ - test/unit/test-scope.rb
188
276
  - test/unit/test-scheme.rb
189
277
  - test/unit/test-template.rb
190
278
  - test/functional/delegation/import.rb