当前位置: 首页>>代码示例>>C#>>正文


C# IParseTree.GetChild方法代码示例

本文整理汇总了C#中IParseTree.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# IParseTree.GetChild方法的具体用法?C# IParseTree.GetChild怎么用?C# IParseTree.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IParseTree的用法示例。


在下文中一共展示了IParseTree.GetChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Descendants

 public static IList<IParseTree> Descendants(IParseTree t)
 {
     List<IParseTree> nodes = new List<IParseTree>();
     nodes.Add(t);
     int n = t.ChildCount;
     for (int i = 0; i < n; i++)
     {
         nodes.AddRange(Descendants(t.GetChild(i)));
     }
     return nodes;
 }
开发者ID:antlr,项目名称:antlr4,代码行数:11,代码来源:Trees.cs

示例2: Same

        /// <summary>
        /// Проверяет два синтаксических дерева на сходство, игнорируя вертикальные "цепочки" и скобки.
        /// </summary>
        public static bool Same(this IParseTree tree1, IParseTree tree2)
        {
            tree1 = tree1.Collapse();
            tree2 = tree2.Collapse();

            if (tree1.ChildCount == 0 || tree2.ChildCount == 0) return tree1.GetText() == tree2.GetText();
            if (tree1.ChildCount != tree2.ChildCount) return false;

            for (int i = 0; i < tree1.ChildCount; i++)
            {
                if (!tree1.GetChild(i).Same(tree2.GetChild(i))) return false;
            }
            return true;
        }
开发者ID:sandwwraith,项目名称:mathlogic,代码行数:17,代码来源:TreeUtils.cs

示例3: GetFirstTerminalNode

 // --- Get tokens in terminal nodes ---
 public static ITerminalNode GetFirstTerminalNode(IParseTree node)
 {
     while (!(node is ITerminalNode))
     {
         if (node.ChildCount == 0)
         {
             return null;
         }
         else
         {
             node = node.GetChild(0);
         }
     }
     return (ITerminalNode)node;
 }
开发者ID:osmedile,项目名称:TypeCobol,代码行数:16,代码来源:ParseTreeUtils.cs

示例4: _findAllNodes

 private static void _findAllNodes(IParseTree t, int index, bool findTokens, IList<IParseTree> nodes)
 {
     // check this node (the root) first
     if (findTokens && t is ITerminalNode)
     {
         ITerminalNode tnode = (ITerminalNode)t;
         if (tnode.Symbol.Type == index)
         {
             nodes.Add(t);
         }
     }
     else
     {
         if (!findTokens && t is ParserRuleContext)
         {
             ParserRuleContext ctx = (ParserRuleContext)t;
             if (ctx.RuleIndex == index)
             {
                 nodes.Add(t);
             }
         }
     }
     // check children
     for (int i = 0; i < t.ChildCount; i++)
     {
         _findAllNodes(t.GetChild(i), index, findTokens, nodes);
     }
 }
开发者ID:antlr,项目名称:antlr4,代码行数:28,代码来源:Trees.cs

