当前位置: 首页>>代码示例>>C#>>正文


C# Grammar.Match方法代码示例

本文整理汇总了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);
        }
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:12,代码来源:SurrogatePairParserTests.cs

示例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);
        }
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:12,代码来源:SurrogatePairParserTests.cs

示例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);
        }
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:12,代码来源:SurrogatePairParserTests.cs

示例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()));
        }
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:SurrogatePairParserTests.cs

示例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)));
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:StringParserTests.cs

示例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));
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:NumberParserTests.cs

示例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)));
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:NumberParserTests.cs

示例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)));
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:NumberParserTests.cs

示例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);
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:14,代码来源:StringParserTests.cs

示例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);
			}
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:15,代码来源:StringParserTests.cs

示例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));
        }
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:16,代码来源:SurrogatePairParserTests.cs

示例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));
        }
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:SurrogatePairParserTests.cs

示例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");
		}
开发者ID:halid-durakovic,项目名称:Eto.Parse,代码行数:13,代码来源:NumberParserTests.cs


注:本文中的Grammar.Match方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。