[antlr-interest] Why I can't use getHiddenAfter() function to get Blank,Comments of BuildinType
Fan Yang <yhhf_dy at yahoo.com>
yhhf_dy at yahoo.com
Wed Feb 5 15:42:35 PST 2003
Hi guys,
I'm working on analyzing java source code and doing some sort of java
code translation by using antlr java parser. I'm using antlr 2.7.1
and Java 1.3 Recognizer.
First problem:
The problem is how to regenerate source code from AST which antlr
java parser generated. I only know one solution which is to use
TokenStreamHiddenTokenFilter to preserve whitespace and comments,
then walk AST to regenerate sourcecode. Is there another(better) way
to do that?
Second Problem:
Based on antlr document - Token Streams and preserveWhiteSpace
example, I have modified java.g and java.tree.g files in order to use
TokenStreamHiddenTokenFilter.
every thing works well except some rule involved with BuildinType. I
use following example to test. Most statements work well such as
package, import, class and method definition... I do get comment and
whitespace. but I couldn't get hidden token for variable definition
statements(in the example I marked them with --- dosen't work). for
instance:
int b; //comment
I got such result
intb; //comment
for buildintype in the VARIABLE_DEF rule such int, shor, float and
boolean ..., I couldn't get hidden tokens.
strange thing is that it works for method definition which include
variable difinition in the parameter list. For example:
int foo(int i, int j)
for this line I can get blanks both for return type and parameter
type.
So in one work, preserving blank and comment dosen't work only for
buildin type in the VARIABLE_DEF rule.
I have tried several time, even tried on antlr2.7.2, but I can't find
solution.
I don't know I have explained the problem clearly or not. If you
need, I can't send you my test case, java.g and java.tree.g.
thanks a lot.
Test Case:
package org.antlr.tools; // comment packege
// comment before import
import java.swing.*; // comment import
public class Test { //class Test
int b; //comment --- dosen't work
int foo(int i, int j) {
int z = 1; --- dosen't work
float f = 0.001; --- dosen't work
i = z + 1;
String s = (String) "ff"; --- dosen't work
}
public static void main(String[] args) {
String[] a = new String[10]; --- dosen't work
Test obj = new Test();
obj.foo(1,2);
}
}
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list