use of antlr.debug.misc.ASTFrame in project groovy-core by groovy.
the class Main method doTreeAction.
public static void doTreeAction(String f, AST t, String[] tokenNames) {
if (t == null)
return;
if (showTree) {
CommonAST.setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0, "AST ROOT");
r.setFirstChild(t);
final ASTFrame frame = new ASTFrame("Groovy AST", r);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// hide the Frame
frame.setVisible(false);
frame.dispose();
System.exit(0);
}
});
if (verbose)
System.out.println(t.toStringList());
}
/*if ( xml ) {
((CommonAST)t).setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0,"AST ROOT");
r.setFirstChild(t);
XStream xstream = new XStream();
xstream.alias("ast", CommonAST.class);
try {
xstream.toXML(r,new FileWriter(f + ".xml"));
System.out.println("Written AST to " + f + ".xml");
} catch (Exception e) {
System.out.println("couldn't write to " + f + ".xml");
e.printStackTrace();
}
//if (verbose) System.out.println(t.toStringList());
}*/
/*@todo
GroovyTreeParser tparse = new GroovyTreeParser();
try {
tparse.compilationUnit(t);
if (verbose) System.out.println("successful walk of result AST for "+f);
}
catch (RecognitionException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
@todo*/
}
use of antlr.debug.misc.ASTFrame in project groovy by apache.
the class Main method doTreeAction.
public static void doTreeAction(String f, AST t, String[] tokenNames) {
if (t == null)
return;
if (showTree) {
CommonAST.setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0, "AST ROOT");
r.setFirstChild(t);
final ASTFrame frame = new ASTFrame("Groovy AST", r);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// hide the Frame
frame.setVisible(false);
frame.dispose();
System.exit(0);
}
});
if (verbose)
System.out.println(t.toStringList());
}
/*if ( xml ) {
((CommonAST)t).setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0,"AST ROOT");
r.setFirstChild(t);
XStream xstream = new XStream();
xstream.alias("ast", CommonAST.class);
try {
xstream.toXML(r,new FileWriter(f + ".xml"));
System.out.println("Written AST to " + f + ".xml");
} catch (Exception e) {
System.out.println("couldn't write to " + f + ".xml");
e.printStackTrace();
}
//if (verbose) System.out.println(t.toStringList());
}*/
/*@todo
GroovyTreeParser tparse = new GroovyTreeParser();
try {
tparse.compilationUnit(t);
if (verbose) System.out.println("successful walk of result AST for "+f);
}
catch (RecognitionException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
@todo*/
}
use of antlr.debug.misc.ASTFrame in project geode by apache.
the class UtilParser method main.
/**
* Parse a query string. Gets the string from stdin unless cmd line has a string in it that
* doesn't start with "-", in which case it parses that string instead. A cmd line arg that starts
* with "-f" causes out put to be put into a GUI tree widget thingy; otherwise, the output is a
* LISP-like string to stdout
*/
public static void main(String[] args) throws Exception {
boolean useFrame = false;
Reader reader = new InputStreamReader(System.in);
if (args.length > 0 && args[0].startsWith("-f"))
useFrame = true;
for (int i = 0; i < args.length; i++) {
if (!args[i].startsWith("-")) {
reader = new StringReader(args[i]);
System.out.println("Parsing: \"" + args[i] + "\"");
break;
}
}
OQLLexer lexer = new OQLLexer(reader);
OQLParser parser = new OQLParser(lexer);
// by default use Unsupported AST class, overridden for supported
// operators in the grammer proper
parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
parser.queryProgram();
AST t = parser.getAST();
if (useFrame) {
ASTFrame frame = new ASTFrame("OQL Example", t);
frame.setVisible(true);
} else {
if (t == null) {
System.out.println("AST is NULL");
} else {
System.out.println(t.toStringTree());
}
}
}
Aggregations