本文整理汇总了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);
}
示例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();
}
示例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);
}