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"); }
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"); }
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"); }
public Match NextToken() { var match = TokenRegex.Match(Text, Index); Index = match.Index + match.Length; return(match); }
protected Match GetMatch(TextBuffer textBuffer) { Match match = TokenRegex.Match(textBuffer.Remainder); if (match.Success) { textBuffer.MoveForward(match.Value.Length); return(match); } else { return(null); } }
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"; }