forked from jasder/antlr
add getChildren() method to Tree.
This commit is contained in:
parent
d505a393ef
commit
00fa2c7617
|
@ -34,6 +34,7 @@ import org.antlr.v4.runtime.misc.Nullable;
|
|||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
import org.antlr.v4.runtime.tree.RuleNode;
|
||||
import org.antlr.v4.runtime.tree.Tree;
|
||||
import org.antlr.v4.runtime.tree.Trees;
|
||||
import org.antlr.v4.runtime.tree.gui.TreeViewer;
|
||||
|
||||
|
@ -59,7 +60,7 @@ import java.util.concurrent.Future;
|
|||
* getting error information.
|
||||
*
|
||||
* These objects are used during parsing and prediction.
|
||||
* For the special case of parsers and tree parsers, we use the subclass
|
||||
* For the special case of parsers, we use the subclass
|
||||
* ParserRuleContext.
|
||||
*
|
||||
* @see ParserRuleContext
|
||||
|
@ -150,6 +151,11 @@ public class RuleContext implements RuleNode {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Tree> getChildren() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ParseTreeVisitor<? extends T> visitor) { return visitor.visitChildren(this); }
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ import org.antlr.v4.runtime.Parser;
|
|||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TerminalNodeImpl implements TerminalNode {
|
||||
public Token symbol;
|
||||
public ParseTree parent;
|
||||
|
@ -63,6 +65,11 @@ public class TerminalNodeImpl implements TerminalNode {
|
|||
@Override
|
||||
public int getChildCount() { return 0; }
|
||||
|
||||
@Override
|
||||
public List<? extends Tree> getChildren() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
|
||||
return visitor.visitTerminal(this);
|
||||
|
|
|
@ -33,6 +33,9 @@ package org.antlr.v4.runtime.tree;
|
|||
import org.antlr.v4.runtime.RuleContext;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/** The basic notion of a tree has a parent, a payload, and a list of children.
|
||||
* It is the most abstract interface for all the trees used by ANTLR.
|
||||
*/
|
||||
|
@ -59,6 +62,9 @@ public interface Tree {
|
|||
*/
|
||||
int getChildCount();
|
||||
|
||||
/** Return ordered list of all children of this node */
|
||||
List<? extends Tree> getChildren();
|
||||
|
||||
/** Print out a whole tree, not just a node, in LISP format
|
||||
* {@code (root child1 .. childN)}. Print just a node if this is a leaf.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue