public override IEnumerable <Warning> Validate(string fileName, NodeTree tree)
        {
            var nodeNames = tree.DecendantNodesWithName("nodeName");

            foreach (var name in nodeNames)
            {
                var flexDeclarations  = name.DecendantNodesWithName("flexOrderDeclaration");
                var staticDeclaration = name.DecendantNodesWithName("staticOrderDeclaration");
                if (flexDeclarations.Any() || staticDeclaration.Any())
                {
                    var parent = name.Parent;
                    var foundConfigNodeParent = false;
                    for (; parent != null; parent = parent.Parent)
                    {
                        if (!foundConfigNodeParent)
                        {
                            if (parent.Name == "configNode")
                            {
                                foundConfigNodeParent = true;
                            }
                        }
                        else
                        {
                            if (parent.Name == "configNode")
                            {
                                yield return(new Warning(fileName, name.Start, name.End, Category, "CN003"));

                                break;
                            }
                        }
                    }
                }
                if (flexDeclarations.Any(decl => decl.Text != "FOR") && staticDeclaration.Any())
                {
                    yield return(new Warning(fileName, name.Start, name.End, Category, "CN001"));
                }
                if (flexDeclarations.Count(decl => decl.Text == "FOR") > 1)
                {
                    yield return(new Warning(fileName, name.Start, name.End, Category, "CN002"));
                }
                if (staticDeclaration.Count() > 1)
                {
                    yield return(new Warning(fileName, name.Start, name.End, Category, "CN001"));
                }
                if (flexDeclarations.Where(decl => decl.Text != "FOR").GroupBy(decl => decl.Text).Count() > 1)
                {
                    yield return(new Warning(fileName, name.Start, name.End, Category, "CN001"));
                }
            }
        }
コード例 #2
0
 private Tuple<NodeTree, int> BuildAST(string text, IEnumerable<LexicalElement> orderedTokens)
 {
     var root = orderedTokens.FirstOrDefault();
     if (root == null) return null;
     var node = new NodeTree(text, root);
     var subTokens = orderedTokens.Skip(1).TakeWhile(element => element.StartCursor.Location >= root.StartCursor.Location);
     var usedTokens = 1;
     while (subTokens.Any())
     {
         var childNode = BuildAST(text, subTokens);
         if (childNode != null)
         {
             node.Add(childNode.Item1);
             subTokens = subTokens.Skip(childNode.Item2);
             usedTokens += childNode.Item2;
         }
     }
     return new Tuple<NodeTree, int>(node, usedTokens);
 }
 public override IEnumerable<Warning> Validate(string fileName, NodeTree tree)
 {
     var nodeNames = tree.DecendantNodesWithName("nodeName");
     foreach (var name in nodeNames)
     {
         var flexDeclarations = name.DecendantNodesWithName("flexOrderDeclaration");
         var staticDeclaration = name.DecendantNodesWithName("staticOrderDeclaration");
         if (flexDeclarations.Any() || staticDeclaration.Any())
         {
             var parent = name.Parent;
             var foundConfigNodeParent = false;
             for (; parent != null; parent = parent.Parent)
             {
                 if (!foundConfigNodeParent)
                 {
                     if (parent.Name == "configNode")
                         foundConfigNodeParent = true;
                 }
                 else
                 {
                     if (parent.Name == "configNode")
                     {
                         yield return new Warning(fileName, name.Start, name.End, Category, "CN003");
                         break;
                     }
                 }
             }
         }
         if (flexDeclarations.Any(decl => decl.Text != "FOR") && staticDeclaration.Any())
             yield return new Warning(fileName, name.Start, name.End, Category, "CN001");
         if (flexDeclarations.Count(decl => decl.Text == "FOR") > 1)
             yield return new Warning(fileName, name.Start, name.End, Category, "CN002");
         if (staticDeclaration.Count() > 1)
             yield return new Warning(fileName, name.Start, name.End, Category, "CN001");
         if (flexDeclarations.Where(decl => decl.Text != "FOR").GroupBy(decl => decl.Text).Count() > 1)
             yield return new Warning(fileName, name.Start, name.End, Category, "CN001");
     }
 }
コード例 #4
0
        private Tuple <NodeTree, int> BuildAST(string text, IEnumerable <LexicalElement> orderedTokens)
        {
            var root = orderedTokens.FirstOrDefault();

            if (root == null)
            {
                return(null);
            }
            var node       = new NodeTree(text, root);
            var subTokens  = orderedTokens.Skip(1).TakeWhile(element => element.StartCursor.Location >= root.StartCursor.Location);
            var usedTokens = 1;

            while (subTokens.Any())
            {
                var childNode = BuildAST(text, subTokens);
                if (childNode != null)
                {
                    node.Add(childNode.Item1);
                    subTokens   = subTokens.Skip(childNode.Item2);
                    usedTokens += childNode.Item2;
                }
            }
            return(new Tuple <NodeTree, int>(node, usedTokens));
        }
コード例 #5
0
 public Builder(string text, IEnumerable <LexicalElement> lexical)
 {
     ast = BuildAST(text, lexical.Reverse()).Item1;
 }
コード例 #6
0
 internal void Add(NodeTree childNode)
 {
     subNodes.AddFirst(childNode);
     childNode.Parent = this;
 }
コード例 #7
0
 internal void Add(NodeTree childNode)
 {
     subNodes.AddFirst(childNode);
     childNode.Parent = this;
 }
コード例 #8
0
 public abstract IEnumerable<Warning> Validate(string fileName, NodeTree tree);
コード例 #9
0
 public Builder(string text, IEnumerable<LexicalElement> lexical)
 {
     ast = BuildAST(text, lexical.Reverse()).Item1;
 }
コード例 #10
0
 public abstract IEnumerable <Warning> Validate(string fileName, NodeTree tree);