Antlr4.Tool.Ast.GrammarAST.DeleteChild C# (CSharp) Метод

DeleteChild() публичный Метод

public DeleteChild ( Antlr.Runtime.Tree.ITree t ) : bool
t Antlr.Runtime.Tree.ITree
Результат bool
        public virtual bool DeleteChild(ITree t)
        {
            for (int i = 0; i < Children.Count; i++)
            {
                object c = Children[i];
                if (c == t)
                {
                    DeleteChild(t.ChildIndex);
                    return true;
                }
            }
            return false;
        }

Usage Example

        // TODO: this strips the tree properly, but since text()
        // uses the start of stop token index and gets text from that
        // ineffectively ignores this routine.
        public virtual GrammarAST StripLeftRecursion(GrammarAST altAST)
        {
            GrammarAST lrlabel = null;
            GrammarAST first = (GrammarAST)altAST.GetChild(0);
            int leftRecurRuleIndex = 0;
            if (first.Type == ELEMENT_OPTIONS)
            {
                first = (GrammarAST)altAST.GetChild(1);
                leftRecurRuleIndex = 1;
            }

            ITree rref = first.GetChild(1); // if label=rule
            if ((first.Type == RULE_REF && first.Text.Equals(ruleName)) ||
                 (rref != null && rref.Type == RULE_REF && rref.Text.Equals(ruleName)))
            {
                if (first.Type == ASSIGN || first.Type == PLUS_ASSIGN)
                    lrlabel = (GrammarAST)first.GetChild(0);
                // remove rule ref (first child unless options present)
                altAST.DeleteChild(leftRecurRuleIndex);
                // reset index so it prints properly (sets token range of
                // ALT to start to right of left recur rule we deleted)
                GrammarAST newFirstChild = (GrammarAST)altAST.GetChild(leftRecurRuleIndex);
                altAST.TokenStartIndex = newFirstChild.TokenStartIndex;
            }

            return lrlabel;
        }