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.ShouldEqual("abc");

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

            regex.Match("123Abc", 1).Value.ShouldEqual("23");
            regex.Match("$23ab!", 0).Success.ShouldBeFalse();
            regex.Match("$23ab!", 1).Value.ShouldEqual("23");
            regex.Match("$23ab!", 3).Value.ShouldEqual("ab");
        }
Beispiel #3
0
 public Pattern(string name, string pattern, bool skippable, params RegexOptions[] regexOptions)
     : base(name, skippable)
 {
     regex = new TokenRegex(pattern, regexOptions);
 }
Beispiel #4
0
        public void CanMatchLeadingCharactersByTokenRegex()
        {
            var end = new TokenRegex(@"$");
            var letters = new TokenRegex(@"[a-z]+");
            var digits = new TokenRegex(@"[0-9]+");
            var alphanumerics = new TokenRegex(@"[a-z0-9]+");

            var empty = new Text("");
            empty.Match(letters).ShouldFail();
            empty.Match(end).ShouldSucceed("");

            var abc123 = new Text("abc123");
            abc123.Match(digits).ShouldFail();
            abc123.Match(letters).ShouldSucceed("abc");
            abc123.Match(alphanumerics).ShouldSucceed("abc123");

            abc123.Advance(2).Match(digits).ShouldFail();
            abc123.Advance(2).Match(letters).ShouldSucceed("c");
            abc123.Advance(2).Match(alphanumerics).ShouldSucceed("c123");

            abc123.Advance(3).Match(digits).ShouldSucceed("123");
            abc123.Advance(3).Match(letters).ShouldFail();
            abc123.Advance(3).Match(alphanumerics).ShouldSucceed("123");

            abc123.Advance(6).Match(digits).ShouldFail();
            abc123.Advance(6).Match(letters).ShouldFail();
            abc123.Advance(6).Match(alphanumerics).ShouldFail();
        }
Beispiel #5
0
 public Pattern(string name, string pattern, bool skippable = false)
     : base(name, skippable)
 {
     regex = new TokenRegex(pattern);
 }
Beispiel #6
0
 public MatchResult Match(TokenRegex regex)
 {
     return regex.Match(input, index);
 }
Beispiel #7
0
 public Pattern(string name, string pattern, bool skippable, params RegexOptions[] regexOptions)
     : base(name, skippable)
 {
     regex = new TokenRegex(pattern, regexOptions);
 }
Beispiel #8
0
 public MatchResult Match(TokenRegex regex)
 {
     return(regex.Match(input, index));
 }