/// <summary> /// Returns <see cref="Path" /> instances matching the specified pattern. /// </summary> /// <param name="pattern">The pattern to match.</param> /// <returns> /// <see cref="Path" /> instances matching the specified pattern. /// </returns> public IEnumerable<Path> Match(string pattern) { var scanner = new Scanner(pattern); var parser = new Parser(scanner, _environment); var path = parser.Parse(); var rootNodes = new List<Node>(); while (path.Count > 0) { // Pop the first path item. var segment = path[0]; path.RemoveAt(0); if (segment.IsWildcard) { path.Insert(0, segment); break; } rootNodes.Add(segment); } // Fix up the tree. var newRoot = FixRootNode(rootNodes); if (newRoot != null) { rootNodes[0] = newRoot; } // Ge the root. var rootDirectory = new DirectoryPath(string.Join("/", rootNodes.Select(x => x.Render()))); // Nothing left in the path? if (path.Count == 0) { // We have an absolute path with no wild cards. return new Path[] { rootDirectory }; } // Walk the root and return the unique results. var segments = new Stack<Node>(((IEnumerable<Node>)path).Reverse()); var results = Walk(rootDirectory, segments); return new HashSet<Path>(results, new PathComparer(_environment.IsUnix())).ToArray(); }
public Parser(Scanner scanner, IEnvironment environment) { _scanner = scanner; _environment = environment; _currentToken = null; }