本文整理汇总了C#中Grammar.Match方法的典型用法代码示例。如果您正苦于以下问题:C# Grammar.Match方法的具体用法?C# Grammar.Match怎么用?C# Grammar.Match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grammar
的用法示例。
在下文中一共展示了Grammar.Match方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMatchingRange
public void TestMatchingRange(int codePoint)
{
var sample = char.ConvertFromUtf32(codePoint);
var grammar = new Grammar();
var parser = new SurrogatePairRangeTerminal(0x12345, 0x8F4FE);
grammar.Inner = parser.Named("char");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
}
示例2: TestMatchOutsideRange
public void TestMatchOutsideRange(int codePoint)
{
var sample = char.ConvertFromUtf32(codePoint);
var grammar = new Grammar();
var parser = new SurrogatePairRangeTerminal(0x12346, 0x8F4FD);
grammar.Inner = parser.Named("char");
var match = grammar.Match(sample);
Assert.IsFalse(match.Success, "Value {0} should be outside given range", codePoint);
}
示例3: TestUnmatchedSpecificSurrogatePairByCodePoint
public void TestUnmatchedSpecificSurrogatePairByCodePoint()
{
var sample = char.ConvertFromUtf32(0x17DF6);
var grammar = new Grammar();
var parser = new SingleSurrogatePairTerminal(0x87FFF);
grammar.Inner = parser.Named("char");
var match = grammar.Match(sample);
Assert.IsFalse(match.Success, match.ErrorMessage);
}
示例4: TestMatchingSpecificSurrogatePairByCodePoint
public void TestMatchingSpecificSurrogatePairByCodePoint()
{
var sample = char.ConvertFromUtf32(0x87FFF);
var grammar = new Grammar();
var parser = new SingleSurrogatePairTerminal(0x87FFF);
grammar.Inner = parser.Named("char");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
Assert.AreEqual(0x87FFF, parser.GetValue(match.Find("char").Single()));
}
示例5: TestDoubleQuoting
public void TestDoubleQuoting()
{
var sample = "\"string\"\" ''1'\",'string'' \"\"2\"'";
var grammar = new Grammar();
var str = new StringParser { AllowDoubleQuote = true };
grammar.Inner = (+str.Named("str")).SeparatedBy(",");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
CollectionAssert.AreEquivalent(new string[] { "string\" ''1'", "string' \"\"2\"" }, match.Find("str").Select(m => str.GetValue(m)));
}
示例6: TestInt32Values
public void TestInt32Values()
{
var sample = "123,+123,-123";
var grammar = new Grammar();
var num = new NumberParser { AllowSign = true, AllowDecimal = true, ValueType = typeof(int) };
grammar.Inner = (+num.Named("str")).SeparatedBy(",");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
CollectionAssert.AreEquivalent(new Int32[] { 123, 123, -123 }, match.Find("str").Select(m => (int)m.Value));
}
示例7: TestExponent
public void TestExponent()
{
var sample = "123E-02,123E+10,123.4567E+5,1234E2";
var grammar = new Grammar();
var num = new NumberParser { AllowDecimal = true, AllowExponent = true };
grammar.Inner = (+num.Named("str")).SeparatedBy(",");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
CollectionAssert.AreEquivalent(new Decimal[] { 123E-2M, 123E+10M, 123.4567E+5M, 1234E+2M }, match.Find("str").Select(m => num.GetValue(m)));
}
示例8: TestSign
public void TestSign()
{
var sample = "123.4567,+123.4567,-123.4567";
var grammar = new Grammar();
var num = new NumberParser { AllowSign = true, AllowDecimal = true };
grammar.Inner = (+num.Named("str")).SeparatedBy(",");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
CollectionAssert.AreEquivalent(new Decimal[] { 123.4567M, 123.4567M, -123.4567M }, match.Find("str").Select(m => num.GetValue(m)));
}
示例9: TestEscaping
public void TestEscaping()
{
var sample = "\"string\\'\\\"\\0\\a\\b\\f\\n\\r\\t\\v\\x123\\u1234\\U00001234 1\",'string\\'\\\"\\0\\a\\b\\f\\n\\r\\t\\v\\x123\\u1234\\U00001234 2'";
var grammar = new Grammar();
var str = new StringParser { AllowEscapeCharacters = true };
grammar.Inner = (+str.Named("str")).SeparatedBy(",");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
var values = match.Find("str").Select(m => str.GetValue(m)).ToArray();
CollectionAssert.AreEquivalent(new string[] { "string\'\"\0\a\b\f\n\r\t\v\x123\u1234\U00001234 1", "string\'\"\0\a\b\f\n\r\t\v\x123\u1234\U00001234 2" }, values);
}
示例10: TestErrorConditionsWithOptions
public void TestErrorConditionsWithOptions()
{
var samples = new string[] { "string 1", "\"string 2", "'string 3", "'string ''4", "string5'", "string6\"", "\"string\\\"7" };
var grammar = new Grammar();
var str = new StringParser { AllowDoubleQuote = true, AllowNonQuoted = true, AllowEscapeCharacters = true };
grammar.Inner = str.Named("str");
foreach (var sample in samples)
{
var match = grammar.Match(sample);
Assert.IsFalse(match.Success, "Should not match string {0}", sample);
}
}
示例11: TestAnySurrogatePair
public void TestAnySurrogatePair()
{
var chars = string.Format("{0},{1},{2}",
char.ConvertFromUtf32(0x10000),
char.ConvertFromUtf32(0x87FFF),
char.ConvertFromUtf32(0x10FFFF));
var grammar = new Grammar();
var parser = new AnySurrogatePairTerminal();
grammar.Inner = (+parser.Named("char")).SeparatedBy(",");
var match = grammar.Match(chars);
Assert.IsTrue(match.Success, match.ErrorMessage);
CollectionAssert.AreEquivalent(new []{0x10000, 0x87FFF, 0x10FFFF}, match.Find("char").Select(parser.GetValue));
}
示例12: TestUseWithOtherParser
public void TestUseWithOtherParser()
{
var sample = "abc" + char.ConvertFromUtf32(0x8F4FE) + "def" + char.ConvertFromUtf32(0x56734);
var grammar = new Grammar();
var parser = new LetterTerminal() | new AnySurrogatePairTerminal();
grammar.Inner = (+parser).Named("char");
var match = grammar.Match(sample);
Assert.IsTrue(match.Success, match.ErrorMessage);
Assert.That(match.Length, Is.EqualTo(10));
}
示例13: TestErrorAtEnd
public void TestErrorAtEnd()
{
var sample = "Num:";
var grammar = new Grammar();
var num = new NumberParser { };
grammar.Inner = "Num:" & num.WithName("num");
var match = grammar.Match(sample);
Assert.IsFalse(match.Success, match.ErrorMessage);
Assert.AreEqual(sample.Length, match.ErrorIndex, "Error index should be at the end");
Assert.AreEqual(sample.Length, match.ChildErrorIndex, "Child error index should be at the end");
}