antlr3 1.8.13 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWU2NmVkYjRjNDlkMTNlYmYyMDAzZWI1YTg4NDFhNTJiNzdlZGIwNA==
5
+ data.tar.gz: !binary |-
6
+ MjA1MmE5ZmMyNGNhNjdkNGExMGE5NGY3MjMzMmNiN2E1ZGIyNDU5ZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Y2Q0NWM3ZmEwZmUwY2MwZjhlNzhjYTM0MzBjNzBjMTk4Y2I3Y2Q1YWNjYzBl
10
+ YzlmYThhMjNhZGEwN2JiMmI5MGZlZGE1ZDA5YTkzYmJhOTM0ZTg3N2MyZDM5
11
+ MmMzOWUzZTc1NDYwMDdjYzQyNzYzYjJjNDA4ZmZkOTVlODdjMmU=
12
+ data.tar.gz: !binary |-
13
+ MGM2NDg4M2Q5NDQzN2RlN2JkZDc3OWNjMGQ0ZmFiODg1NmYzNjM0YzE1MjFm
14
+ Y2U1ZWYzYmZhMTBiMzZhZjk3ZTA5YWRjMTllMjc3Mjc2YzE5YjdmYWUwYmQy
15
+ MDQ5MjU2YjFkOWZkMjcxNTc5Nzg1YmEwMGY5ZDQyODE5MTk2MDI=
@@ -1,3 +1,12 @@
1
+ === 1.9.0 / 08-05-13
2
+
3
+ * Minor Enhancements:
4
+ - upgraded bundled ANTLR JAR from v3.2 to v3.5, which was recompiled with Java 6 to avoid Java 7 resolve compatibility issues
5
+ - thoroughly tested and fixed to function with Ruby 1.9.3
6
+
7
+ * Known Issues:
8
+ - Remote socket event debugging in debug mode does not function properly in Ruby 1.9.3 yet
9
+
1
10
  === 1.8.5 / 10-21-10
2
11
 
3
12
  * 1 Bug Fix
@@ -1,170 +1,170 @@
1
1
  bin/antlr4ruby
2
- lib/antlr3/tree.rb
3
- lib/antlr3/template.rb
2
+ lib/antlr3/dot.rb
3
+ lib/antlr3/error.rb
4
4
  lib/antlr3/dfa.rb
5
+ lib/antlr3/debug.rb
6
+ lib/antlr3/main.rb
7
+ lib/antlr3/tree/debug.rb
5
8
  lib/antlr3/tree/wizard.rb
6
9
  lib/antlr3/tree/visitor.rb
7
- lib/antlr3/tree/debug.rb
8
- lib/antlr3/constants.rb
9
- lib/antlr3/version.rb
10
- lib/antlr3/streams.rb
11
- lib/antlr3/dot.rb
12
- lib/antlr3/profile.rb
13
- lib/antlr3/error.rb
14
- lib/antlr3/debug/rule-tracer.rb
15
10
  lib/antlr3/debug/record-event-listener.rb
16
- lib/antlr3/debug/trace-event-listener.rb
11
+ lib/antlr3/debug/rule-tracer.rb
17
12
  lib/antlr3/debug/event-hub.rb
18
13
  lib/antlr3/debug/socket.rb
19
- lib/antlr3/main.rb
20
- lib/antlr3/debug.rb
14
+ lib/antlr3/debug/trace-event-listener.rb
15
+ lib/antlr3/version.rb
16
+ lib/antlr3/streams/interactive.rb
17
+ lib/antlr3/streams/unicode.rb
18
+ lib/antlr3/streams/rewrite.rb
19
+ lib/antlr3/streams.rb
20
+ lib/antlr3/tree.rb
21
+ lib/antlr3/profile.rb
21
22
  lib/antlr3/task.rb
22
- lib/antlr3/template/parameter.rb
23
+ lib/antlr3/template.rb
24
+ lib/antlr3/constants.rb
25
+ lib/antlr3/token.rb
26
+ lib/antlr3/modes/filter.rb
27
+ lib/antlr3/modes/ast-builder.rb
28
+ lib/antlr3/recognizers.rb
23
29
  lib/antlr3/template/group-file-parser.rb
30
+ lib/antlr3/template/parameter.rb
24
31
  lib/antlr3/template/group-file-lexer.rb
25
32
  lib/antlr3/template/group-file.rb
