本文整理汇总了C#中Scanner.NextToken方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.NextToken方法的具体用法?C# Scanner.NextToken怎么用?C# Scanner.NextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.NextToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignmentAndColon
public void AssignmentAndColon()
{
var lexer = new Scanner(":");
Assert.That(lexer.NextToken(), Is.InstanceOf<TypeDeclaration>());
lexer = new Scanner(":=");
Assert.That(lexer.NextToken(), Is.InstanceOf<AssignmentToken>());
}
示例2: Keywords
public void Keywords(string keyword)
{
var lexer = new Scanner(keyword);
Token next = lexer.NextToken();
Assert.That(next, Is.InstanceOf<KeywordToken>());
Assert.That(((KeywordToken)next).Value, Is.EqualTo(keyword));
}
示例3: DivisionSymbolIsNotConfusedWithAComment
public void DivisionSymbolIsNotConfusedWithAComment()
{
var lexer = new Scanner("/");
Assert.That(lexer.NextToken(), Is.InstanceOf<BinaryOperator>());
lexer = new Scanner("// .. / ..\n /");
Assert.That(((BinaryOperator) lexer.NextToken()).Value, Is.EqualTo("/"));
Assert.That(lexer.Col, Is.EqualTo(2));
Assert.That(lexer.Row, Is.EqualTo(2));
}
示例4: CommentsAreSkipped
public void CommentsAreSkipped()
{
var lexer = new Scanner("// ... \n // ... \n foo");
var token = (Identifier) lexer.NextToken();
Assert.That(token.Value, Is.EqualTo("foo"));
Assert.That(token.Row, Is.EqualTo(3));
Assert.That(token.Col, Is.EqualTo(4));
lexer = new Scanner("/* ... \n\n*/ \tfoo");
token = (Identifier) lexer.NextToken();
Assert.That(token.Value, Is.EqualTo("foo"));
Assert.That(token.Row, Is.EqualTo(3));
Assert.That(token.Col, Is.EqualTo(7));
lexer = new Scanner("\n\n// ...//\n// ... \n\n/* ... */ foo");
Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("foo"));
}
示例5: Identifiers
public void Identifiers()
{
var lexer = new Scanner("42foo");
Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("42"));
Token next = lexer.NextToken();
Assert.That(next, Is.InstanceOf<Identifier>());
Assert.That(((Identifier) next).Value, Is.EqualTo("foo"));
lexer = new Scanner("f_o12a");
Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("f_o12a"));
}
示例6: DoubleDots
public void DoubleDots()
{
var lexer = new Scanner("..");
Assert.That(lexer.NextToken(), Is.InstanceOf<RangeOperator>());
lexer = new Scanner(".");
Assert.Throws<LexicalError>(() => lexer.NextToken());
Assert.That(lexer.Col, Is.EqualTo(1));
}
示例7: CombinedWhiteSpaceAndComments
public void CombinedWhiteSpaceAndComments()
{
var lexer = new Scanner("\n\t\t// ... \n // ... \n foo");
Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("foo"));
}
示例8: UnaryNot
public void UnaryNot()
{
var lexer = new Scanner("!");
Assert.That(lexer.NextToken(), Is.InstanceOf<UnaryNotToken>());
}
示例9: WhiteSpaceIsSkipped
public void WhiteSpaceIsSkipped()
{
var lexer = new Scanner("\n\t\v\n foo");
Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("foo"));
}
示例10: BinaryOperators
public void BinaryOperators(string binop)
{
var lexer = new Scanner(binop);
Token token = lexer.NextToken();
Assert.That(token, Is.InstanceOf<BinaryOperator>());
Assert.That(((BinaryOperator)token).Value, Is.EqualTo(binop));
}
示例11: StringLiterals
public void StringLiterals()
{
var lexer = new Scanner("\"foo 42\"");
Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo 42"));
Assert.That(lexer.NextToken(), Is.InstanceOf<EOF>());
lexer = new Scanner("\"foo\\n\"");
Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo\n"));
lexer = new Scanner("\"foo\\\"...\\\"\"");
Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo\"...\""));
lexer = new Scanner("\"foo\\\"");
Assert.Throws<LexicalError>(() => lexer.NextToken());
lexer = new Scanner("\"foo\\");
Assert.Throws<LexicalError>(() => lexer.NextToken());
}
示例12: Statement
public void Statement()
{
var lexer = new Scanner("var x : int := 4 + (2 * \"foo\");");
Assert.That(((KeywordToken) lexer.NextToken()).Value, Is.EqualTo("var"));
Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("x"));
Assert.That(lexer.NextToken(), Is.InstanceOf<TypeDeclaration>());
Assert.That(((KeywordToken) lexer.NextToken()).Value, Is.EqualTo("int"));
Assert.That(lexer.NextToken(), Is.InstanceOf<AssignmentToken>());
Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("4"));
Assert.That(((BinaryOperator) lexer.NextToken()).Value, Is.EqualTo("+"));
Assert.That(lexer.NextToken(), Is.InstanceOf<LeftParenthesis>());
Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("2"));
Assert.That(((BinaryOperator) lexer.NextToken()).Value, Is.EqualTo("*"));
Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo"));
Assert.That(lexer.NextToken(), Is.InstanceOf<RightParenthesis>());
Assert.That(lexer.NextToken(), Is.InstanceOf<EndLine>());
}
示例13: ShouldBeInvalid
public void ShouldBeInvalid()
{
var lexer = new Scanner("$");
Assert.Throws<LexicalError>(() => lexer.NextToken());
Assert.That(lexer.Col, Is.EqualTo(1));
}
示例14: IntegerConstants
public void IntegerConstants()
{
var lexer = new Scanner("123");
Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("123"));
Assert.That(lexer.NextToken(), Is.InstanceOf<EOF>());
lexer = new Scanner("1 23");
var token = (IntegerLiteralToken) lexer.NextToken();
Assert.That(token.Value, Is.EqualTo("1"));
Assert.That(token.Row, Is.EqualTo(1));
Assert.That(token.Col, Is.EqualTo(1));
Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("23"));
}
示例15: InputConsistingOfWhitespaceOnly
public void InputConsistingOfWhitespaceOnly()
{
var lexer = new Scanner("\n ");
Assert.That(lexer.NextToken(), Is.InstanceOf<EOF>());
}