[antlr-interest] Patch for exception constructors

Brian Smith brian-l-smith at uiowa.edu
Tue Oct 15 18:08:49 PDT 2002


Hi,

The runtime library (antlr.jar) of ANTLR 2.7.2 alphas is not compatible 
with parsers and lexers generated with earlier versions (2.7.1 and 
before). The reason is that many of the exceptions' constructors were 
changed to include a "column" parameter. As a result, whenever a 
2.7.1-based lexer/parser tries to throw an exception, it will receive a 
java.lang.NoSuchMethodError while attempting to invoke a 
now-non-existant constructor. This affects _all_ lexers (and maybe 
parsers too) that are generated with 2.7.1 or earlier, since the calls 
to these constructors get automatically generated.

One way to avoid the work around the problem is simply to re-generate 
the classes with ANTLR 2.7.2. However, this workaround isn't sufficient 
when the ANTLR 2.7.2 runtime is to be used in an enviroment that must 
support ANTLR-based tools that don't have source code available. My 
particular interest in this is to make sure that ANTLR 2.7.2 can be 
integrated into the NetBeans IDE's API with minimal problems.

This patch simply adds back the old constructors and marks them 
@deprecated, refering users via the JavaDoc to use the new constructors. 
I believe that it is a very low-risk patch and hopefully it can be 
incorporated into the next release.

I will send in similar patches that apply to the contents of antlr.jar 
if I find them.

Thanks,
Brian

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

-------------- next part --------------
diff -u --recursive antlr-2.7.2a3-orig/antlr/NoViableAltForCharException.java antlr-2.7.2a3/antlr/NoViableAltForCharException.java
--- antlr-2.7.2a3-orig/antlr/NoViableAltForCharException.java	Sat Dec 22 20:16:14 2001
+++ antlr-2.7.2a3/antlr/NoViableAltForCharException.java	Mon Oct 14 17:53:17 2002
@@ -16,6 +16,11 @@
         foundChar = c;
     }
 
+    /** @deprecated As of ANTLR 2.7.2 use {@see #NoViableAltForCharException(char, String, int, int) } */
+    public NoViableAltForCharException(char c, String fileName, int line) {
+        this(c, fileName, line, -1);
+    }
+    
     public NoViableAltForCharException(char c, String fileName, int line, int column) {
         super("NoViableAlt", fileName, line, column);
         foundChar = c;
diff -u --recursive antlr-2.7.2a3-orig/antlr/RecognitionException.java antlr-2.7.2a3/antlr/RecognitionException.java
--- antlr-2.7.2a3-orig/antlr/RecognitionException.java	Sat Dec 22 20:16:14 2001
+++ antlr-2.7.2a3/antlr/RecognitionException.java	Mon Oct 14 17:52:09 2002
@@ -30,6 +30,11 @@
         column = -1;
     }
 
+    /** @deprecated As of ANTLR 2.7.2 use {@see #RecognitionException(String, String, int, int) } */
+    public RecognitionException(String s, String fileName_, int line_) {
+        this(s, fileName_, line_, -1);
+    }
+    
     /**
      * RecognitionException constructor comment.
      * @param s java.lang.String
diff -u --recursive antlr-2.7.2a3-orig/antlr/SemanticException.java antlr-2.7.2a3/antlr/SemanticException.java
--- antlr-2.7.2a3-orig/antlr/SemanticException.java	Sat Sep 14 22:21:38 2002
+++ antlr-2.7.2a3/antlr/SemanticException.java	Mon Oct 14 17:51:38 2002
@@ -10,13 +10,15 @@
 public class SemanticException extends RecognitionException {
     public SemanticException(String s) {
         super(s);
+        
     }
 
-	public SemanticException(String s, String fileName, int line) {
-        this(s, fileName, line, 0);
+    /** @deprecated As of ANTLR 2.7.2 use {@see #SemanticException(String, String, int, int) } */
+    public SemanticException(String s, String fileName, int line) {
+        this(s, fileName, line, -1);
     }
 
-	public SemanticException(String s, String fileName, int line, int column) {
+    public SemanticException(String s, String fileName, int line, int column) {
         super(s, fileName, line, column);
     }
 }


More information about the antlr-interest mailing list