children;
/// 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.
virtual std::string toStringTree(bool pretty = false) = 0;
virtual std::string toString() = 0;
/// Specialize toStringTree so that it can print out more information
/// based upon the parser.
virtual std::string toStringTree(Parser *parser, bool pretty = false) = 0;
virtual bool operator == (const ParseTree &other) const;
/// The needs a double dispatch method.
// ml: This has been changed to use Any instead of a template parameter, to avoid the need of a virtual template function.
virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) = 0;
/// 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.
virtual std::string getText() = 0;
/**
* Return an {@link Interval} indicating the index in the
* {@link TokenStream} of the first and last token associated with this
* subtree. If this node is a leaf, then the interval represents a single
* token and has interval i..i for token index i.
*
* An interval of i..i-1 indicates an empty interval at position
* i in the input stream, where 0 <= i <= the size of the input
* token stream. Currently, the code base can only have i=0..n-1 but
* in concept one could have an empty interval after EOF.
*
* If source interval is unknown, this returns {@link Interval#INVALID}.
*
* As a weird special case, the source interval for rules matched after
* EOF is unspecified.
*/
virtual misc::Interval getSourceInterval() = 0;
};
// A class to help managing ParseTree instances without the need of a shared_ptr.
class ANTLR4CPP_PUBLIC ParseTreeTracker {
public:
template
T* createInstance(Args&& ... args) {
static_assert(std::is_base_of::value, "Argument must be a parse tree type");
T* result = new T(args...);
_allocated.push_back(result);
return result;
}
void reset() {
for (auto * entry : _allocated)
delete entry;
_allocated.clear();
}
private:
std::vector _allocated;
};
} // namespace tree
} // namespace antlr4