26
- lib/antlr3/streams/rewrite.rb
27
- lib/antlr3/streams/unicode.rb
28
- lib/antlr3/streams/interactive.rb
29
- lib/antlr3/token.rb
30
- lib/antlr3/recognizers.rb
31
- lib/antlr3/modes/ast-builder.rb
32
- lib/antlr3/modes/filter.rb
33
- lib/antlr3/test/call-stack.rb
33
+ lib/antlr3/util.rb
34
34
  lib/antlr3/test/grammar.rb
35
- lib/antlr3/test/functional.rb
36
35
  lib/antlr3/test/core-extensions.rb
37
- lib/antlr3/util.rb
36
+ lib/antlr3/test/call-stack.rb
37
+ lib/antlr3/test/functional.rb
38
38
  lib/antlr3.rb
39
+ test/unit/test-exceptions.rb
40
+ test/unit/test-trees.rb
39
41
  test/unit/test-scope.rb
40
- test/unit/sample-input/teststreams.input2
42
+ test/unit/test-tree-wizard.rb
43
+ test/unit/test-streams.rb
44
+ test/unit/test-recognizers.rb
45
+ test/unit/test-template.rb
41
46
  test/unit/sample-input/file-stream-1
47
+ test/unit/sample-input/teststreams.input2
42
48
  test/unit/sample-input/template-group
43
- test/unit/test-template.rb
44
- test/unit/test-tree-wizard.rb
45
49
  test/unit/test-unicode-stream.rb
46
- test/unit/test-scheme.rb
47
- test/unit/test-trees.rb
48
- test/unit/test-streams.rb
49
50
  test/unit/test-dfa.rb
50
- test/unit/test-recognizers.rb
51
- test/unit/test-exceptions.rb
52
- test/functional/ast-output/auto-ast.rb
53
- test/functional/ast-output/hetero-nodes.rb
54
- test/functional/ast-output/construction.rb
55
- test/functional/ast-output/rewrites.rb
56
- test/functional/ast-output/tree-rewrite.rb
57
- test/functional/token-rewrite/via-parser.rb
58
- test/functional/token-rewrite/basic.rb
59
- test/functional/main/main-scripts.rb
51
+ test/unit/test-scheme.rb
60
52
  test/functional/tree-parser/basic.rb
61
- test/functional/parser/nuances.rb
62
- test/functional/parser/backtracking.rb
63
- test/functional/parser/properties.rb
64
- test/functional/parser/scopes.rb
65
- test/functional/parser/rule-methods.rb
53
+ test/functional/parser/actions.rb
66
54
  test/functional/parser/predicates.rb
67
55
  test/functional/parser/calc.rb
68
56
  test/functional/parser/basic.rb
57
+ test/functional/parser/rule-methods.rb
58
+ test/functional/parser/properties.rb
59
+ test/functional/parser/scopes.rb
60
+ test/functional/parser/nuances.rb
61
+ test/functional/parser/backtracking.rb
69
62
  test/functional/parser/ll-star.rb
70
- test/functional/parser/actions.rb
71
- test/functional/lexer/filter-mode.rb
72
- test/functional/lexer/nuances.rb
73
- test/functional/lexer/properties.rb
74
- test/functional/lexer/basic.rb
75
- test/functional/lexer/syn-pred.rb
76
- test/functional/lexer/xml.rb
77
63
  test/functional/debugging/rule-tracing.rb
78
64
  test/functional/debugging/profile-mode.rb
79
65
  test/functional/debugging/debug-mode.rb
66
+ test/functional/main/main-scripts.rb
67
+ test/functional/lexer/filter-mode.rb
68
+ test/functional/lexer/basic.rb
69
+ test/functional/lexer/properties.rb
70
+ test/functional/lexer/xml.rb
71
+ test/functional/lexer/nuances.rb
72
+ test/functional/lexer/syn-pred.rb
73
+ test/functional/ast-output/construction.rb
74
+ test/functional/ast-output/hetero-nodes.rb
75
+ test/functional/ast-output/tree-rewrite.rb
76
+ test/functional/ast-output/auto-ast.rb
77
+ test/functional/ast-output/rewrites.rb
80
78
  test/functional/delegation/import.rb
79
+ test/functional/token-rewrite/basic.rb
80
+ test/functional/token-rewrite/via-parser.rb
81
81
  test/functional/template-output/template-output.rb
82
- templates/ASTDbg.stg
83
82
  templates/Support.stg
83
+ templates/ASTDbg.stg
84
+ templates/ASTTreeParser.stg
84
85
  templates/ASTParser.stg
85
86
  templates/AST.stg
86
- templates/ASTTreeParser.stg
87
- templates/Dbg.stg
88
87
  templates/ST.stg
88
+ templates/Dbg.stg
89
89
  templates/Ruby.stg
90
90
  samples/CPP.g
91
91
  samples/ANTLRv3Grammar.g
92
92
  samples/JavaScript.g
93
- samples/standard/treeparser/treeparser.rb
94
- samples/standard/treeparser/Lang.g
95
- samples/standard/treeparser/input
96
- samples/standard/treeparser/output
97
- samples/standard/treeparser/LangDumpDecl.g
98
- samples/standard/cminus/python.group
99
- samples/standard/cminus/CMinus.g
100
- samples/standard/cminus/input
101
- samples/standard/cminus/output
102
- samples/standard/cminus/bytecode.group
103
- samples/standard/cminus/java.group
104
- samples/standard/cminus/cminus.rb
105
- samples/standard/calc/Calculator.rb
106
- samples/standard/calc/Calculator.py
107
- samples/standard/calc/Calculator.g
108
- samples/standard/dynamic-scope/input
109
- samples/standard/dynamic-scope/dynamic-scopes.rb
110
- samples/standard/dynamic-scope/output
111
- samples/standard/dynamic-scope/DynamicScopes.g
112
- samples/standard/rakefile
113
93
  samples/standard/java/Java.g
114
- samples/standard/java/input
115
94
  samples/standard/java/output
95
+ samples/standard/java/input
116
96
  samples/standard/java/java.rb
117
- samples/standard/tweak/tweak.rb
118
- samples/standard/tweak/input
119
- samples/standard/tweak/output
120
- samples/standard/tweak/Tweak.g
121
- samples/standard/simplecTreeParser/input
122
- samples/standard/simplecTreeParser/SimpleC.g
123
- samples/standard/simplecTreeParser/output
97
+ samples/standard/xml/xml.rb
98
+ samples/standard/xml/XML.g
99
+ samples/standard/xml/output
100
+ samples/standard/xml/input
101
+ samples/standard/xml/README
102
+ samples/standard/scopes/scopes.rb
103
+ samples/standard/scopes/output
104
+ samples/standard/scopes/input
105
+ samples/standard/scopes/SymbolTable.g
124
106
  samples/standard/simplecTreeParser/SimpleCWalker.g
107
+ samples/standard/simplecTreeParser/output
108
+ samples/standard/simplecTreeParser/input
125
109
  samples/standard/simplecTreeParser/simplec.rb
126
- samples/standard/island-grammar/island.rb
110
+ samples/standard/simplecTreeParser/SimpleC.g
111
+ samples/standard/cminus/cminus.rb
112
+ samples/standard/cminus/python.group
113
+ samples/standard/cminus/output
114
+ samples/standard/cminus/java.group
115
+ samples/standard/cminus/input
116
+ samples/standard/cminus/bytecode.group
117
+ samples/standard/cminus/CMinus.g
118
+ samples/standard/rakefile
119
+ samples/standard/calc/Calculator.g
120
+ samples/standard/calc/Calculator.py
121
+ samples/standard/calc/Calculator.rb
122
+ samples/standard/island-grammar/Javadoc.g
123
+ samples/standard/island-grammar/output
127
124
  samples/standard/island-grammar/input
125
+ samples/standard/island-grammar/island.rb
128
126
  samples/standard/island-grammar/Simple.g
129
- samples/standard/island-grammar/output
130
- samples/standard/island-grammar/Javadoc.g
131
- samples/standard/C/C.g
132
- samples/standard/C/C.tokens
133
- samples/standard/C/input
134
- samples/standard/C/c.rb
135
- samples/standard/C/output
136
- samples/standard/C/C__testrig.st
137
- samples/standard/fuzzy/input
138
- samples/standard/fuzzy/output
127
+ samples/standard/python/output
128
+ samples/standard/python/PythonTokenSource.rb
129
+ samples/standard/python/Python.g
130
+ samples/standard/python/input
131
+ samples/standard/python/python.rb
132
+ samples/standard/treeparser/treeparser.rb
133
+ samples/standard/treeparser/LangDumpDecl.g
134
+ samples/standard/treeparser/output
135
+ samples/standard/treeparser/Lang.g
136
+ samples/standard/treeparser/input
139
137
  samples/standard/fuzzy/fuzzy.py
