private static void Assert(GlobNode node, GlobNodeType type) { if (node.Type != type) { throw new InvalidOperationException(); } }
public static string Process(GlobNode node) { if (node.Type != GlobNodeType.Tree) throw new InvalidOperationException(); return ProcessTree(node); }
public GlobNode(GlobNodeType type, GlobNode child) { this.Type = type; this.Text = null; this.Children = new List <GlobNode> { child }; }
public bool Scan(GlobNode node, string input) { if (node.Type != GlobNodeType.Tree) throw new InvalidOperationException(); _input = input; return ProcessTree(node); }
public static string Process(GlobNode node) { if (node.Type != GlobNodeType.Tree) { throw new InvalidOperationException(); } return(ProcessTree(node)); }
private bool ProcessTree(GlobNode node) { var root = node.Children.First(); ProcessRoot(root); foreach (var child in node.Children.Skip(1)) { ProcessSegment(child); } }
private static string ProcessRoot(GlobNode node) { if (node.Children.Count > 0) //windows root return Regex.Escape(node.Children[0].Text + ":"); if (!string.IsNullOrEmpty(node.Text)) // CWD return Regex.Escape(node.Text); return string.Empty; }
public bool Scan(GlobNode node, string input) { if (node.Type != GlobNodeType.Tree) { throw new InvalidOperationException(); } _input = input; return(ProcessTree(node)); }
private GlobNode ParseIdentifier() { if (this._currentToken.Kind == TokenKind.Identifier) { var identifier = new GlobNode(GlobNodeType.Identifier, this._currentToken.Spelling); this.AcceptIt(); return identifier; } throw new Exception("Unable to parse Identifier"); }
private GlobNode ParseIdentifier() { if (this._currentToken.Kind == TokenKind.Identifier) { var identifier = new GlobNode(GlobNodeType.Identifier, this._currentToken.Spelling); this.AcceptIt(); return(identifier); } throw new Exception("Unable to parse Identifier"); }
private void Compile() { if(_root != null) return; var parser = new Parser(this.Pattern); _root = parser.Parse(); //TODO: this is basically cheating and probably not efficient but it works for now. _regex = new Regex(GlobToRegexVisitor.Process(_root), RegexOptions.Compiled); }
private static string ProcessSegment(GlobNode node) { switch (node.Type) { case GlobNodeType.Root: return ProcessRoot(node); case GlobNodeType.DirectoryWildcard: return ProcessDirectoryWildcard(node); case GlobNodeType.PathSegment: return ProcessPathSegment(node); default: throw new InvalidOperationException(); } }
private void Compile() { if (_root != null) { return; } var parser = new Parser(this.Pattern); _root = parser.Parse(); //TODO: this is basically cheating and probably not efficient but it works for now. _regex = new Regex(GlobToRegexVisitor.Process(_root), RegexOptions.Compiled); }
private static string ProcessRoot(GlobNode node) { if (node.Children.Count > 0) //windows root { return(Regex.Escape(node.Children[0].Text + ":")); } if (!string.IsNullOrEmpty(node.Text)) // CWD { return(Regex.Escape(node.Text)); } return(string.Empty); }
private static string ProcessSubSegment(GlobNode node) { switch (node.Type) { case GlobNodeType.Identifier: return ProcessIdentifier(node); case GlobNodeType.CharacterSet: return ProcessCharacterSet(node); case GlobNodeType.LiteralSet: return ProcessLiteralSet(node); case GlobNodeType.CharacterWildcard: return ProcessCharacterWildcard(node); case GlobNodeType.WildcardString: return ProcessWildcardString(node); } }
private static string ProcessSegment(GlobNode node) { switch (node.Type) { case GlobNodeType.Root: return(ProcessRoot(node)); case GlobNodeType.DirectoryWildcard: return(ProcessDirectoryWildcard(node)); case GlobNodeType.PathSegment: return(ProcessPathSegment(node)); default: throw new InvalidOperationException(); } }
private void Compile() { if (_root != null) { return; } if (_regex != null) { return; } var parser = new Parser(this.Pattern); _root = parser.Parse(); var regexPattern = GlobToRegexVisitor.Process(_root); _regex = new Regex(regexPattern, _options == GlobOptions.Compiled ? RegexOptions.Compiled | RegexOptions.Singleline : RegexOptions.Singleline); }
private static string ProcessSubSegment(GlobNode node) { switch (node.Type) { case GlobNodeType.Identifier: return(ProcessIdentifier(node)); case GlobNodeType.CharacterSet: return(ProcessCharacterSet(node)); case GlobNodeType.LiteralSet: return(ProcessLiteralSet(node)); case GlobNodeType.CharacterWildcard: return(ProcessCharacterWildcard(node)); case GlobNodeType.WildcardString: return(ProcessWildcardString(node)); } }
private static string ProcessSubSegment(GlobNode node) { switch (node.Type) { case GlobNodeType.Identifier: return(ProcessIdentifier((Identifier)node)); case GlobNodeType.CharacterSet: return(ProcessCharacterSet((CharacterSet)node)); case GlobNodeType.LiteralSet: return(ProcessLiteralSet((LiteralSet)node)); case GlobNodeType.CharacterWildcard: return(ProcessCharacterWildcard((CharacterWildcard)node)); case GlobNodeType.StringWildcard: return(ProcessStringWildcard((StringWildcard)node)); default: throw new InvalidOperationException("Expected SubSegment, found " + node.Type); } }
private static string ProcessTree(GlobNode node) { return string.Join("/", node.Children.Select(ProcessSegment)); }
private void ProcessSegment(GlobNode child) { throw new NotImplementedException(); }
public static string Process(GlobNode node) { Assert(node, GlobNodeType.Tree); return(ProcessTree((Tree)node) + "$"); }
private static string ProcessDirectoryWildcard(GlobNode node) { return ".*"; }
private static string ProcessDirectoryWildcard(GlobNode node) { return(".*"); }
private static string ProcessCharacterSet(GlobNode node) { return "[" + ProcessIdentifier(node.Children.First()) + "]"; }
private void Assert(GlobNode node, GlobNodeType type) { if (node.Type != type) throw new InvalidOperationException(); }
private static string ProcessCharacterWildcard(GlobNode node) { return(@"[^/]{1}"); }
private static string ProcessWildcardString(GlobNode node) { return(@"[^/]*"); }
private static string ProcessWildcardString(GlobNode node) { return @"[^/]*"; }
public GlobNode(GlobNodeType type, GlobNode child) { this.Type = type; this.Text = null; this.Children = new List<GlobNode> {child}; }
private static string ProcessIdentifier(GlobNode node) { return Regex.Escape(node.Text); }
private static string ProcessIdentifier(GlobNode node) { return(Regex.Escape(node.Text)); }
private static string ProcessSubSegment(GlobNode node) { switch (node.Type) { case GlobNodeType.Identifier: return ProcessIdentifier((Identifier)node); case GlobNodeType.CharacterSet: return ProcessCharacterSet((CharacterSet)node); case GlobNodeType.LiteralSet: return ProcessLiteralSet((LiteralSet)node); case GlobNodeType.CharacterWildcard: return ProcessCharacterWildcard((CharacterWildcard)node); case GlobNodeType.StringWildcard: return ProcessStringWildcard((StringWildcard)node); default: throw new InvalidOperationException("Expected SubSegment, found " + node.Type); } }
private void ProcessRoot(GlobNode root) { }
private static string ProcessCharacterSet(GlobNode node) { return("[" + ProcessIdentifier(node.Children.First()) + "]"); }
private static string ProcessTree(GlobNode node) { return(string.Join("/", node.Children.Select(ProcessSegment))); }
public static string Process(GlobNode node) { Assert(node, GlobNodeType.Tree); return ProcessTree((Tree)node) + "$"; }
private static string ProcessLiteralSet(GlobNode node) { return "(" + string.Join(",", node.Children.Select(ProcessIdentifier)) + ")"; }
private static string ProcessPathSegment(GlobNode node) { return string.Join("", node.Children.Select(ProcessSubSegment)); }
private static string ProcessPathSegment(GlobNode node) { return(string.Join("", node.Children.Select(ProcessSubSegment))); }
private static string ProcessCharacterWildcard(GlobNode node) { return @"[^/]{1}"; }
private static string ProcessLiteralSet(GlobNode node) { return("(" + string.Join(",", node.Children.Select(ProcessIdentifier)) + ")"); }