Top Description Methods
org.antlr.v4.runtime.tree

public Interface ParseTree

extends SyntaxTree
Known Direct Subinterfaces
org.antlr.v4.runtime.tree.RuleNode, org.antlr.v4.runtime.tree.TerminalNode
Imports
org.antlr.v4.runtime.Parser, .RuleContext, .Token

An interface to access the tree of RuleContext objects created during a parse that makes the data structure look like a simple parse tree. This node represents both internal nodes, rule invocations, and leaf nodes, token matches.

The payload is either a Token or a RuleContext object.

Method Summary

Modifier and TypeMethod and Description
public <T> T
accept(ParseTreeVisitor<? extends T> visitor)

The ParseTreeVisitor needs a double dispatch method.

public ParseTree
getChild(int i)

Redeclares org.antlr.v4.runtime.tree.Tree.getChild.

If there are children, get the ith value indexed from 0.
public ParseTree
getParent()

Redeclares org.antlr.v4.runtime.tree.Tree.getParent.

The parent of this node.
public String
getText()

Return the combined text of all leaf nodes.

public void
setParent(RuleContext parent)

Set the parent for this node.

public String
toStringTree(Parser parser)

Specialize toStringTree so that it can print out more information based upon the parser.

Inherited from org.antlr.v4.runtime.tree.SyntaxTree:
getSourceInterval

Method Detail

acceptback to summary
public <T> T accept(ParseTreeVisitor<? extends T> visitor)

The ParseTreeVisitor needs a double dispatch method.

getChildback to summary
public ParseTree getChild(int i)

Redeclares org.antlr.v4.runtime.tree.Tree.getChild.

Doc from org.antlr.v4.runtime.tree.Tree.getChild.

If there are children, get the ith value indexed from 0.

Annotations
@Override
getParentback to summary
public ParseTree getParent()

Redeclares org.antlr.v4.runtime.tree.Tree.getParent.

Doc from org.antlr.v4.runtime.tree.Tree.getParent.

The parent of this node. If the return value is null, then this node is the root of the tree.

Annotations
@Override
getTextback to summary
public String getText()

Return the combined text of all leaf nodes. Does not get any off-channel tokens (if any) so won't return whitespace and comments if they are sent to parser on hidden channel.

setParentback to summary
public void setParent(RuleContext parent)

Set the parent for this node. This is not backward compatible as it changes the interface but no one was able to create custom nodes anyway so I'm adding as it improves internal code quality. One could argue for a restructuring of the class/interface hierarchy so that setParent, addChild are moved up to Tree but that's a major change. So I'll do the minimal change, which is to add this method.

Since
4.7
toStringTreeback to summary
public String toStringTree(Parser parser)

Specialize toStringTree so that it can print out more information based upon the parser.