/** Create an AST node with the token type and text passed in, but * with the same background information as another supplied Token (e.g. line numbers). * To be used in place of antlr tree construction syntax, * i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken) * * todo - change antlr.ASTFactory to do this instead... */ public AST create(int type, String txt, AST first) { AST t = astFactory.create(type,txt); if ( t != null && first != null) { // first copy details from first token t.initialize(first); // then ensure that type and txt are specific to this new node t.initialize(type,txt); } return t; }
/** Create an AST node with the token type and text passed in, but * with the same background information as another supplied Token (e.g. line numbers) * to be used in place of antlr tree construction syntax, * i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken) * * todo - change antlr.ASTFactory to do this instead... */ public AST create(int type, String txt, Token first, Token last) { AST t = astFactory.create(type,txt); if ( t != null && first != null) { // first copy details from first token t.initialize(first); // then ensure that type and txt are specific to this new node t.initialize(type,txt); } if ((t instanceof GroovySourceAST) && last != null) { GroovySourceAST node = (GroovySourceAST)t; node.setLast(last); // This is a good point to call node.setSnippet(), // but it bulks up the AST too much for production code. } return t; }
/** Create an AST node with the token type and text passed in, but * with the same background information as another supplied Token (e.g. line numbers). * To be used in place of antlr tree construction syntax, * i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken) * * todo - change antlr.ASTFactory to do this instead... */ public AST create(int type, String txt, AST first) { AST t = astFactory.create(type,txt); if ( t != null && first != null) { // first copy details from first token t.initialize(first); // then ensure that type and txt are specific to this new node t.initialize(type,txt); } return t; }
/** Create an AST node with the token type and text passed in, but * with the same background information as another supplied Token (e.g. line numbers) * to be used in place of antlr tree construction syntax, * i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken) * * todo - change antlr.ASTFactory to do this instead... */ public AST create(int type, String txt, Token first, Token last) { AST t = astFactory.create(type,txt); if ( t != null && first != null) { // first copy details from first token t.initialize(first); // then ensure that type and txt are specific to this new node t.initialize(type,txt); } if ((t instanceof GroovySourceAST) && last != null) { GroovySourceAST node = (GroovySourceAST)t; node.setLast(last); // This is a good point to call node.setSnippet(), // but it bulks up the AST too much for production code. } return t; }