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


C# SyntaxNode.GetKind方法代码示例

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


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

示例1: ValidateNonTerminal

        private bool ValidateNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, string filename = "", List<Failure> failures = null)
        {
            var retVal = true;
            if (!string.IsNullOrEmpty(filename))
            {
                filename = Path.GetFullPath(filename);
            }
            else if (filename == null)
            {
                filename = string.Empty;
            }

            if (nonTerminal != null)
            {
                foreach (var child in nonTerminal.ChildNodesAndTokens())
                {
                    retVal = retVal & ValidateNodeOrToken(child, tree, filename, failures);
                }

                bool pass = false;
                foreach (var rule in m_NonTerminalRules.Values)
                {
                    var errorText = string.Empty;
                    pass = rule.Test(nonTerminal, tree, ref errorText);
                    if (!pass)
                    {
                        if (failures != null)
                        {
                            failures.Add(new Failure(filename, rule, nonTerminal.GetKind(), errorText, new FailureLocation(nonTerminal.Span, tree)));
                        }

                        ValidationFailed(errorText, rule);
                    }

                    retVal = retVal & pass;
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:40,代码来源:TreeValidator.cs

示例2: ZeroWidthOrMissingNonTerminals

        public bool ZeroWidthOrMissingNonTerminals(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            if (nonTerminal.ContainsDiagnostics || tree.GetDiagnostics().Any())
            {
                if (nonTerminal.IsMissing)
                {
                    if (nonTerminal.Span.Length == 0)
                    {
                        foreach (var child in nonTerminal.ChildNodesAndTokens())
                        {
                            if (child.IsNode && !child.AsNode().IsMissing)
                            {
                                retVal = false;
                                errorText = "This missing non-terminal has a non-missing child non-terminal";
                                continue;
                            }
                            else if (child.IsToken && !child.AsToken().IsMissing)
                            {
                                retVal = false;
                                errorText = "This missing non-terminal has a non-missing child token";
                                continue;
                            }
                        }
                    }
                    else
                    {
                        retVal = false;
                        errorText = "Missing non-terminals should have 0 Span width";
                    }
                }
                else if (nonTerminal.Span.Length == 0)
                {
                    var kind = nonTerminal.GetKind();
                    if (!(kind == "OmittedArgument" || kind.Contains("Bad") ||
                        (kind == "CompilationUnit" && 
                        nonTerminal.ChildNodesAndTokens().Count == 1 &&
                        nonTerminal.ChildNodesAndTokens().First().GetKind() == "EndOfFileToken")))
                    {
                        //Ignore BadStatement and BadDirective (these can only be present if tree has errors).
                        //Ignore case where code file is empty or file only includes trivia - in this case
                        //root node will have a single child ('EndOfFileToken') which has 0 width.
                        retVal = false;
                        errorText = "Non-terminals with 0 Span width should have IsMissing set to 'True'";
                    }
                }
            }
            else
            {
                if (nonTerminal.IsMissing)
                {
                    retVal = false;
                    errorText = "A tree with 0 errors should not contain missing non-terminals";
                }
                else if (nonTerminal.Span.Length == 0)
                {
                    var kind = nonTerminal.GetKind();
                    if (!(kind == "OmittedArgument" || (kind == "CompilationUnit" && nonTerminal.ChildNodesAndTokens().Count == 1 && nonTerminal.ChildNodesAndTokens().First().GetKind() == "EndOfFileToken")))
                    {
                        //Ignore case where code file is empty or file only includes trivia - in this case
                        //root node will have a single child ('EndOfFileToken') which has 0 width.
                        retVal = false;
                        errorText = "A tree with 0 errors should not contain non-terminals with 0 width";
                    }
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:69,代码来源:NodeRules.cs

示例3: BadNonTerminals

        public bool BadNonTerminals(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            var kind = nonTerminal.GetKind();
            if (tree.GetDiagnostics().Any())
            {
                if (kind.Contains("Bad"))
                {
                    if (tree.GetDiagnostics(nonTerminal).Any())
                    {
                    }
                    else
                    {
                        retVal = false;
                        errorText = "Bad non-terminals should have at least one error on them";
                    }
                }
            }
            else if (kind.Contains("Bad"))
            {
                retVal = false;
                errorText = "A tree with 0 errors should not contain Bad non-terminals";
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:26,代码来源:NodeRules.cs

示例4: ParentForNonTerminal

        public bool ParentForNonTerminal(SyntaxNode nonTerminal, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            if (nonTerminal.Parent == null)
            {
                if (!nonTerminal.IsStructuredTrivia && nonTerminal.GetKind() != "CompilationUnit")
                {
                    retVal = false;
                    errorText = "This non-terminal has a null parent";
                }
            }
            else
            {
                if (nonTerminal.IsStructuredTrivia)
                {
                    retVal = false;
                    errorText = "This structured trivia has a non-null parent";
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:22,代码来源:NodeRules.cs


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