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

public GetFirstDescendantWithType ( Antlr types ) : Antlr.Runtime.Tree.CommonTree
types Antlr
Результат Antlr.Runtime.Tree.CommonTree
Пример #1
0
        public LabelElementPair(Grammar g, GrammarAST label, GrammarAST element, int labelOp)
        {
            this.label = label;
            this.element = element;
            // compute general case for label type
            if (element.GetFirstDescendantWithType(tokenTypeForTokens) != null)
            {
                if (labelOp == ANTLRParser.ASSIGN)
                    type = LabelType.TOKEN_LABEL;
                else
                    type = LabelType.TOKEN_LIST_LABEL;
            }
            else if (element.GetFirstDescendantWithType(ANTLRParser.RULE_REF) != null)
            {
                if (labelOp == ANTLRParser.ASSIGN)
                    type = LabelType.RULE_LABEL;
                else
                    type = LabelType.RULE_LIST_LABEL;
            }

            // now reset if lexer and string
            if (g.IsLexer())
            {
                if (element.GetFirstDescendantWithType(ANTLRParser.STRING_LITERAL) != null)
                {
                    if (labelOp == ANTLRParser.ASSIGN)
                        type = LabelType.LEXER_STRING_LABEL;
                }
            }
        }
Пример #2
0
 // TODO: don't include this node!!
 public virtual CommonTree GetFirstDescendantWithType(Antlr.Runtime.BitSet types)
 {
     if (types.Member(Type))
     {
         return(this);
     }
     if (Children == null)
     {
         return(null);
     }
     foreach (object c in Children)
     {
         GrammarAST t = (GrammarAST)c;
         if (types.Member(t.Type))
         {
             return(t);
         }
         CommonTree d = t.GetFirstDescendantWithType(types);
         if (d != null)
         {
             return(d);
         }
     }
     return(null);
 }
Пример #3
0
 // TODO: move to basetree when i settle on how runtime works
 // TODO: don't include this node!!
 // TODO: reuse other method
 public virtual CommonTree GetFirstDescendantWithType(int type)
 {
     if (Type == type)
     {
         return(this);
     }
     if (Children == null)
     {
         return(null);
     }
     foreach (object c in Children)
     {
         GrammarAST t = (GrammarAST)c;
         if (t.Type == type)
         {
             return(t);
         }
         CommonTree d = t.GetFirstDescendantWithType(type);
         if (d != null)
         {
             return(d);
         }
     }
     return(null);
 }