Search in sources :

Example 1 with CommonAST

use of antlr.CommonAST 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*/
}
Also used : AST(antlr.collections.AST) CommonAST(antlr.CommonAST) ASTFrame(antlr.debug.misc.ASTFrame) ASTFactory(antlr.ASTFactory) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 2 with CommonAST

use of antlr.CommonAST in project hibernate-orm by hibernate.

the class OrderByFragmentParser method postProcessSortSpecification.

@Override
protected AST postProcessSortSpecification(AST sortSpec) {
    assert SORT_SPEC == sortSpec.getType();
    SortSpecification sortSpecification = (SortSpecification) sortSpec;
    AST sortKey = sortSpecification.getSortKey();
    if (IDENT_LIST == sortKey.getFirstChild().getType()) {
        AST identList = sortKey.getFirstChild();
        AST ident = identList.getFirstChild();
        AST holder = new CommonAST();
        do {
            holder.addChild(createSortSpecification(ident, sortSpecification.getCollation(), sortSpecification.getOrdering()));
            ident = ident.getNextSibling();
        } while (ident != null);
        sortSpec = holder.getFirstChild();
    }
    return sortSpec;
}
Also used : AST(antlr.collections.AST) CommonAST(antlr.CommonAST) CommonAST(antlr.CommonAST)

Example 3 with CommonAST

use of antlr.CommonAST 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*/
}
Also used : AST(antlr.collections.AST) CommonAST(antlr.CommonAST) ASTFrame(antlr.debug.misc.ASTFrame) ASTFactory(antlr.ASTFactory) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

CommonAST (antlr.CommonAST)3 AST (antlr.collections.AST)3 ASTFactory (antlr.ASTFactory)2 ASTFrame (antlr.debug.misc.ASTFrame)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2