示例#1
0
        public void SupportsOptionalRegexOptions()
        {
            var regex = new TokenRegex(@"[a-z]+", RegexOptions.IgnoreCase);

            regex.Match("123aBc0", 0).Success.ShouldBeFalse();

            regex.Match("123aBc0", 3).Success.ShouldBeTrue();
            regex.Match("123aBc0", 3).Value.ShouldBe("aBc");

            regex.Match("123aBc0", 4).Success.ShouldBeTrue();
            regex.Match("123aBc0", 4).Value.ShouldBe("Bc");
        }
示例#2
0
        public void CanMatchRegexStartingFromGivenCharacterPosition()
        {
            var regex = new TokenRegex(@"[a-z]+");

            regex.Match("123abc0", 0).Success.ShouldBeFalse();

            regex.Match("123abc0", 3).Success.ShouldBeTrue();
            regex.Match("123abc0", 3).Value.ShouldBe("abc");

            regex.Match("123abc0", 4).Success.ShouldBeTrue();
            regex.Match("123abc0", 4).Value.ShouldBe("bc");
        }
示例#3
0
        public void SupportsOptionalRegexOptions()
        {
            var regex = new TokenRegex(@"[a-z]+", RegexOptions.IgnoreCase);

            regex.Match("123aBc0", 0).Success.ShouldBeFalse();

            regex.Match("123aBc0", 3).Success.ShouldBeTrue();
            regex.Match("123aBc0", 3).Value.ShouldBe("aBc");

            regex.Match("123aBc0", 4).Success.ShouldBeTrue();
            regex.Match("123aBc0", 4).Value.ShouldBe("Bc");
        }
示例#4
0
        public void CanMatchMultilineAndCommentedRegexes()
        {
            var regex = new TokenRegex(
                @"  [a-z]+   # Just Lower
                  | [A-Z]+   # Just Upper
                  | [0-9]+   # Just Digit");

            regex.Match("123Abc", 1).Value.ShouldBe("23");
            regex.Match("$23ab!", 0).Success.ShouldBeFalse();
            regex.Match("$23ab!", 1).Value.ShouldBe("23");
            regex.Match("$23ab!", 3).Value.ShouldBe("ab");
        }
示例#5
0
        public void CanMatchRegexStartingFromGivenCharacterPosition()
        {
            var regex = new TokenRegex(@"[a-z]+");

            regex.Match("123abc0", 0).Success.ShouldBeFalse();

            regex.Match("123abc0", 3).Success.ShouldBeTrue();
            regex.Match("123abc0", 3).Value.ShouldBe("abc");

            regex.Match("123abc0", 4).Success.ShouldBeTrue();
            regex.Match("123abc0", 4).Value.ShouldBe("bc");
        }
示例#6
0
        public void CanMatchMultilineAndCommentedRegexes()
        {
            var regex = new TokenRegex(
                @"  [a-z]+   # Just Lower
                  | [A-Z]+   # Just Upper
                  | [0-9]+   # Just Digit");

            regex.Match("123Abc", 1).Value.ShouldBe("23");
            regex.Match("$23ab!", 0).Success.ShouldBeFalse();
            regex.Match("$23ab!", 1).Value.ShouldBe("23");
            regex.Match("$23ab!", 3).Value.ShouldBe("ab");
        }
示例#7
0
            public Match NextToken()
            {
                var match = TokenRegex.Match(Text, Index);

                Index = match.Index + match.Length;

                return(match);
            }
示例#8
0
        protected Match GetMatch(TextBuffer textBuffer)
        {
            Match match = TokenRegex.Match(textBuffer.Remainder);

            if (match.Success)
            {
                textBuffer.MoveForward(match.Value.Length);
                return(match);
            }
            else
            {
                return(null);
            }
        }
示例#9
0
        public virtual void Parse(string code)
        {
            var match = TokenRegex.Match(code);

            if (!match.Success)
            {
                //Console.WriteLine($"|{TokenRegex}| ({code})");
                //TODO logging
                return;
            }

            Value     = match.Value;
            Groups    = match.Groups.Cast <Group>().ToList();
            ValueType = "string";
        }