140
- samples/standard/fuzzy/fuzzy.rb
141
138
  samples/standard/fuzzy/FuzzyJava.g
142
- samples/standard/xml/input
143
- samples/standard/xml/output
144
- samples/standard/xml/README
145
- samples/standard/xml/xml.rb
146
- samples/standard/xml/XML.g
147
- samples/standard/LL-star/input
139
+ samples/standard/fuzzy/output
140
+ samples/standard/fuzzy/input
141
+ samples/standard/fuzzy/fuzzy.rb
142
+ samples/standard/tweak/tweak.rb
143
+ samples/standard/tweak/output
144
+ samples/standard/tweak/Tweak.g
145
+ samples/standard/tweak/input
146
+ samples/standard/C/c.rb
147
+ samples/standard/C/C__testrig.st
148
+ samples/standard/C/C.g
149
+ samples/standard/C/output
150
+ samples/standard/C/input
151
+ samples/standard/C/C.tokens
152
+ samples/standard/dynamic-scope/output
153
+ samples/standard/dynamic-scope/DynamicScopes.g
154
+ samples/standard/dynamic-scope/input
155
+ samples/standard/dynamic-scope/dynamic-scopes.rb
148
156
  samples/standard/LL-star/output
149
- samples/standard/LL-star/LLStar.g
157
+ samples/standard/LL-star/input
150
158
  samples/standard/LL-star/ll-star.rb
159
+ samples/standard/LL-star/LLStar.g
151
160
  samples/standard/hoisted-predicates/hoisted-predicates.rb
152
- samples/standard/hoisted-predicates/input
153
- samples/standard/hoisted-predicates/output
154
161
  samples/standard/hoisted-predicates/HoistedPredicates.g
155
- samples/standard/scopes/SymbolTable.g
156
- samples/standard/scopes/input
157
- samples/standard/scopes/scopes.rb
158
- samples/standard/scopes/output
159
- samples/standard/python/Python.g
160
- samples/standard/python/input
161
- samples/standard/python/PythonTokenSource.rb
162
- samples/standard/python/output
163
- samples/standard/python/python.rb
164
- ANTLR-LICENSE.txt
162
+ samples/standard/hoisted-predicates/output
163
+ samples/standard/hoisted-predicates/input
165
164
  History.txt
165
+ ANTLR-LICENSE.txt
166
166
  DEVELOPER-README.rdoc
167
167
  README.rdoc
168
- java/antlr-full-3.2.1.jar
168
+ java/antlr-full-3.5.jar
169
169
  java/RubyTarget.java
170
170
  rakefile
@@ -97,6 +97,7 @@ ARGV.delete( '--keep-classpath' ) or
97
97
  if ARGV.include?( '--version' )
98
98
 
99
99
  puts( "Ruby Target and Runtime Library Version: #{ ANTLR3::VERSION_STRING }" )
100
+ puts "ANTLR3 Jar Path: #{ jar }"
100
101
  run.call( '-version' )
101
102
 
102
103
  elsif ARGV.include?( '--help' ) or ARGV.include?( '-h' )
@@ -104,6 +105,10 @@ elsif ARGV.include?( '--help' ) or ARGV.include?( '-h' )
104
105
  # the ANTLR tool doesn't follow the --help/-h convention
105
106
  # -- it provides help only if no arguments are specified
106
107
  run.call
108
+
109
+ elsif ARGV.include?( "--jar-path" )
110
+
111
+ puts "ANTLR3 Jar Path: #{ jar }"
107
112
 
108
113
  else
109
114
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- [The "BSD licence"]
2
+ [The "BSD license"]
3
3
  Copyright (c) 2010 Kyle Yetter
4
4
  All rights reserved.
5
5
 
@@ -28,74 +28,77 @@
28
28
 
29
29
  package org.antlr.codegen;
30
30
 
31
- import java.io.IOException;
32
- import java.util.*;
33
-
34
31
  import org.antlr.Tool;
35
- import org.antlr.stringtemplate.*;
36
32
  import org.antlr.tool.Grammar;
33
+ import org.stringtemplate.v4.AttributeRenderer;
34
+ import org.stringtemplate.v4.ST;
35
+ import org.stringtemplate.v4.STGroup;
36
+
37
+ import java.io.IOException;
38
+ import java.util.*;
37
39
 
38
40
  public class RubyTarget extends Target
