本文整理汇总了C#中Lexer.NextToken方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.NextToken方法的具体用法?C# Lexer.NextToken怎么用?C# Lexer.NextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer.NextToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAsteriskAsArithmeticOperator
public void GetAsteriskAsArithmeticOperator()
{
Lexer lexer = new Lexer("*");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("*", token.Value);
Assert.AreEqual(TokenType.Operator, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例2: GetCommaAsDelimiter
public void GetCommaAsDelimiter()
{
Lexer lexer = new Lexer(",");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual(",", token.Value);
Assert.AreEqual(TokenType.Delimiter, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例3: GetComparisonOperators
public void GetComparisonOperators()
{
Lexer lexer = new Lexer("< > <= >= == /=");
foreach (var value in new string[] { "<", ">", "<=", ">=", "==", "/=" })
{
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual(value, token.Value);
Assert.AreEqual(TokenType.Operator, token.Type);
}
Assert.IsNull(lexer.NextToken());
}
示例4: GetArrowsAsOperators
public void GetArrowsAsOperators()
{
Lexer lexer = new Lexer("-> <-");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("->", token.Value);
Assert.AreEqual(TokenType.Operator, token.Type);
token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("<-", token.Value);
Assert.AreEqual(TokenType.Operator, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例5: SkipMultiLineComment
public void SkipMultiLineComment()
{
Lexer lexer = new Lexer("{- a comment\nin many lines -}");
Assert.IsNull(lexer.NextToken());
}
示例6: SkipComment
public void SkipComment()
{
Lexer lexer = new Lexer("-- a comment\n");
Assert.IsNull(lexer.NextToken());
}
示例7: GetUnclosedString
public void GetUnclosedString()
{
Lexer lexer = new Lexer("\"foo");
try
{
lexer.NextToken();
Assert.Fail();
}
catch (Exception ex)
{
Assert.IsInstanceOfType(ex, typeof(LexerException));
Assert.AreEqual("Unclosed string", ex.Message);
}
}
示例8: TestParse
private static void TestParse(string text, params string[] values)
{
Lexer lexer = new Lexer(text);
Token token;
for (int k = 0; k < values.Length; k++)
{
token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual(values[k], token.Value);
}
Assert.IsNull(lexer.NextToken());
}
示例9: GetIndexingOperator
public void GetIndexingOperator()
{
Lexer lexer = new Lexer("!!");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("!!", token.Value);
Assert.AreEqual(TokenType.Operator, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例10: GetParensAsDelimiters
public void GetParensAsDelimiters()
{
Lexer lexer = new Lexer("()");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("(", token.Value);
Assert.AreEqual(TokenType.Delimiter, token.Type);
token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual(")", token.Value);
Assert.AreEqual(TokenType.Delimiter, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例11: GetNullTokenFromNullText
public void GetNullTokenFromNullText()
{
Lexer lexer = new Lexer(null);
Assert.IsNull(lexer.NextToken());
}
示例12: GetNullTokenFromEmptyText
public void GetNullTokenFromEmptyText()
{
Lexer lexer = new Lexer(string.Empty);
Assert.IsNull(lexer.NextToken());
}
示例13: GetNameWithDigits
public void GetNameWithDigits()
{
Lexer lexer = new Lexer("foo42");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("foo42", token.Value);
Assert.AreEqual(TokenType.Name, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例14: GetInteger
public void GetInteger()
{
Lexer lexer = new Lexer("42");
var token = lexer.NextToken();
Assert.IsNotNull(token);
Assert.AreEqual("42", token.Value);
Assert.AreEqual(TokenType.Integer, token.Type);
Assert.IsNull(lexer.NextToken());
}
示例15: UnexpectedChar
public void UnexpectedChar()
{
var lexer = new Lexer("@");
try
{
lexer.NextToken();
Assert.Fail();
}
catch (Exception ex)
{
Assert.IsInstanceOfType(ex, typeof(LexerException));
Assert.AreEqual("Unexpected '@'", ex.Message);
}
}