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


C# Lexer.ToArray方法代码示例

本文整理汇总了C#中Lexer.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.ToArray方法的具体用法?C# Lexer.ToArray怎么用?C# Lexer.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lexer的用法示例。


在下文中一共展示了Lexer.ToArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CorrectLineAndColumnNumbers

        public void CorrectLineAndColumnNumbers()
        {
            var input = "Hello World!\nSecond line\r\nFoo";

            MemoryStream m = new MemoryStream();
            var w = new StreamWriter(m);
            w.Write(input);
            w.Flush();
            m.Position = 0;

            var word = new Terminal("Word", "\\S+");
            var whitespace = new Terminal("Whitespace", " |\n|\r");

            var lexer = new Lexer(m, word, whitespace);
            Token[] tokens = lexer.ToArray();

            Assert.AreEqual(10, tokens.Length);
            AssertToken(tokens[0], "Word", 1, 1);
            AssertToken(tokens[1], "Whitespace", 1, 6);
            AssertToken(tokens[2], "Word", 1, 7);
            AssertToken(tokens[3], "Whitespace", 1, 13);
            AssertToken(tokens[4], "Word", 2, 1);
            AssertToken(tokens[5], "Whitespace", 2, 7);
            AssertToken(tokens[6], "Word", 2, 8);
            AssertToken(tokens[7], "Whitespace", 2, 12);
            AssertToken(tokens[8], "Whitespace", 2, 13);
            AssertToken(tokens[9], "Word", 3, 1);
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:28,代码来源:LexerTest.cs

示例2: InvalidInputStream

        public void InvalidInputStream()
        {
            var myString = "Hello World!";

            MemoryStream m = new MemoryStream();
            var w = new StreamWriter(m);
            w.Write(myString);
            w.Flush();

            m.Position = 0;

            Terminal singleCharacter = new Terminal("Match a single A", "A");

            Lexer t = new Lexer(m, singleCharacter);
            Token[] characters = t.ToArray();
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:16,代码来源:LexerTest.cs

示例3: ReadATokenStream

        public void ReadATokenStream()
        {
            var myString = "Hello World!";

            MemoryStream m = new MemoryStream();
            var w = new StreamWriter(m);
            w.Write(myString);
            w.Flush();

            m.Position = 0;

            Terminal singleCharacter = new Terminal("Match a single character", ".");

            Lexer t = new Lexer(m, singleCharacter);
            Token[] characters = t.ToArray();

            Assert.AreEqual(myString.Length, characters.Length);

            for (int i = 0; i < myString.Length; i++)
                Assert.AreEqual(myString[i].ToString(), characters[i].Value);
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:21,代码来源:LexerTest.cs


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