public void TestOptional() { var expected = new SumRegex <int>(new EpsilonRegex <int>(), 123.ToRegex()); var actual = 123.ToRegex().Optional(); Assert.AreEqual(expected, actual); }
public void TestSumNotEmpty() { var expected = new SumRegex <int>(new SumRegex <int>(1.ToRegex(), 2.ToRegex()), 3.ToRegex()); var actual = RegexUtils.Sum(1.ToRegex(), 2.ToRegex(), 3.ToRegex()); Assert.AreEqual(expected, actual); }
public void CharacterClassEscapedBrackets() { const string input = "[\\[-\\]]"; var expected = new SumRegex <char>(new SumRegex <char>(new AtomicRegex <char>('['), new AtomicRegex <char>('\\')), new AtomicRegex <char>(']')); var actual = this.converter.Convert(input); Assert.AreEqual(expected, actual); }
public void SumAndEpsilonRegex() { const string input = "a|"; var expected = new SumRegex <char>(new AtomicRegex <char>('a'), new EpsilonRegex <char>()); var actual = this.converter.Convert(input); Assert.AreEqual(expected, actual); }
public void TestCreateList() { var expected = new SumRegex <int>( new EpsilonRegex <int>(), RegexUtils.Concat(123.ToRegex(), RegexUtils.Concat(0.ToRegex(), 123.ToRegex()).Starred())); var actual = RegexUtils.SeparatedBy(123.ToRegex(), 0.ToRegex()); Assert.AreEqual(expected, actual); }
public void CharacterClass() { const string input = "[a-d]"; var expected = new SumRegex <char>( new SumRegex <char>( new SumRegex <char>( new AtomicRegex <char>('a'), new AtomicRegex <char>('b')), new AtomicRegex <char>('c')), new AtomicRegex <char>('d')); var actual = this.converter.Convert(input); Assert.AreEqual(expected, actual); }
private Regex ParseAll() { var alreadyParsedBackup = this.alreadyParsed; try { var result = this.ParseWithoutSum(); while (this.Accept(typeof(SumToken))) { var other = this.ParseWithoutSum(); result = new SumRegex <char>(result, other); } return(result); } catch (RegexParserInternalException) { this.alreadyParsed = alreadyParsedBackup; throw; } }