List of usage examples for org.antlr.v4.runtime.tree AbstractParseTreeVisitor AbstractParseTreeVisitor
AbstractParseTreeVisitor
From source file:com.github.gfx.android.orma.migration.sqliteparser.SQLiteCreateTableStatementCollector.java
License:Apache License
static String combineParseTree(ParseTree node) { return node.accept(new AbstractParseTreeVisitor<StringBuilder>() { final StringBuilder sb = new StringBuilder(); @Override/*w ww . jav a 2s . c o m*/ protected StringBuilder defaultResult() { return sb; } @Override public StringBuilder visitTerminal(TerminalNode node) { if (sb.length() != 0) { sb.append(' '); } sb.append(node.getText()); return sb; } }).toString(); }
From source file:com.github.gfx.android.orma.migration.sqliteparser.SQLiteParserUtils.java
License:Apache License
static void appendTokenList(final SQLiteComponent component, ParseTree node) { node.accept(new AbstractParseTreeVisitor<Void>() { @Override/*from w ww. j a v a2 s. c o m*/ public Void visitTerminal(TerminalNode node) { int type = node.getSymbol().getType(); if (type == Token.EOF) { return null; } if (node.getParent() instanceof SQLiteParser.Any_nameContext) { component.tokens.add(new SQLiteComponent.Name(node.getText())); } else if (isKeyword(type)) { component.tokens.add(new SQLiteComponent.Keyword(node.getText())); } else { component.tokens.add(node.getText()); } return null; } }); }
From source file:org.icesquirrel.interpreter.SquirrelInterpretedFunction.java
License:Open Source License
public SquirrelInterpretedFunction(StatContext functionBody, FuncargsContext functionSignature) { super();/*from w w w.ja v a 2 s. 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); } } } }