本文整理汇总了C#中Lexer.Lexer类的典型用法代码示例。如果您正苦于以下问题:C# Lexer类的具体用法?C# Lexer怎么用?C# Lexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Lexer类属于Lexer命名空间,在下文中一共展示了Lexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestScanCompare
public void TestScanCompare()
{
var lex = new Lexer.Lexer();
var reader = new StringReader( " < <= == != >= >" );
var t = lex.Scan( reader );
Assert.AreEqual( typeof( Word), t.GetType() );
Assert.AreEqual( Tag.Less, t.Tag );
t = lex.Scan( reader );
Assert.AreEqual( typeof( Word ), t.GetType() );
Assert.AreEqual( Tag.LessOrEqual, t.Tag );
t = lex.Scan( reader );
Assert.AreEqual( typeof( Word ), t.GetType() );
Assert.AreEqual( Tag.Equal, t.Tag );
t = lex.Scan( reader );
Assert.AreEqual( typeof( Word ), t.GetType() );
Assert.AreEqual( Tag.NotEqual, t.Tag );
t = lex.Scan( reader );
Assert.AreEqual( typeof( Word ), t.GetType() );
Assert.AreEqual( Tag.BetterOrEqual, t.Tag );
t = lex.Scan( reader );
Assert.AreEqual( typeof( Word ), t.GetType() );
Assert.AreEqual( Tag.Better, t.Tag );
}
示例2: Parse
public Expression Parse(string fileData)
{
// First round to construct the label table
Lexer lexer = new Lexer(fileData);
var output = ParseExpression(lexer);
return output;
//while (lexer.HasNext())
//{
// //ParseInstruction(lexer, true);
//}
//// reset the stuff after the first go round that found the label locations
//Kernel = new List<uint>(KERNEL_SIZE);
//for (int i = 0; i < KERNEL_SIZE; i++) { Kernel.Add(0); }
//lexer = new Lexer.Lexer(fileData);
//KernelIndex = 0;
//LineNumber = 1;
//while (lexer.HasNext())
//{
// //ParseInstruction(lexer, false);
//}
//return Kernel.ToArray();
}
示例3: TestScanComment
public void TestScanComment()
{
var lex = new Lexer.Lexer();
var reader = new StringReader( "// Comment\n" );
var t = lex.Scan( reader );
Assert.AreEqual( typeof (Comment), t.GetType() );
Assert.AreEqual( " Comment", ( (Comment) t ).Value );
}
示例4: ParseFiledOption_NOK04
public void ParseFiledOption_NOK04()
{
const string text = " cpp=\r\n"; // incomplete statement
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseFieldOption());
Assert.AreEqual(1, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(3, lex.Index);
}
示例5: ParseExtend_NOK04
public void ParseExtend_NOK04()
{
const string text = " extend Foo x\r\n optional int32 bar = 126;\r\n }";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseExtend());
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(2, lex.Index);
}
示例6: ParseExtend_NOK05
public void ParseExtend_NOK05()
{
const string text = " extend Foo {";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseExtend());
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(3, lex.Index);
}
示例7: ParseMessage_NOK05
public void ParseMessage_NOK05()
{
const string text = " message SearchResponse x\r\n required string url = 2;\r\n optional string title = 3;\r\n repeated string snippets = 4;";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseMessage(false));
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(2, lex.Index);
}
示例8: MessageField_NOK05
public void MessageField_NOK05()
{
const string text = " extensions "; // incomplete statement
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseMessageExtensions());
Assert.AreEqual(1, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(1, lex.Index);
}
示例9: ParseMessage_NOK04
public void ParseMessage_NOK04()
{
const string text = " message SearchResponse";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseMessage(false));
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(2, lex.Index);
}
示例10: MessageField_NOK05
public void MessageField_NOK05()
{
const string text = " option"; // statement not finished
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseMessageField());
Assert.AreEqual(0, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(1, lex.Index);
}
示例11: MessageField_NOK02
public void MessageField_NOK02()
{
const string text = " optional string test1 ;"; // = + number is missing
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseMessageField());
Assert.AreEqual(3, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(3, lex.Index);
}
示例12: ParseEnum_NOK05
public void ParseEnum_NOK05()
{
const string text = " option java_package\r\n";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseOption(true));
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(3, lex.Index);
}
示例13: ParseFieldOptions_NOK04
public void ParseFieldOptions_NOK04()
{
const string text = " [default = 123";
var field = new Field { FieldType = FieldType.TypeInt32, HasOption = false };
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseFieldOptions(field));
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(4, lex.Index);
}
示例14: ParseFiledOption_NOK02
public void ParseFiledOption_NOK02()
{
const string text = " aaa"; // incomplete statement
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
Assert.IsFalse(lex.ParseFieldOption());
Assert.AreEqual(1, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(1, lex.Index);
Assert.AreEqual(2, lex.Tokens[0].Position);
Assert.AreEqual(3, lex.Tokens[0].Length);
Assert.AreEqual(CodeType.Keyword, lex.Tokens[0].CodeType);
}
示例15: Package_NOK03
public void Package_NOK03()
{
const string text = " package"; // still not finished line
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
lex.ParsePackage();
Assert.AreEqual(1, lex.Tokens.Count);
Assert.AreEqual(4, lex.Tokens[0].Position);
Assert.AreEqual(7, lex.Tokens[0].Length);
Assert.AreEqual(CodeType.TopLevelCmd, lex.Tokens[0].CodeType);
Assert.AreEqual(0, lex.Line);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(11, lex.Errors[0].Position);
Assert.AreEqual(1, lex.Errors[0].Length);
Assert.AreEqual(0, lex.Line);
}