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


C# ITreeAdaptor.GetParent方法代码示例

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


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

示例1: InContext

        /// <summary>
        /// The worker for <see cref="InContext(TreeParser, string)"/>. It's <see langword="static"/> and full of
        /// parameters for testing purposes.
        /// </summary>
        private static bool InContext(
            ITreeAdaptor adaptor,
            string[] tokenNames,
            object t,
            string context)
        {
            if (Regex.IsMatch(context, DotDot))
            {
                // don't allow "..", must be "..."
                throw new ArgumentException("invalid syntax: ..");
            }

            if (Regex.IsMatch(context, DoubleEtc))
            {
                // don't allow double "..."
                throw new ArgumentException("invalid syntax: ... ...");
            }

            context = context.Replace("...", " ... "); // ensure spaces around ...
            context = context.Trim();
            string[] nodes = context.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int ni = nodes.Length - 1;
            t = adaptor.GetParent(t);
            while (ni >= 0 && t != null)
            {
                if (nodes[ni].Equals("..."))
                {
                    // walk upwards until we see nodes[ni-1] then continue walking
                    if (ni == 0)
                    {
                        // ... at start is no-op
                        return true;
                    }

                    string goal = nodes[ni - 1];
                    object ancestor = GetAncestor(adaptor, tokenNames, t, goal);
                    if (ancestor == null)
                        return false;

                    t = ancestor;
                    ni--;
                }

                string name = tokenNames[adaptor.GetType(t)];
                if (!name.Equals(nodes[ni]))
                {
                    //System.Console.Error.WriteLine("not matched: " + nodes[ni] + " at " + t);
                    return false;
                }

                // advance to parent and to previous element in context node list
                ni--;
                t = adaptor.GetParent(t);
            }

            if (t == null && ni >= 0)
                return false; // at root but more nodes to match
            return true;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:63,代码来源:TreeParserExtensions.cs

示例2: GetAncestor

        /// <summary>
        /// Helper for static <see cref="InContext(ITreeAdaptor, string[], object, string)"/>.
        /// </summary>
        private static object GetAncestor(ITreeAdaptor adaptor, string[] tokenNames, object t, string goal)
        {
            while (t != null)
            {
                string name = tokenNames[adaptor.GetType(t)];
                if (name.Equals(goal))
                    return t;

                t = adaptor.GetParent(t);
            }

            return null;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:16,代码来源:TreeParserExtensions.cs


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