39
41
  {
40
42
  /** A set of ruby keywords which are used to escape labels and method names
41
43
  * which will cause parse errors in the ruby source
42
44
  */
43
- public static final Set rubyKeywords =
44
- new HashSet() {
45
+ public static final Set<String> rubyKeywords =
46
+ new HashSet<String>() {
45
47
  {
46
- add( "alias" ); add( "END" ); add( "retry" );
47
- add( "and" ); add( "ensure" ); add( "return" );
48
- add( "BEGIN" ); add( "false" ); add( "self" );
49
- add( "begin" ); add( "for" ); add( "super" );
50
- add( "break" ); add( "if" ); add( "then" );
51
- add( "case" ); add( "in" ); add( "true" );
52
- add( "class" ); add( "module" ); add( "undef" );
53
- add( "def" ); add( "next" ); add( "unless" );
54
- add( "defined?" ); add( "nil" ); add( "until" );
55
- add( "do" ); add( "not" ); add( "when" );
56
- add( "else" ); add( "or" ); add( "while" );
57
- add( "elsif" ); add( "redo" ); add( "yield" );
58
- add( "end" ); add( "rescue" );
48
+ add( "alias" ); add( "END" ); add( "retry" );
49
+ add( "and" ); add( "ensure" ); add( "return" );
50
+ add( "BEGIN" ); add( "false" ); add( "self" );
51
+ add( "begin" ); add( "for" ); add( "super" );
52
+ add( "break" ); add( "if" ); add( "then" );
53
+ add( "case" ); add( "in" ); add( "true" );
54
+ add( "class" ); add( "module" ); add( "undef" );
55
+ add( "def" ); add( "next" ); add( "unless" );
56
+ add( "defined?" ); add( "nil" ); add( "until" );
57
+ add( "do" ); add( "not" ); add( "when" );
58
+ add( "else" ); add( "or" ); add( "while" );
59
+ add( "elsif" ); add( "redo" ); add( "yield" );
60
+ add( "end" ); add( "rescue" );
59
61
  }
60
62
  };
61
63
 
62
- public static HashMap sharedActionBlocks = new HashMap();
64
+ public static Map<String, Map<String, Object>> sharedActionBlocks = new HashMap<String, Map<String, Object>>();
63
65
 
64
66
  public class RubyRenderer implements AttributeRenderer
65
67
  {
66
- protected String[] rubyCharValueEscape = new String[256];
67
-
68
- public RubyRenderer() {
69
- for ( int i = 0; i < 16; i++ ) {
70
- rubyCharValueEscape[ i ] = "\\x0" + Integer.toHexString( i );
71
- }
72
- for ( int i = 16; i < 32; i++ ) {
73
- rubyCharValueEscape[ i ] = "\\x" + Integer.toHexString( i );
74
- }
75
- for ( char i = 32; i < 127; i++ ) {
76
- rubyCharValueEscape[ i ] = Character.toString( i );
77
- }
78
- for ( int i = 127; i < 256; i++ ) {
79
- rubyCharValueEscape[ i ] = "\\x" + Integer.toHexString( i );
80
- }
81
-
82
- rubyCharValueEscape['\n'] = "\\n";
83
- rubyCharValueEscape['\r'] = "\\r";
84
- rubyCharValueEscape['\t'] = "\\t";
85
- rubyCharValueEscape['\b'] = "\\b";
86
- rubyCharValueEscape['\f'] = "\\f";
87
- rubyCharValueEscape['\\'] = "\\\\";
88
- rubyCharValueEscape['"'] = "\\\"";
89
- }
90
-
91
- public String toString( Object o ) {
92
- return o.toString();
68
+ protected String[] rubyCharValueEscape = new String[256];
69
+
70
+ public RubyRenderer() {
71
+ for ( int i = 0; i < 16; i++ ) {
72
+ rubyCharValueEscape[ i ] = "\\x0" + Integer.toHexString( i );
73
+ }
74
+ for ( int i = 16; i < 32; i++ ) {
75
+ rubyCharValueEscape[ i ] = "\\x" + Integer.toHexString( i );
76
+ }
77
+ for ( char i = 32; i < 127; i++ ) {
78
+ rubyCharValueEscape[ i ] = Character.toString( i );
79
+ }
80
+ for ( int i = 127; i < 256; i++ ) {
81
+ rubyCharValueEscape[ i ] = "\\x" + Integer.toHexString( i );
82
+ }
83
+
84
+ rubyCharValueEscape['\n'] = "\\n";
85
+ rubyCharValueEscape['\r'] = "\\r";
86
+ rubyCharValueEscape['\t'] = "\\t";
87
+ rubyCharValueEscape['\b'] = "\\b";
88
+ rubyCharValueEscape['\f'] = "\\f";
89
+ rubyCharValueEscape['\\'] = "\\\\";
90
+ rubyCharValueEscape['"'] = "\\\"";
93
91
  }
94
92
 
95
- public String toString( Object o, String formatName ) {
93
+ @Override
94
+ public String toString( Object o, String formatName, Locale locale ) {
95
+ if ( formatName==null ) {
96
+ return o.toString();
97
+ }
98
+
96
99
  String idString = o.toString();
97
100
 
98
- if ( idString.isEmpty() ) return idString;
101
+ if ( idString.length() == 0 ) return idString;
99
102
 
100
103
  if ( formatName.equals( "snakecase" ) ) {
101
104
  return snakecase( idString );
@@ -110,13 +113,15 @@ public class RubyTarget extends Target
110
113
  } else if ( formatName.equals( "lexerRule" ) ) {
111
114
  return lexerRule( idString );
112
115
  } else if ( formatName.equals( "constantPath" ) ) {
113
- return constantPath( idString );
116
+ return constantPath( idString );
114
117
  } else if ( formatName.equals( "rubyString" ) ) {
115
118
  return rubyString( idString );
116
119
  } else if ( formatName.equals( "label" ) ) {
117
120
  return label( idString );
118
121
  } else if ( formatName.equals( "symbol" ) ) {
119
122
  return symbol( idString );
123
+ } else if ( formatName.equals( "tokenLabel" ) ) {
124
+ return tokenLabel( idString );
120
125
  } else {
121
126
  throw new IllegalArgumentException( "Unsupported format name" );
122
127
  }
@@ -146,7 +151,7 @@ public class RubyTarget extends Target
146
151
  char next;
147
152
  char peek;
148
153
 
149
- if ( value.isEmpty() ) return value;
154
+ if ( value.length() == 0 ) return value;
150
155
  if ( l == 1 ) return value.toLowerCase();
151
156
 
152
157
  for ( int i = 0; i < cliff; i++ ) {
@@ -209,31 +214,35 @@ public class RubyTarget extends Target
209
214
  }
210
215
 
211
216
  private String lexerRule( String value ) {
212
- // System.out.print( "lexerRule( \"" + value + "\") => " );
217
+ // System.out.print( "lexerRule( \"" + value + "\") => " );
213
218
  if ( value.equals( "Tokens" ) ) {
214
- // System.out.println( "\"token!\"" );
219
+ // System.out.println( "\"token!\"" );
215
220
  return "token!";
216
221
  } else {
217
- // String result = snakecase( value ) + "!";
218
- // System.out.println( "\"" + result + "\"" );
222
+ // String result = snakecase( value ) + "!";
223
+ // System.out.println( "\"" + result + "\"" );
219
224
  return ( snakecase( value ) + "!" );
220
225
  }
221
226
  }
227
+
228
+ private String tokenLabel( String value ) {
229
+ return value.replaceAll( "^<|>$", "" );
230
+ }
222
231
 
223
232
  private String constantPath( String value ) {
224
233
  return value.replaceAll( "\\.", "::" );
225
234
  }
226
-
235
+
227
236
  private String rubyString( String value ) {
228
- StringBuilder output_buffer = new StringBuilder();
229
- int len = value.length();
230
-
231
- output_buffer.append( '"' );
232
- for ( int i = 0; i < len; i++ ) {
233
- output_buffer.append( rubyCharValueEscape[ value.charAt( i ) ] );
234
- }
235
- output_buffer.append( '"' );
236
- return output_buffer.toString();
237
+ StringBuilder output_buffer = new StringBuilder();
238
+ int len = value.length();
239
+
240
+ output_buffer.append( '"' );
241
+ for ( int i = 0; i < len; i++ ) {
242
+ output_buffer.append( rubyCharValueEscape[ value.charAt( i ) ] );
243
+ }
244
+ output_buffer.append( '"' );
245
+ return output_buffer.toString();
237
246
  }
238
247
 
239
248
  private String camelcase( String value ) {
@@ -243,7 +252,7 @@ public class RubyTarget extends Target
243
252
  char next;
244
253
  boolean at_edge = true;
245
254
 
246
- if ( value.isEmpty() ) return value;
255
+ if ( value.length() == 0 ) return value;
247
256
  if ( cliff == 1 ) return value.toUpperCase();
248
257
 
249
258
  for ( int i = 0; i < cliff; i++ ) {
@@ -290,7 +299,7 @@ public class RubyTarget extends Target
290
299
 
291
300
  private String subcamelcase( String value ) {
292
301
  value = camelcase( value );
293
- if ( value.isEmpty() )
302
+ if ( value.length() == 0 )
294
303
  return value;
295
304
  Character head = Character.toLowerCase( value.charAt( 0 ) );
296
305
  String tail = value.substring( 1 );
@@ -298,11 +307,12 @@ public class RubyTarget extends Target
298
307
  }
299
308
  }
300
309
 
301
- protected void genRecognizerFile(
302
- Tool tool,
303
- CodeGenerator generator,
304
- Grammar grammar,
305
- StringTemplate outputFileST
310
+ @Override
311
+ protected void genRecognizerFile(
312
+ Tool tool,
313
+ CodeGenerator generator,
314
+ Grammar grammar,
315
+ ST outputFileST
306
316
  ) throws IOException
307
317
  {
308
318
  /*
@@ -335,21 +345,22 @@ public class RubyTarget extends Target
335
345
 
336
346
  Kyle Yetter - March 25, 2010
337
347
  */
338
-
348
+
339
349
  if ( grammar.type == Grammar.COMBINED ) {
340
- Map actions = grammar.getActions();
350
+ Map<String, Map<String, Object>> actions = grammar.getActions();
341
351
  if ( actions.containsKey( "all" ) ) {
342
352
  sharedActionBlocks.put( grammar.name, actions.get( "all" ) );
343
353
  }
344
354
  } else if ( grammar.implicitLexer ) {
345
355
  if ( sharedActionBlocks.containsKey( grammar.name ) ) {
346
- Map actions = grammar.getActions();
356
+ Map<String, Map<String, Object>> actions = grammar.getActions();
347
357
  actions.put( "all", sharedActionBlocks.get( grammar.name ) );
348
358
  }
349
359
  }
350
360
 
351
- StringTemplateGroup group = generator.getTemplates();
361
+ STGroup group = generator.getTemplates();
352
362
  RubyRenderer renderer = new RubyRenderer();
363
+
353
364
  try {
354
365
  group.registerRenderer( Class.forName( "java.lang.String" ), renderer );
355
366
  } catch ( ClassNotFoundException e ) {
@@ -362,6 +373,7 @@ public class RubyTarget extends Target
362
373
  generator.write( outputFileST, fileName );
363
374
  }
364
375
 
376
+ @Override
365
377
  public String getTargetCharLiteralFromANTLRCharLiteral(
366
378
  CodeGenerator generator,
367
379
  String literal
@@ -369,7 +381,7 @@ public class RubyTarget extends Target
369
381
  {
370
382
  int code_point = 0;
371
383
  literal = literal.substring( 1, literal.length() - 1 );
372
-
384
+
373
385
  if ( literal.charAt( 0 ) == '\\' ) {
374
386
  switch ( literal.charAt( 1 ) ) {
375
387
  case '\\':
@@ -404,16 +416,18 @@ public class RubyTarget extends Target
404
416
  } else {
405
417
  System.out.println( "2: hey you didn't account for this: \"" + literal + "\"" );
406
418
  }
407
-
419
+
408
420
  return ( "0x" + Integer.toHexString( code_point ) );
409
421
  }
410
422
 
423
+ @Override
411
424
  public int getMaxCharValue( CodeGenerator generator )
412
425
  {
413
426
  // Versions before 1.9 do not support unicode
414
427
  return 0xFF;
415
428
  }
416
429
 
430
+ @Override
417
431
  public String getTokenTypeAsTargetLabel( CodeGenerator generator, int ttype )
418
432
  {
419
433
  String name = generator.grammar.getTokenDisplayName( ttype );
@@ -423,7 +437,8 @@ public class RubyTarget extends Target
423
437
  }
424
438
  return name;
425
439
  }
426
-
440
+
441
+ @Override
427
442
  public boolean isValidActionScope( int grammarType, String scope ) {
428
443
  if ( scope.equals( "all" ) ) {
429
444
  return true;
@@ -437,7 +452,7 @@ public class RubyTarget extends Target
437
452
  if ( scope.equals( "overrides" ) ) {
438
453
  return true;
439
454
  }
440
-
455
+
441
456
  switch ( grammarType ) {
442
457
  case Grammar.LEXER:
443
458
  if ( scope.equals( "lexer" ) ) {
@@ -466,6 +481,7 @@ public class RubyTarget extends Target
466
481
  return false;
467
482
  }
468
483
 
484
+ @Override
469
485
  public String encodeIntAsCharEscape( final int v ) {
470
486
  final int intValue;
471
487
 
@@ -477,135 +493,4 @@ public class RubyTarget extends Target
477
493
 
478
494
  return String.valueOf( intValue );
479
495
  }
480
-
481
- /** Convert from an ANTLR string literal found in a grammar file to
482
- * an equivalent string literal in the target language. For Java, this
483
- * is the translation 'a\n"' -> "a\n\"". Expect single quotes
484
- * around the incoming literal. Just flip the quotes and replace
485
- * double quotes with \"
486
- *
487
- * Note that we have decided to allow poeple to use '\"' without
488
- * penalty, so we must build the target string in a loop as Utils.replae
489
- * cannot handle both \" and " without a lot of messing around.
490
- *
491
- */
492
- public String getTargetStringLiteralFromANTLRStringLiteral(
493
- CodeGenerator generator,
494
- String literal)
495
- {
496
- StringBuilder sb = new StringBuilder();
497
- StringBuffer is = new StringBuffer(literal);
498
- int lastIndex = is.length() - 1;
499
-
500
- // Opening quote
501
- //
502
- sb.append('"');
503
-
504
- for ( int i = 1; i < lastIndex; i++ ) {
505
- if (is.charAt(i) == '\\') {
506
- // Anything escaped is what it is! We assume that
507
- // people know how to escape characters correctly. However
508
- // we catch anything that does not need an escape in Java (which
509
- // is what the default implementation is dealing with and remove
510
- // the escape. The C target does this for instance.
511
- //
512
- switch (is.charAt(i+1)) {
513
- // Pass through any escapes that Java also needs
514
- //
515
- case '"':
516
- case 'n':
517
- case 'r':
518
- case 't':
519
- case 'b':
520
- case 'f':
521
- case '\\':
522
- case 'u': // Assume unnnn
523
- sb.append('\\'); // Pass the escape through
524
- break;
525
- default:
526
- // Remove the escape by virtue of not adding it here
527
- // Thus \' becomes ' and so on
528
- //
529
- break;
530
- }
531
-
532
- // Go past the \ character
533
- //
534
- i++;
535
- } else {
536
-
537
- // in ruby, double quoted strings have interpolation signifiers that
538
- // will cause a syntax error in the output if they are not properly
539
- // escaped
540
-
541
- if ( is.charAt( i ) == '#' && i < lastIndex - 1 ) {
542
- switch ( is.charAt( i + 1 ) ) {
543
- case '{':
544
- case '@':
545
- case '$':
546
- sb.append('\\');
547
- break;
548
- default:
549
- break;
550
- // pass through
551
- }
552
- } else if (is.charAt(i) == '"') {
553
- sb.append('\\');
554
- }
555
-
556
- }
557
- // Add in the next character, which may have been escaped
558
- //
559
- sb.append(is.charAt(i));
560
- }
561
-
562
- // Append closing " and return
563
- //
564
- sb.append('"');
565
-
566
- return sb.toString();
567
- }
568
-
569
-
570
- public String getTargetStringLiteralFromString(String s, boolean quoted) {
571
- if ( s == null ) { return null; }
572
-
573
- StringBuffer buf = new StringBuffer();
574
-
575
- if ( quoted ) { buf.append('"'); }
576
-
577
- for ( int i = 0; i < s.length(); i++ ) {
578
- int c = s.charAt( i );
579
-
580
- if ( c != '\'' && // don't escape single quotes in strings for java
581
- c < targetCharValueEscape.length &&
582
- targetCharValueEscape[c] != null )
583
- {
584
- buf.append(targetCharValueEscape[c]);
585
- }
586
- else if ( c == '#' && i < s.length() - 1 )
587
- {
588
- switch ( s.charAt( i + 1 ) ) {
589
- case '{':
590
- case '@':
591
- case '$':
592
- buf.append( "\\#" );
593
- break;
594
- default:
595
- buf.append( '#' );
596
- break;
597
- }
598
- }
599
- else
600
- {
601
- buf.append((char)c);
602
- }
603
- }
604
- if ( quoted ) {
605
- buf.append('"');
606
- }
607
- return buf.toString();
608
- }
609
-
610
-
611
496
  }