private static void Project_Compile(Dictionary <string, IList <Token> > project, bool embDebugToken) { foreach (KeyValuePair <string, IList <Token> > f in project) { //先把所有代码里的类注册一遍 IList <IType> types = CQ_Expression_Compiler.FilePreCompile(f.Key, f.Value); foreach (var type in types) { RegisterType(type); } } foreach (KeyValuePair <string, IList <Token> > f in project) { //预处理符号 for (int i = 0; i < f.Value.Count; i++) { if (f.Value[i].type == TokenType.IDENTIFIER && CQ_TokenParser.ContainsType(f.Value[i].text)) //有可能预处理导致新的类型 { if (i > 0 && (f.Value[i - 1].type == TokenType.TYPE || f.Value[i - 1].text == ".")) { continue; } Token rp = f.Value[i]; rp.type = TokenType.TYPE; f.Value[i] = rp; } } File_CompileToken(f.Key, f.Value, embDebugToken); } }
public static void BuildProject(string path, string pattern) { string[] files = System.IO.Directory.GetFiles(path, pattern, System.IO.SearchOption.AllDirectories); Dictionary <string, IList <CQuark.Token> > project = new Dictionary <string, IList <CQuark.Token> >(); foreach (var file in files) { if (project.ContainsKey(file)) { continue; } string text = System.IO.File.ReadAllText(file); var tokens = CQ_TokenParser.Parse(text); project.Add(file, tokens); } Project_Compile(project, true); }
//把文本断成TokenList private static IList <Token> ParserToken(string code) { if (code[0] == 0xFEFF) { //windows下用记事本写,会在文本第一个字符出现BOM(65279) code = code.Substring(1); } IList <Token> tokens = CQ_TokenParser.Parse(code); if (tokens == null) { DebugUtil.LogWarning("没有解析到代码"); } return(tokens); }
public static void RegisterType(IType type) { types[type.typeBridge] = type; string typename = type.keyword; //if (useNamespace) //{ // if (string.IsNullOrEmpty(type._namespace) == false) // { // typename = type._namespace + "." + type.keyword; // } //} if (string.IsNullOrEmpty(typename)) //匿名自动注册 { } else { typess[typename] = type; CQ_TokenParser.AddType(typename); } }