Esempio n. 1
0
 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);
        }
Esempio n. 3
0
 public GlobNode(GlobNodeType type, GlobNode child)
 {
     this.Type     = type;
     this.Text     = null;
     this.Children = new List <GlobNode> {
         child
     };
 }
Esempio n. 4
0
        public bool Scan(GlobNode node, string input)
        {
            if (node.Type != GlobNodeType.Tree)
                throw new InvalidOperationException();

            _input = input;
            return ProcessTree(node);
        }
Esempio n. 5
0
        public static string Process(GlobNode node)
        {
            if (node.Type != GlobNodeType.Tree)
            {
                throw new InvalidOperationException();
            }

            return(ProcessTree(node));
        }
Esempio n. 6
0
        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;
        }
Esempio n. 8
0
        public bool Scan(GlobNode node, string input)
        {
            if (node.Type != GlobNodeType.Tree)
            {
                throw new InvalidOperationException();
            }

            _input = input;
            return(ProcessTree(node));
        }
Esempio n. 9
0
        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");
        }
Esempio n. 10
0
        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");
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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 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();
     }
 }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
     }
 }
Esempio n. 17
0
        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();
            }
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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));
            }
        }
Esempio n. 20
0
        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));
 }
Esempio n. 22
0
 private void ProcessSegment(GlobNode child)
 {
     throw new NotImplementedException();
 }
Esempio n. 23
0
        public static string Process(GlobNode node)
        {
            Assert(node, GlobNodeType.Tree);

            return(ProcessTree((Tree)node) + "$");
        }
Esempio n. 24
0
 private void ProcessSegment(GlobNode child)
 {
     throw new NotImplementedException();
 }
 private static string ProcessDirectoryWildcard(GlobNode node)
 {
     return ".*";
 }
Esempio n. 26
0
 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();
 }
Esempio n. 29
0
 private static string ProcessCharacterWildcard(GlobNode node)
 {
     return(@"[^/]{1}");
 }
Esempio n. 30
0
 private static string ProcessWildcardString(GlobNode node)
 {
     return(@"[^/]*");
 }
 private static string ProcessWildcardString(GlobNode node)
 {
     return @"[^/]*";
 }
Esempio n. 32
0
 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);
 }
Esempio n. 34
0
 private static string ProcessIdentifier(GlobNode node)
 {
     return(Regex.Escape(node.Text));
 }
Esempio n. 35
0
 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);
     }
 }
Esempio n. 36
0
 private void ProcessRoot(GlobNode root)
 {
 }
Esempio n. 37
0
 private static string ProcessCharacterSet(GlobNode node)
 {
     return("[" + ProcessIdentifier(node.Children.First()) + "]");
 }
Esempio n. 38
0
 private static string ProcessTree(GlobNode node)
 {
     return(string.Join("/", node.Children.Select(ProcessSegment)));
 }
Esempio n. 39
0
        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)) + ")";
 }
Esempio n. 41
0
 private void ProcessRoot(GlobNode root)
 {
 }
 private static string ProcessPathSegment(GlobNode node)
 {
     return string.Join("", node.Children.Select(ProcessSubSegment));
 }
Esempio n. 43
0
 private static string ProcessPathSegment(GlobNode node)
 {
     return(string.Join("", node.Children.Select(ProcessSubSegment)));
 }
 private static string ProcessCharacterWildcard(GlobNode node)
 {
     return @"[^/]{1}";
 }
Esempio n. 45
0
 private static string ProcessLiteralSet(GlobNode node)
 {
     return("(" + string.Join(",", node.Children.Select(ProcessIdentifier)) + ")");
 }