示例5: MatchImpl

        protected internal virtual IParseTree MatchImpl(IParseTree tree, IParseTree patternTree, MultiMap<string, IParseTree> labels)
        {
            if (tree == null)
            {
                throw new ArgumentException("tree cannot be null");
            }
            if (patternTree == null)
            {
                throw new ArgumentException("patternTree cannot be null");
            }
            // x and <ID>, x and y, or x and x; or could be mismatched types
            if (tree is ITerminalNode && patternTree is ITerminalNode)
            {
                ITerminalNode t1 = (ITerminalNode)tree;
                ITerminalNode t2 = (ITerminalNode)patternTree;
                IParseTree mismatchedNode = null;
                // both are tokens and they have same type
                if (t1.Symbol.Type == t2.Symbol.Type)
                {
                    if (t2.Symbol is TokenTagToken)
                    {
                        // x and <ID>
                        TokenTagToken tokenTagToken = (TokenTagToken)t2.Symbol;
                        // track label->list-of-nodes for both token name and label (if any)

                        labels.Map(tokenTagToken.TokenName, tree);
                        if (tokenTagToken.Label != null)
                        {
                            labels.Map(tokenTagToken.Label, tree);
                        }
                    }
                    else
                    {
                        if (t1.GetText().Equals(t2.GetText(), StringComparison.Ordinal))
                        {
                        }
                        else
                        {
                            // x and x
                            // x and y
                            if (mismatchedNode == null)
                            {
                                mismatchedNode = t1;
                            }
                        }
                    }
                }
                else
                {
                    if (mismatchedNode == null)
                    {
                        mismatchedNode = t1;
                    }
                }
                return mismatchedNode;
            }
            if (tree is ParserRuleContext && patternTree is ParserRuleContext)
            {
                ParserRuleContext r1 = (ParserRuleContext)tree;
                ParserRuleContext r2 = (ParserRuleContext)patternTree;
                IParseTree mismatchedNode = null;
                // (expr ...) and <expr>
                RuleTagToken ruleTagToken = GetRuleTagToken(r2);
                if (ruleTagToken != null)
                {
                    if (r1.RuleIndex == r2.RuleIndex)
                    {
                        // track label->list-of-nodes for both rule name and label (if any)
                        labels.Map(ruleTagToken.RuleName, tree);
                        if (ruleTagToken.Label != null)
                        {
                            labels.Map(ruleTagToken.Label, tree);
                        }
                    }
                    else
                    {
                        if (mismatchedNode == null)
                        {
                            mismatchedNode = r1;
                        }
                    }
                    return mismatchedNode;
                }
                // (expr ...) and (expr ...)
                if (r1.ChildCount != r2.ChildCount)
                {
                    if (mismatchedNode == null)
                    {
                        mismatchedNode = r1;
                    }
                    return mismatchedNode;
                }
                int n = r1.ChildCount;
                for (int i = 0; i < n; i++)
                {
                    IParseTree childMatch = MatchImpl(r1.GetChild(i), patternTree.GetChild(i), labels);
                    if (childMatch != null)
                    {
                        return childMatch;
                    }
//.........这里部分代码省略.........
开发者ID:rharrisxtheta,项目名称:antlr4cs,代码行数:101,代码来源:ParseTreePatternMatcher.cs

示例6: GetRootOfSubtreeEnclosingRegion

 public static ParserRuleContext GetRootOfSubtreeEnclosingRegion(IParseTree t, int startTokenIndex, int stopTokenIndex)
 {
     // inclusive
     // inclusive
     int n = t.ChildCount;
     for (int i = 0; i < n; i++)
     {
         IParseTree child = t.GetChild(i);
         ParserRuleContext r = GetRootOfSubtreeEnclosingRegion(child, startTokenIndex, stopTokenIndex);
         if (r != null)
         {
             return r;
         }
     }
     if (t is ParserRuleContext)
     {
         ParserRuleContext r = (ParserRuleContext)t;
         if (startTokenIndex >= r.Start.TokenIndex && (r.Stop == null || stopTokenIndex <= r.Stop.TokenIndex))
         {
             // is range fully contained in t?
             // note: r.getStop()==null likely implies that we bailed out of parser and there's nothing to the right
             return r;
         }
     }
     return null;
 }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:26,代码来源:Trees.cs

示例7: GetTokensList

 public static IList<Token> GetTokensList(IParseTree node)
 {
     IList<Token> tokens = new List<Token>();
     if(node is ITerminalNode)
     {
         tokens.Add(GetTokenFromTerminalNode((ITerminalNode)node));
     }
     else
     {
         for(int i=0; i<node.ChildCount; i++)
         {
             var childNode = node.GetChild(i);
             if(childNode is ITerminalNode)
             {
                 tokens.Add(GetTokenFromTerminalNode((ITerminalNode)childNode));
             }
         }
     }
     return tokens;
 }
开发者ID:osmedile,项目名称:TypeCobol,代码行数:20,代码来源:ParseTreeUtils.cs

示例8: GetRootOfSubtreeEnclosingRegion

 public static ParserRuleContext GetRootOfSubtreeEnclosingRegion(IParseTree t, int startTokenIndex, int stopTokenIndex)
 {
     // inclusive
     // inclusive
     int n = t.ChildCount;
     for (int i = 0; i < n; i++)
     {
         IParseTree child = t.GetChild(i);
         ParserRuleContext r = GetRootOfSubtreeEnclosingRegion(child, startTokenIndex, stopTokenIndex);
         if (r != null)
         {
             return r;
         }
     }
     if (t is ParserRuleContext)
     {
         ParserRuleContext r = (ParserRuleContext)t;
         if (startTokenIndex >= r.Start.TokenIndex && stopTokenIndex <= r.Stop.TokenIndex)
         {
             // is range fully contained in t?
             return r;
         }
     }
     return null;
 }
开发者ID:EvgeniyKo,项目名称:antlr4cs,代码行数:25,代码来源:Trees.cs

示例9: Match

        private bool Match(IParseTree tree, IParseTree localTree)
        {
            tree = tree.Collapse();
            localTree = localTree.Collapse();
            if (localTree.ChildCount == 0) return CompareWrite(localTree.GetText(), tree);
            if (tree.ChildCount != localTree.ChildCount) return false;

            for (int i = 0; i < tree.ChildCount; i++)
            {
                if (!Match(tree.GetChild(i), localTree.GetChild(i))) return false;
            }

            return true;
        }
开发者ID:sandwwraith,项目名称:mathlogic,代码行数:14,代码来源:TreeUtils.cs

示例10: FindFirstNodeAfterOffset

        protected virtual ITerminalNode FindFirstNodeAfterOffset(IParseTree parseTree, int offset)
        {
            ITerminalNode lastNode = ParseTrees.GetStopNode(parseTree);
            if (lastNode == null)
                return null;

            ICaretToken caretToken = lastNode.Symbol as ICaretToken;
            if (caretToken != null)
                throw new NotImplementedException();
            else if (lastNode.Symbol.StartIndex < offset)
                return null;

            lastNode = parseTree as ITerminalNode;
            if (lastNode != null)
                return lastNode;

            for (int i = 0; i < parseTree.ChildCount; i++)
            {
                ITerminalNode node = FindFirstNodeAfterOffset(parseTree.GetChild(i), offset);
                if (node != null)
                    return node;
            }

            return null;
        }
开发者ID:chandramouleswaran,项目名称:LangSvcV2,代码行数:25,代码来源:SmartIndent.cs

示例11: LoadNode

 // загрузить дерево в TreeView по дереву парсинга
 public void LoadNode(TreeNode node, IParseTree tree)
 {
     string s;
     if (node == null)
     {// если дерева в TreeView еще нет
         {
             s = tree.GetType().ToString();
             if (s.Contains("+")) s = tree.GetType().ToString().Split('+')[1];
             if (s.Contains(".")) s = tree.GetType().ToString().Split('.')[3];
             if (s.Contains("Context")) s = "Rule:" + s.Substring(0, s.IndexOf("Context"));
             if (s.Contains("Terminal")) s = s.Substring(0, 8);
             node = tv.Nodes.Add(s + " # " + tree.GetText());
         }
     }
     else
     {
         {
             s = tree.GetType().ToString();
             if (s.Contains("+")) s = tree.GetType().ToString().Split('+')[1];
             if (s.Contains(".")) s = tree.GetType().ToString().Split('.')[3];
             if (s.Contains("Context")) s = "Rule:" + s.Substring(0, s.IndexOf("Context"));
             if (s.Contains("Terminal")) s = s.Substring(0, 8);
             node = node.Nodes.Add(s + " # " + tree.GetText());
         }
     }
     // загрузить дочерние ноды
     for (int i = 0; i < tree.ChildCount; i++)
     {
         LoadNode(node, tree.GetChild(i));
     }
 }
开发者ID:IraPro,项目名称:MyProject,代码行数:32,代码来源:TreeHelper.cs


注:本文中的IParseTree.GetChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。