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")); } } }
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"); } }
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 Builder(string text, IEnumerable <LexicalElement> lexical) { ast = BuildAST(text, lexical.Reverse()).Item1; }
internal void Add(NodeTree childNode) { subNodes.AddFirst(childNode); childNode.Parent = this; }
public abstract IEnumerable<Warning> Validate(string fileName, NodeTree tree);
public Builder(string text, IEnumerable<LexicalElement> lexical) { ast = BuildAST(text, lexical.Reverse()).Item1; }
public abstract IEnumerable <Warning> Validate(string fileName, NodeTree tree);