/** This factory is the correct way to wire together a Groovy parser and lexer. */ public static JavaRecognizer make(JavaLexer lexer) { JavaRecognizer parser = new JavaRecognizer(lexer.plumb()); // TODO: set up a common error-handling control block, to avoid excessive tangle between these guys parser.lexer = lexer; lexer.parser = parser; parser.setASTNodeClass("org.codehaus.groovy.antlr.GroovySourceAST"); return parser; } // Create a scanner that reads from the input stream passed to us...
private void visitJavaLiteralDo(GroovySourceAST t) { // todo - incomplete, as body of do...while... should be executed at least once, which this doesn't provide. swapTwoChildren(t); }
private JavaRecognizer getJavaParser(String input, SourceBuffer sourceBuffer) { UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(new StringReader(input), sourceBuffer); JavaLexer lexer = new JavaLexer(unicodeReader); unicodeReader.setLexer(lexer); JavaRecognizer parser = JavaRecognizer.make(lexer); parser.setSourceBuffer(sourceBuffer); return parser; }
private static void modifyJavaASTintoGroovyAST(String[] tokenNames, AST ast) { // mutate the tree when in Javaland Visitor preJava2groovyConverter = new PreJava2GroovyConverter(tokenNames); AntlrASTProcessor preJava2groovyTraverser = new PreOrderTraversal(preJava2groovyConverter); preJava2groovyTraverser.process(ast); // map the nodes to Groovy types Visitor java2groovyConverter = new Java2GroovyConverter(tokenNames); AntlrASTProcessor java2groovyTraverser = new PreOrderTraversal(java2groovyConverter); java2groovyTraverser.process(ast); }
public JavaRecognizer(ParserSharedInputState state) { super(state,2); tokenNames = _tokenNames; buildTokenTypeASTClassMap(); astFactory = new ASTFactory(getTokenTypeToASTClassMap()); }
public final void finallyClause() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST finallyClause_AST = null; AST tmp188_AST = null; tmp188_AST = astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp188_AST); match(LITERAL_finally); compoundStatement(); astFactory.addASTChild(currentAST, returnAST); finallyClause_AST = (AST)currentAST.root; returnAST = finallyClause_AST; }
public void visitDefault(GroovySourceAST t,int visit) { if (visit == OPENING_VISIT) { if (t.getType() == JavaTokenTypes.LITERAL_do) { visitJavaLiteralDo(t); } else if (t.getType() == JavaTokenTypes.ARRAY_INIT) { visitJavaArrayInit(t); } } }
private static void groovifyFatJavaLikeGroovyAST(AST ast, String[] groovyTokenNames) { Visitor groovifier = new Groovifier(groovyTokenNames); AntlrASTProcessor groovifierTraverser = new PreOrderTraversal(groovifier); groovifierTraverser.process(ast); }
public void setFilename(String f) { super.setFilename(f); lexer.setFilename(f); } private SourceBuffer sourceBuffer;
public static String convert(String filename, String input) throws Exception { return convert(filename, input, false, false); }
private String nodePrinter(String input) throws Exception { return Java2GroovyProcessor.nodePrinter(input); } }
private String mindmap(String input) throws Exception { return Java2GroovyProcessor.mindmap(input); }
private static JavaRecognizer getJavaParser(String input) { JavaRecognizer parser = null; SourceBuffer sourceBuffer = new SourceBuffer(); UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(new StringReader(input), sourceBuffer); JavaLexer lexer = new JavaLexer(unicodeReader); unicodeReader.setLexer(lexer); parser = JavaRecognizer.make(lexer); parser.setSourceBuffer(sourceBuffer); return parser; }
protected JavaRecognizer(TokenBuffer tokenBuf, int k) { super(tokenBuf,k); tokenNames = _tokenNames; buildTokenTypeASTClassMap(); astFactory = new ASTFactory(getTokenTypeToASTClassMap()); }
private String convert(String input) throws Exception { return Java2GroovyProcessor.convert("Java2GroovyTest.java", input); }
protected JavaRecognizer(TokenStream lexer, int k) { super(lexer,k); tokenNames = _tokenNames; buildTokenTypeASTClassMap(); astFactory = new ASTFactory(getTokenTypeToASTClassMap()); }