List of usage examples for org.antlr.v4.runtime.tree AbstractParseTreeVisitor visit
@Override
public T visit(ParseTree tree)
The default implementation calls ParseTree#accept on the specified tree.
From source file:org.icesquirrel.interpreter.SquirrelInterpretedFunction.java
License:Open Source License
public SquirrelInterpretedFunction(StatContext functionBody, FuncargsContext functionSignature) { super();/* w w w . j a v a 2s . c o m*/ this.functionBody = Arrays.asList(functionBody); AbstractParseTreeVisitor<YieldContext> visitor = new AbstractParseTreeVisitor<YieldContext>() { @Override public YieldContext visitChildren(RuleNode node) { System.err.println("VISIT CHILDREN: " + node.getText()); // TODO Auto-generated method stub return super.visitChildren(node); } @Override protected boolean shouldVisitNextChild(RuleNode node, YieldContext currentResult) { // TODO Auto-generated method stub boolean shouldVisitNextChild = super.shouldVisitNextChild(node, currentResult); System.err.println("VISIT SHOULD VISIT: " + node.getText() + " = " + shouldVisitNextChild + " / YIELD : " + currentResult); return shouldVisitNextChild; } @Override public YieldContext visit(ParseTree tree) { System.err.println("VISIT: " + tree.getText()); return super.visit(tree); } }; YieldContext yield = visitor.visit(functionBody); // YieldContext yield = functionBody.accept(visitor); if (yield != null) { System.err.println("REMOVEME! GOT YIELD"); } // setGenerator(functionBody.getText().contains("yi)); // TODO // vararg support // TODO // friend variables // Arguments ArglistContext parlist = functionSignature.arglist(); if (parlist != null) { varargs = parlist.VARARGS() != null; if (!varargs) { for (NameContext name : parlist.namelist().name()) { String nameText = name.NAME().getText(); ExpContext exp = name.exp(); Object value = null; if (exp != null) { value = SquirrelExecutionContext.get().getProcessor().evaluate(exp); } arguments.insertLocal(nameText, value); } } } }