/** Is {@code t} {@code (expr <expr>)} subtree? */ protected RuleTagToken getRuleTagToken(ParseTree t) { if ( t instanceof RuleNode ) { RuleNode r = (RuleNode)t; if ( r.getChildCount()==1 && r.getChild(0) instanceof TerminalNode ) { TerminalNode c = (TerminalNode)r.getChild(0); if ( c.getSymbol() instanceof RuleTagToken ) { // System.out.println("rule tag subtree "+t.toStringTree(parser)); return (RuleTagToken)c.getSymbol(); } } } return null; }
/** * {@inheritDoc} * * <p>The default implementation initializes the aggregate result to * {@link #defaultResult defaultResult()}. Before visiting each child, it * calls {@link #shouldVisitNextChild shouldVisitNextChild}; if the result * is {@code false} no more children are visited and the current aggregate * result is returned. After visiting a child, the aggregate result is * updated by calling {@link #aggregateResult aggregateResult} with the * previous aggregate result and the result of visiting the child.</p> * * <p>The default implementation is not safe for use in visitors that modify * the tree structure. Visitors that modify the tree should override this * method to behave properly in respect to the specific algorithm in use.</p> */ @Override public T visitChildren(RuleNode node) { T result = defaultResult(); int n = node.getChildCount(); for (int i=0; i<n; i++) { if (!shouldVisitNextChild(node, result)) { break; } ParseTree c = node.getChild(i); T childResult = c.accept(this); result = aggregateResult(result, childResult); } return result; }
public void walk(ParseTreeListener listener, ParseTree t) { if ( t instanceof ErrorNode) { listener.visitErrorNode((ErrorNode)t); return; } else if ( t instanceof TerminalNode) { listener.visitTerminal((TerminalNode)t); return; } RuleNode r = (RuleNode)t; enterRule(listener, r); int n = r.getChildCount(); for (int i = 0; i<n; i++) { walk(listener, r.getChild(i)); } exitRule(listener, r); }
private static void parseTreeWalker(ParseTree node, Consumer<RuleNode> f) { RuleNode rule = checkNode(node, RuleNode.class); if (rule == null) { return; } f.accept(rule); for (int i = 0; i < rule.getChildCount(); i++) { parseTreeWalker(rule.getChild(i), f); } }
/** Is {@code t} {@code (expr <expr>)} subtree? */ protected RuleTagToken getRuleTagToken(ParseTree t) { if ( t instanceof RuleNode ) { RuleNode r = (RuleNode)t; if ( r.getChildCount()==1 && r.getChild(0) instanceof TerminalNode ) { TerminalNode c = (TerminalNode)r.getChild(0); if ( c.getSymbol() instanceof RuleTagToken ) { // System.out.println("rule tag subtree "+t.toStringTree(parser)); return (RuleTagToken)c.getSymbol(); } } } return null; }
/** Is {@code t} {@code (expr <expr>)} subtree? */ protected RuleTagToken getRuleTagToken(ParseTree t) { if ( t instanceof RuleNode ) { RuleNode r = (RuleNode)t; if ( r.getChildCount()==1 && r.getChild(0) instanceof TerminalNode ) { TerminalNode c = (TerminalNode)r.getChild(0); if ( c.getSymbol() instanceof RuleTagToken ) { // System.out.println("rule tag subtree "+t.toStringTree(parser)); return (RuleTagToken)c.getSymbol(); } } } return null; }
/** Is {@code t} {@code (expr <expr>)} subtree? */ protected RuleTagToken getRuleTagToken(ParseTree t) { if ( t instanceof RuleNode ) { RuleNode r = (RuleNode)t; if ( r.getChildCount()==1 && r.getChild(0) instanceof TerminalNode ) { TerminalNode c = (TerminalNode)r.getChild(0); if ( c.getSymbol() instanceof RuleTagToken ) { // System.out.println("rule tag subtree "+t.toStringTree(parser)); return (RuleTagToken)c.getSymbol(); } } } return null; }
/** Is {@code t} {@code (expr <expr>)} subtree? */ protected RuleTagToken getRuleTagToken(ParseTree t) { if ( t instanceof RuleNode ) { RuleNode r = (RuleNode)t; if ( r.getChildCount()==1 && r.getChild(0) instanceof TerminalNode ) { TerminalNode c = (TerminalNode)r.getChild(0); if ( c.getSymbol() instanceof RuleTagToken ) { // System.out.println("rule tag subtree "+t.toStringTree(parser)); return (RuleTagToken)c.getSymbol(); } } } return null; }
/** * ANTLR2 construct ruleName: TOKEN TOKEN | rule TOKEN | rule ... */ private JPNode.Builder createNode(RuleNode ctx) { if (ctx.getChildCount() == 0) return null; JPNode.Builder firstNode = visit(ctx.getChild(0)); JPNode.Builder lastNode = firstNode == null ? null : firstNode.getLast(); for (int zz = 1; zz < ctx.getChildCount(); zz++) { JPNode.Builder xx = visit(ctx.getChild(zz)); if (lastNode != null) { lastNode = lastNode.setRight(xx).getLast(); } else if (xx != null) { firstNode = xx; lastNode = firstNode.getLast(); } } return firstNode; }
/** * ANTLR2 construct ruleName: TOKEN TOKEN | rule TOKEN | rule ... */ private JPNode.Builder createNode(RuleNode ctx) { if (ctx.getChildCount() == 0) return null; JPNode.Builder firstNode = visit(ctx.getChild(0)); JPNode.Builder lastNode = firstNode == null ? null : firstNode.getLast(); for (int zz = 1; zz < ctx.getChildCount(); zz++) { JPNode.Builder xx = visit(ctx.getChild(zz)); if (lastNode != null) { lastNode = lastNode.setRight(xx).getLast(); } else if (xx != null) { firstNode = xx; lastNode = firstNode.getLast(); } } return firstNode; }
public void walk(ParseTreeListener listener, ParseTree t) { if ( t instanceof ErrorNode) { listener.visitErrorNode((ErrorNode)t); return; } else if ( t instanceof TerminalNode) { listener.visitTerminal((TerminalNode)t); return; } RuleNode r = (RuleNode)t; enterRule(listener, r); int n = r.getChildCount(); for (int i = 0; i<n; i++) { walk(listener, r.getChild(i)); } exitRule(listener, r); }
public void walk(ParseTreeListener listener, ParseTree t) { if ( t instanceof ErrorNode) { listener.visitErrorNode((ErrorNode)t); return; } else if ( t instanceof TerminalNode) { listener.visitTerminal((TerminalNode)t); return; } RuleNode r = (RuleNode)t; enterRule(listener, r); int n = r.getChildCount(); for (int i = 0; i<n; i++) { walk(listener, r.getChild(i)); } exitRule(listener, r); }
public void walk(ParseTreeListener listener, ParseTree t) { if ( t instanceof ErrorNode) { listener.visitErrorNode((ErrorNode)t); return; } else if ( t instanceof TerminalNode) { listener.visitTerminal((TerminalNode)t); return; } RuleNode r = (RuleNode)t; enterRule(listener, r); int n = r.getChildCount(); for (int i = 0; i<n; i++) { walk(listener, r.getChild(i)); } exitRule(listener, r); }
/** * {@inheritDoc} * * <p>The default implementation initializes the aggregate result to * {@link #defaultResult defaultResult()}. Before visiting each child, it * calls {@link #shouldVisitNextChild shouldVisitNextChild}; if the result * is {@code false} no more children are visited and the current aggregate * result is returned. After visiting a child, the aggregate result is * updated by calling {@link #aggregateResult aggregateResult} with the * previous aggregate result and the result of visiting the child.</p> * * <p>The default implementation is not safe for use in visitors that modify * the tree structure. Visitors that modify the tree should override this * method to behave properly in respect to the specific algorithm in use.</p> */ @Override public T visitChildren(RuleNode node) { T result = defaultResult(); int n = node.getChildCount(); for (int i=0; i<n; i++) { if (!shouldVisitNextChild(node, result)) { break; } ParseTree c = node.getChild(i); T childResult = c.accept(this); result = aggregateResult(result, childResult); } return result; }
/** * {@inheritDoc} * * <p>The default implementation initializes the aggregate result to * {@link #defaultResult defaultResult()}. Before visiting each child, it * calls {@link #shouldVisitNextChild shouldVisitNextChild}; if the result * is {@code false} no more children are visited and the current aggregate * result is returned. After visiting a child, the aggregate result is * updated by calling {@link #aggregateResult aggregateResult} with the * previous aggregate result and the result of visiting the child.</p> * * <p>The default implementation is not safe for use in visitors that modify * the tree structure. Visitors that modify the tree should override this * method to behave properly in respect to the specific algorithm in use.</p> */ @Override public T visitChildren(RuleNode node) { T result = defaultResult(); int n = node.getChildCount(); for (int i=0; i<n; i++) { if (!shouldVisitNextChild(node, result)) { break; } ParseTree c = node.getChild(i); T childResult = c.accept(this); result = aggregateResult(result, childResult); } return result; }
/** * ANTLR2 construct ruleName: TOKEN^ (TOKEN | rule).... */ private JPNode.Builder createTreeFromFirstNode(RuleNode ctx) { if (ctx.getChildCount() == 0) return null; JPNode.Builder node = visit(ctx.getChild(0)); // Can be null, as some rules can be empty (as of today, will perhpas be fixed one day) JPNode.Builder firstChild = node.getDown(); JPNode.Builder lastChild = firstChild == null ? null : firstChild.getLast(); for (int zz = 1; zz < ctx.getChildCount(); zz++) { JPNode.Builder xx = visit(ctx.getChild(zz)); if (lastChild != null) { lastChild = lastChild.setRight(xx).getLast(); } else if (xx != null) { firstChild = xx; lastChild = firstChild.getLast(); } } node.setDown(firstChild); node.setRuleNode(ctx); return node; }
/** * ANTLR2 construct ruleName: TOKEN^ (TOKEN | rule).... */ private JPNode.Builder createTreeFromFirstNode(RuleNode ctx) { if (ctx.getChildCount() == 0) return null; JPNode.Builder node = visit(ctx.getChild(0)); // Can be null, as some rules can be empty (as of today, will perhpas be fixed one day) JPNode.Builder firstChild = node.getDown(); JPNode.Builder lastChild = firstChild == null ? null : firstChild.getLast(); for (int zz = 1; zz < ctx.getChildCount(); zz++) { JPNode.Builder xx = visit(ctx.getChild(zz)); if (lastChild != null) { lastChild = lastChild.setRight(xx).getLast(); } else if (xx != null) { firstChild = xx; lastChild = firstChild.getLast(); } } node.setDown(firstChild); node.setRuleNode(ctx); return node; }
/** * {@inheritDoc} * * <p>The default implementation initializes the aggregate result to * {@link #defaultResult defaultResult()}. Before visiting each child, it * calls {@link #shouldVisitNextChild shouldVisitNextChild}; if the result * is {@code false} no more children are visited and the current aggregate * result is returned. After visiting a child, the aggregate result is * updated by calling {@link #aggregateResult aggregateResult} with the * previous aggregate result and the result of visiting the child.</p> * * <p>The default implementation is not safe for use in visitors that modify * the tree structure. Visitors that modify the tree should override this * method to behave properly in respect to the specific algorithm in use.</p> */ @Override public Result visitChildren(@NotNull RuleNode node) { Result result = defaultResult(); int n = node.getChildCount(); for (int i=0; i<n; i++) { if (!shouldVisitNextChild(node, result)) { break; } ParseTree c = node.getChild(i); Result childResult = c.accept(this); result = aggregateResult(result, childResult); } return result; }
/** * ANTLR2 construct ruleName: exp OR^ exp ... */ private JPNode.Builder createTreeFromSecondNode(RuleNode ctx) { assert ctx.getChildCount() >= 3; JPNode.Builder node = visit(ctx.getChild(1)); if (node == null) return null; JPNode.Builder left = visit(ctx.getChild(0)); JPNode.Builder right = visit(ctx.getChild(2)); node.setDown(left); left.getLast().setRight(right); JPNode.Builder lastNode = node.getLast(); for (int zz = 3; zz < ctx.getChildCount(); zz++) { lastNode = lastNode.setRight(visit(ctx.getChild(zz))).getLast(); } node.setRuleNode(ctx); return node; }
/** * ANTLR2 construct ruleName: exp OR^ exp ... */ private JPNode.Builder createTreeFromSecondNode(RuleNode ctx) { assert ctx.getChildCount() >= 3; JPNode.Builder node = visit(ctx.getChild(1)); if (node == null) return null; JPNode.Builder left = visit(ctx.getChild(0)); JPNode.Builder right = visit(ctx.getChild(2)); node.setDown(left); left.getLast().setRight(right); JPNode.Builder lastNode = node.getLast(); for (int zz = 3; zz < ctx.getChildCount(); zz++) { lastNode = lastNode.setRight(visit(ctx.getChild(zz))).getLast(); } node.setRuleNode(ctx); return node; }