internal bool Init(string dslFile) { m_DslFile = dslFile; try { DslFile file = new DslFile(); if (!file.Load(dslFile, LogSystem.Log)) { LogSystem.Error("DSL {0} load failed !", dslFile); return false; } bool haveError = false; foreach (DslInfo info in file.DslInfos) { if (info.GetId() == "explanationfile") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; CallData call = funcData.Call; if (null != call && call.GetParamNum() >= 1) { string commentFile = call.GetParamId(0); string path = Path.Combine(Path.GetDirectoryName(m_DslFile), commentFile); try { string[] lines = File.ReadAllLines(path); m_Explanation.AddRange(lines); } catch(Exception fileEx) { LogSystem.Error("File.ReadAllLines({0}) throw exception {1}, line {2} file {3}", fileEx.Message, path, info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("explanationfile must have param file , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("explanationfile must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "explanation") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; CallData call = funcData.Call; if (null != call && call.GetParamNum() >= 1) { string line = call.GetParamId(0); m_Explanation.Add(line); } else { LogSystem.Error("explanation must have param explanation , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("explanation must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "version") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; CallData call = funcData.Call; if (null != call && call.GetParamNum() >= 1) { m_Version = call.GetParamId(0); } else { LogSystem.Error("version must have param version , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("version must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "package") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; CallData call = funcData.Call; if (null != call && call.GetParamNum() >= 1) { m_Package = call.GetParamId(0); } else { LogSystem.Error("package must have param package , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("package must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "defaultsize") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; CallData call = funcData.Call; if (null != call && call.GetParamNum() >= 1) { m_DefVarcharSize = int.Parse(call.GetParamId(0)); } else { LogSystem.Error("defaultsize must have param size , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("defaultsize must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "import") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; CallData call = funcData.Call; if (null != call && call.GetParamNum() >= 1) { string importDslFile = call.GetParamId(0); if (string.IsNullOrEmpty(importDslFile)) { LogSystem.Error("import must have param dslfile, line {0} file {1}", info.GetLine(), dslFile); haveError = true; } else { string filePath = Path.Combine(Path.GetDirectoryName(dslFile), importDslFile); MessageDslParser parser = new MessageDslParser(); if (parser.Init(filePath)) { if (m_Explanation.Count <= 0 && parser.m_Explanation.Count > 0) { m_Explanation.AddRange(parser.m_Explanation); } if (string.IsNullOrEmpty(m_Version) && !string.IsNullOrEmpty(parser.m_Version)) { m_Version = parser.m_Version; } if (string.IsNullOrEmpty(m_Package) && !string.IsNullOrEmpty(parser.m_Package)) { m_Package = parser.m_Package; } if (m_DefVarcharSize == c_DefVarcharSize && parser.m_DefVarcharSize != c_DefVarcharSize) { m_DefVarcharSize = parser.m_DefVarcharSize; } foreach (var pair in parser.m_TypeConverters) { m_TypeConverters.Add(pair.Key, pair.Value); } foreach (var pair in parser.m_EnumTypes) { m_EnumTypes.Add(pair.Key, pair.Value); } foreach (var pair in parser.m_Messages) { m_Messages.Add(pair.Key, pair.Value); } foreach (string name in parser.m_SortedMessageEnums) { m_SortedMessageEnums.Add(name); } } } } } else { LogSystem.Error("import must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "typeconverter") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; if (null != funcData) { CallData callData = funcData.Call; if (null != callData && callData.GetParamNum() >= 1) { string logicTypeName = callData.GetParamId(0); TypeConverterDef typeConverter = new TypeConverterDef(); typeConverter.m_LogicType = logicTypeName; typeConverter.m_IsSpecial = false; if (m_TypeConverters.ContainsKey(logicTypeName)) { m_TypeConverters[logicTypeName] = typeConverter; } else { m_TypeConverters.Add(logicTypeName, typeConverter); } foreach (ISyntaxComponent comp in funcData.Statements) { FunctionData item = comp as FunctionData; if (null != item) { if (item.HaveExternScript()) { if (item.GetId() == "message2logic") { typeConverter.m_Message2LogicCode = item.GetExternScript(); } else if (item.GetId() == "logic2message") { typeConverter.m_Logic2MessageCode = item.GetExternScript(); } else if (item.GetId() == "crudcode") { typeConverter.m_IsSpecial = true; typeConverter.m_CrudCode = item.GetExternScript(); } } else { LogSystem.Error("typeconverter {0} member must contains code ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } } else { CallData converterData = comp as CallData; if (null != converterData && converterData.GetParamNum() == 1) { string id = converterData.GetId(); string param = converterData.GetParamId(0); if (id == "messagetype") { typeConverter.m_MessageType = param; } } else { if (comp is ValueData || null != converterData) { LogSystem.Error("typeconverter {0} member must have params ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } else { LogSystem.Error("typeconverter {0} member must end with ';' ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } } } } if (string.IsNullOrEmpty(typeConverter.m_LogicType) || string.IsNullOrEmpty(typeConverter.m_MessageType) || string.IsNullOrEmpty(typeConverter.m_Message2LogicCode) || string.IsNullOrEmpty(typeConverter.m_Logic2MessageCode)) { LogSystem.Error("typeconverter {0} error, logictype or messagetype or message2logic or logic2message is null or empty ! line {1} file {2}", funcData.ToScriptString(), funcData.GetLine(), dslFile); haveError = true; } if (typeConverter.m_IsSpecial && string.IsNullOrEmpty(typeConverter.m_CrudCode)) { LogSystem.Error("typeconverter {0} error, special type must have crudcode ! line {1} file {2}", funcData.ToScriptString(), funcData.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("typeconverter {0} must have 1 params ! line {1} file {2}", funcData.ToScriptString(), funcData.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("typeconverter {0} must have function body ! line {1} file {2}", info.ToScriptString(), info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("typeconverter {0} must end with ';' ! line {1} file {2}", info.ToScriptString(), info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "enum") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; ParseEnum(dslFile, funcData, string.Empty, m_EnumTypes, ref haveError); } else { LogSystem.Error("enum must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else if (info.GetId() == "message") { if (info.Functions.Count == 1) { FunctionData funcData = info.First; string typeName = ParseMessage(dslFile, funcData, string.Empty, false, m_Messages, ref haveError); if (!string.IsNullOrEmpty(typeName) && !haveError) { m_SortedMessageEnums.Add(typeName); } } else { LogSystem.Error("message must end with ';' , line {0} file {1}", info.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("Unknown part {0}, line {1} file {2}", info.GetId(), info.GetLine(), dslFile); haveError = true; } } return !haveError; } catch (Exception ex) { Console.WriteLine(ex); } return false; }
private static void GenServerData() { MessageDslParser parser = new MessageDslParser(); parser.Init("DataProto/Data.dsl"); parser.GenAllMessageWraps("DataProto/Data.cs", string.Empty); parser.GenAllMessagesEnum("DataProto/DataEnum.cs", "DataEnum", string.Empty); parser.GenAllMessageProtos("DataProto/Data.proto", string.Empty); parser.GenAllMessageDDL("DataProto/CreateDataTables.sql", string.Empty); parser.GenAllMessageDML("DataProto/DataDML.cs", "DataEnum", string.Empty); }
private static void GenDataMessage() { MessageDslParser parser = new MessageDslParser(); parser.Init("ProtoFiles/DataMessageDefine.dsl"); parser.GenAllMessagesEnum("ProtoFiles/DataMessageDefineEnum.cs", "DataMessageEnum", string.Empty); parser.GenAllMessageProtos("ProtoFiles/DataMessageDefine.proto", string.Empty); }
private static void GenClientRoomMessage() { MessageDslParser parser = new MessageDslParser(); parser.Init("ProtoFiles/RoomMsg.dsl"); parser.GenAllMessagesEnum("ProtoFiles/RoomMsgEnum.cs", "RoomMessageDefine", string.Empty); parser.GenAllMessageProtos("ProtoFiles/RoomMsg.proto", string.Empty); }
private static void GenBillingMessage() { MessageDslParser parser = new MessageDslParser(); parser.Init("ProtoFiles/Billing.dsl"); parser.GenAllMessagesEnum("ProtoFiles/BillingEnum.cs", "BillingMessageEnum", string.Empty); parser.GenAllMessageProtos("ProtoFiles/Billing.proto", string.Empty); }
private static void GenBigwordMessage() { MessageDslParser parser = new MessageDslParser(); parser.Init("ProtoFiles/BigworldAndRoomServer.dsl"); parser.GenAllMessagesEnum("ProtoFiles/BigworldAndRoomServerMessageEnum.cs", "BigworldAndRoomServerMessageEnum", string.Empty); parser.GenAllMessageProtos("ProtoFiles/BigworldAndRoomServer.proto", string.Empty); }