本文整理汇总了C#中Lexer.Next方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.Next方法的具体用法?C# Lexer.Next怎么用?C# Lexer.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer.Next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldRecognizeNumbers
public void ShouldRecognizeNumbers()
{
var lexer = new Lexer("1 2.3 4.56789");
AssertTokenIs("number", 1, lexer.Next());
AssertTokenIs("number", 2.3, lexer.Next());
AssertTokenIs("number", 4.56789, lexer.Next());
}
示例2: ShouldDistinguishTwoDigitOperatorsStartingWithSameChar
public void ShouldDistinguishTwoDigitOperatorsStartingWithSameChar()
{
var lexer = new Lexer("= ==");
AssertTokenIs("=", lexer.Next());
AssertTokenIs("==", lexer.Next());
AssertTokenIs("EOF", lexer.Next());
}
示例3: ShouldRecordPositionOfTokens
public void ShouldRecordPositionOfTokens()
{
var lexer = new Lexer("one\ntwo\nthree");
Assert.AreEqual(1, lexer.Next().LineNo);
Assert.AreEqual(2, lexer.Next().LineNo);
Assert.AreEqual(3, lexer.Next().LineNo);
}
示例4: Lexer_CanIdentifyNumberTokens
public void Lexer_CanIdentifyNumberTokens(string input, double expectedValue)
{
var lexer = new Lexer(input);
Assert.IsTrue(lexer.Next());
Assert.AreEqual(TokenType.Number, lexer.CurrentToken.Type);
Assert.AreEqual(expectedValue, (double)(Number)lexer.CurrentToken.Value);
}
示例5: ShouldReportErrorForUnclosedString
public void ShouldReportErrorForUnclosedString()
{
var lexer = new Lexer("\"the cow said \\\"moo\\\"");
AssertTokenIs("string", "the cow said \"moo\"", lexer.Next());
Assert.AreEqual(lexer.Errors.Count, 1);
Assert.AreEqual("String not closed - Unexpected end of file", lexer.Errors[0].Message);
}
示例6: Lexer_CanTrackLineAndColumn
public void Lexer_CanTrackLineAndColumn(string input, int expectedLine, int expectedColumn, double expectedValue)
{
var lexer = new Lexer(input);
Assert.IsTrue(lexer.Next());
Assert.AreEqual(TokenType.Number, lexer.CurrentToken.Type);
Assert.AreEqual(expectedValue, (double)(Number)lexer.CurrentToken.Value);
Assert.AreEqual(expectedLine, lexer.Line);
Assert.AreEqual(expectedColumn, lexer.Column);
}
示例7: Poly
public Poly(string p)
{
a = new int[size, size];
Lexer l = new Lexer(p);
Lexer.Token curr = l.Next();
while (curr.t != Lexer.Type.EOF)
{
int m = 1;
if (curr.t == Lexer.Type.minus)
{
m = -1;
curr = l.Next();
}
if (curr.t == Lexer.Type.plus)
curr = l.Next();
int num = 0;
if (curr.t == Lexer.Type.a)
{
num = curr.value * m;
curr = l.Next();
}
else
num = m;
int px = 0;
int py = 0;
if (curr.t == Lexer.Type.x)
{
curr = l.Next();
if (curr.t == Lexer.Type.power)
{
px = curr.value;
curr = l.Next();
}
else
px = 1;
//curr = l.Next();
}
if (curr.t == Lexer.Type.y)
{
curr = l.Next();
if (curr.t == Lexer.Type.power)
{
py = curr.value;
curr = l.Next();
}
else
py = 1;
}
a[px, py] += num;
}
}
示例8: CompileGreeter
public void CompileGreeter()
{
Lexer lexer = new Lexer(@"
PRINT ""Enter your name: ""
name = INPUT()
PRINT ""Hello, "" + name + ""!""
");
CodeCompileUnit ccu = new CodeCompileUnit();
CodeNamespace samples = new CodeNamespace("Samples");
samples.Imports.Add(new CodeNamespaceImport("System"));
CodeTypeDeclaration targetClass = new CodeTypeDeclaration("CreatedClass");
targetClass.IsClass = true;
targetClass.TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed;
CodeEntryPointMethod start = new CodeEntryPointMethod();
targetClass.Members.Add(start);
var token = lexer.Next();
if (token is SubCallToken)
{
SubCallToken subCallToken = (SubCallToken) token;
if (subCallToken.Name == "PRINT")
{
CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("Console"),
"WriteLine",
subCallToken.Arguments.Select(ConvertSubCallArgument).ToArray());
start.Statements.Add(cs1);
}
}
samples.Types.Add(targetClass);
ccu.Namespaces.Add(samples);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CodeGeneratorOptions options = new CodeGeneratorOptions();
options.BracingStyle = "C";
StringWriter writer = new StringWriter();
provider.GenerateCodeFromCompileUnit(ccu, writer, options);
string result = writer.ToString();
Console.WriteLine(result);
//StringAssert.Contains(@"Console.WriteLine(""Enter your name: "");", result);
var compileResults = provider.CompileAssemblyFromDom(new CompilerParameters(), ccu);
Assert.IsNotNull(compileResults);
Assert.AreEqual(0, compileResults.Errors.Count);
Console.WriteLine(compileResults.PathToAssembly);
}
示例9: Assert
private static void Assert(string text, string expected)
{
Lexer lexer = new Lexer(text);
var tokens = new List<string>();
Token token;
while ((token = lexer.Next()).TokenType != TokenType.EndOfFile)
{
tokens.Add(token.TokenType + (String.IsNullOrEmpty(token.Text) ? "" : ":" + token.Text));
}
string actual = String.Join("|", tokens);
NUnit.Framework.Assert.That(actual, Is.EqualTo(expected));
}
示例10: Test
public void Test()
{
var text = "abc{def}";
var lexer = new Lexer();
lexer.Init(text);
Token<TokenType> token;
string actual = null;
while ((token = lexer.Next()).TokenType != TokenType.EndOfFile)
{
actual += Environment.NewLine + token.TokenType + " : " + token.Text;
}
var parser = new Parser();
var node = parser.Parse(text);
}
示例11: Run
private void Run(string text, string expected)
{
Lexer testLexer = new Lexer();
testLexer.Init(text);
List<Token<TokenType>> tokens = new List<Token<TokenType>>();
Token<TokenType> token;
while ((token = testLexer.Next()).TokenType != TokenType.EndOfFile)
{
tokens.Add(token);
}
string actual = Environment.NewLine + Join(Environment.NewLine, tokens.Select(x => x.TokenType + (x.Text == "" ? "" : " - " + x.Text)));
Assert.That(actual, Is.EqualTo(expected));
}
示例12: Match
public override bool Match(Lexer lexer, out State result)
{
if (!lexer.IsNummeric)
{
result = new State();
return false;
}
int startPos = lexer.Pos;
while (lexer.Next())
{
if (!(lexer.IsNummeric || lexer.Current == '.'))
break;
}
result = new State(Type, startPos, lexer.Pos - startPos);
return true;
}
示例13: Input
public void Input()
{
Lexer lexer = new Lexer("name = INPUT()");
Token result = lexer.Next();
Assert.AreEqual(new AssignmentToken(new NameToken("name"), new FunctionCallToken("INPUT")), result);
}
示例14: ShouldSplitOperators_WithWhitespace
public void ShouldSplitOperators_WithWhitespace()
{
var lexer = new Lexer("+/=");
AssertTokenIs("+", lexer.Next());
AssertTokenIs("/", lexer.Next());
AssertTokenIs("=", lexer.Next());
AssertTokenIs("EOF", lexer.Next());
}
示例15: Lexer_CanIdentifyOperatorTokens
public void Lexer_CanIdentifyOperatorTokens(string input, TokenType expectedType)
{
var lexer = new Lexer(input);
Assert.IsTrue(lexer.Next());
Assert.AreEqual(expectedType, lexer.CurrentToken.Type);
}