本文整理汇总了C#中Lexer.Lexer类的典型用法代码示例。如果您正苦于以下问题:C# Lexer类的具体用法?C# Lexer怎么用?C# Lexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Lexer类属于Lexer命名空间,在下文中一共展示了Lexer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 );
}
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:35,代码来源:LexerTest.cs
示例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();
}
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:26,代码来源:Parser.cs
示例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 );
}
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:10,代码来源:LexerTest.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseFieldOptionTests.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseExtendTests.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseExtendTests.cs
示例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);
}
开发者ID:TruDan,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseMessageTest.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseMessageExtensionsTests.cs
示例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);
}
开发者ID:TruDan,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseMessageTest.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseMessageFieldTest.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseMessageFieldTest.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:12,代码来源:ParseOptionTest.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:14,代码来源:ParseFieldOptionsTests.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:16,代码来源:ParseFieldOptionTests.cs
示例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);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:19,代码来源:ParsePackageTests.cs
示例16: Package_NOK02
public void Package_NOK02()
{
const string text = " package Teäst1.kjhkj.jjjj;";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
lex.ParsePackage();
Assert.AreEqual(4, 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(12, lex.Errors[0].Position);
Assert.AreEqual(6, lex.Errors[0].Length);
Assert.AreEqual(0, lex.Line);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:19,代码来源:ParsePackageTests.cs
示例17: Import_NOK2
public void Import_NOK2()
{
const string text = " import \"blah fasel\"";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
lex.ParseImport();
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(2, lex.Tokens[0].Position);
Assert.AreEqual(6, lex.Tokens[0].Length);
Assert.AreEqual(CodeType.TopLevelCmd, lex.Tokens[0].CodeType);
Assert.AreEqual(0, lex.Line);
Assert.AreEqual(9, lex.Tokens[1].Position);
Assert.AreEqual(12, lex.Tokens[1].Length);
Assert.AreEqual(CodeType.String, lex.Tokens[1].CodeType);
Assert.AreEqual(0, lex.Line);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:19,代码来源:ParseImportTest.cs
示例18: Default_NOK03
public void Default_NOK03()
{
const string text = "default=-1234a]";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
var field = new Field { FieldType = FieldType.TypeString, HasOption = false };
Assert.IsFalse(lex.ParseDefault(field));
Assert.AreEqual(1, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(0, lex.Tokens[0].Position);
Assert.AreEqual(7, lex.Tokens[0].Length);
Assert.AreEqual(CodeType.Keyword, lex.Tokens[0].CodeType);
Assert.AreEqual(8, lex.Errors[0].Position);
Assert.AreEqual(6, lex.Errors[0].Length);
Assert.AreEqual(CodeType.Text, lex.Errors[0].CodeType);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:19,代码来源:ParseDefaultTests.cs
示例19: TestScanFloatNum
public void TestScanFloatNum()
{
var lex = new Lexer.Lexer();
var reader = new StringReader( "2. 3.14 .5" );
var t = lex.Scan( reader );
Assert.AreEqual( typeof (Float), t.GetType() );
Assert.AreEqual( 2.0, ( (Float) t ).Value );
t = lex.Scan( reader );
Assert.AreEqual( typeof (Float), t.GetType() );
Assert.AreEqual( 3.14, ( (Float) t ).Value );
t = lex.Scan( reader );
Assert.AreEqual( typeof (Float), t.GetType() );
Assert.AreEqual( 0.5, ( (Float) t ).Value );
}
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:20,代码来源:LexerTest.cs
示例20: Default_NOK02
public void Default_NOK02()
{
const string text = "default=\"-1234a\"]";
var lex = new Lexer(text) { Matches = Helper.SplitText(text) };
var field = new Field { FieldType = FieldType.TypeInt32, HasOption = false };
Assert.IsTrue(lex.ParseDefault(field));
Assert.AreEqual(2, lex.Tokens.Count);
Assert.AreEqual(1, lex.Errors.Count);
Assert.AreEqual(0, lex.Tokens[0].Position);
Assert.AreEqual(7, lex.Tokens[0].Length);
Assert.AreEqual(CodeType.Keyword, lex.Tokens[0].CodeType);
Assert.AreEqual(0, lex.Line);
Assert.AreEqual(8, lex.Tokens[1].Position);
Assert.AreEqual(1, lex.Tokens[1].Length);
Assert.AreEqual(CodeType.Number, lex.Tokens[1].CodeType);
Assert.AreEqual(0, lex.Line);
}
开发者ID:mreu,项目名称:ProtobufLanguageService,代码行数:21,代码来源:ParseDefaultTests.cs
注:本文中的Lexer.Lexer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论