//编译一个非类函数块 public static ICQ_Expression CompileParagraph(string text) { List <Token> tokens = TokenSpliter.SplitToken(text); PreCompiler.IdentifyType("", tokens); return(ExpressionCompiler.CompileParagraph(tokens)); }
public static void CompileProject(string[] filePaths) { Dictionary <string, IList <CQuark.Token> > project = new Dictionary <string, IList <CQuark.Token> >(); //分割Token,注册所有类 foreach (string filePath in filePaths) { //2.1 分割成Token(此时只有Keyword,Identifier,Punction) if (project.ContainsKey(filePath)) { continue; } string text = System.IO.File.ReadAllText(filePath); List <Token> tokens = TokenSpliter.SplitToken(text); project.Add(filePath, tokens); //2.2把所有代码里的类注册一遍 PreCompiler.RegisterCQClass(filePath, tokens); } //这一步必须在所有类型注册完后,因为编译会产生新的类 foreach (KeyValuePair <string, IList <Token> > f in project) { CompileOneFile(f.Key, f.Value); } }
//TODO 测试完后改成private public static void CompileOneFile(string fileName, IList <Token> tokens) { //到这里,所有会用到的类都注册过了,可以用AppDomain判断类了 //2.3 补足命名空间 DebugUtil.Log("File_CompilerToken:" + fileName); PreCompiler.IdentifyType(fileName, tokens); //2.3 编译成表达式 ExpressionCompiler.CompileClass(fileName, tokens); }
//编译单个文件 //如果调用这个函数,你必须确保在此之前已经注册了这个CQ需要引用的所有类 //除非你完全理解了这个函数的意思,否则请调用CompileProject // 这里的filename只是为了编译时报错可以看到出错文件 public static IList <Token> CompileOneFile(string fileName, string text) { //2.1 分割成Token List <Token> tokens = TokenSpliter.SplitToken(text); //2.2把所有代码里的类注册一遍 PreCompiler.RegisterCQClass(fileName, tokens); CompileOneFile(fileName, tokens); return(tokens); }
public static Expr PreCompileExpr(Expr input) { var result = PreCompiler.Compile(input); if (result.HasValue) { return(result.Value); } else { Console.WriteLine("Pre Compiler failed with error: " + result.Error); } return(null); }