Search in sources :

Example 1 with TerminalNodeImpl

use of org.antlr.v4.runtime.tree.TerminalNodeImpl in project antlr4 by antlr.

the class ParserRuleContext method addChild.

/** Add a child to this node based upon matchedToken. It
	 *  creates a TerminalNodeImpl rather than using
	 *  {@link Parser#createTerminalNode(ParserRuleContext, Token)}. I'm leaving this
     *  in for compatibility but the parser doesn't use this anymore.
	 */
@Deprecated
public TerminalNode addChild(Token matchedToken) {
    TerminalNodeImpl t = new TerminalNodeImpl(matchedToken);
    addAnyChild(t);
    t.setParent(this);
    return t;
}
Also used : TerminalNodeImpl(org.antlr.v4.runtime.tree.TerminalNodeImpl)

Example 2 with TerminalNodeImpl

use of org.antlr.v4.runtime.tree.TerminalNodeImpl in project antlr4 by antlr.

the class Trees method stripChildrenOutOfRange.

/** Replace any subtree siblings of root that are completely to left
	 *  or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...")
	 *  node. The source interval for t is not altered to suit smaller range!
	 *
	 *  WARNING: destructive to t.
	 *
	 *  @since 4.5.1
	 */
public static void stripChildrenOutOfRange(ParserRuleContext t, ParserRuleContext root, int startIndex, int stopIndex) {
    if (t == null)
        return;
    for (int i = 0; i < t.getChildCount(); i++) {
        ParseTree child = t.getChild(i);
        Interval range = child.getSourceInterval();
        if (child instanceof ParserRuleContext && (range.b < startIndex || range.a > stopIndex)) {
            if (isAncestorOf(child, root)) {
                // replace only if subtree doesn't have displayed root
                CommonToken abbrev = new CommonToken(Token.INVALID_TYPE, "...");
                t.children.set(i, new TerminalNodeImpl(abbrev));
            }
        }
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) CommonToken(org.antlr.v4.runtime.CommonToken) Interval(org.antlr.v4.runtime.misc.Interval)

Aggregations

CommonToken (org.antlr.v4.runtime.CommonToken)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 Interval (org.antlr.v4.runtime.misc.Interval)1 TerminalNodeImpl (org.antlr.v4.runtime.tree.TerminalNodeImpl)1