static public void getAllChild(PBElement p) { foreach (PBElement chlidPBElement in p.child) { Debug.LogWarning("start ----------------------->>>>>>>>>>>>>>>>>>>>>"); Debug.LogWarning(chlidPBElement.code); Debug.LogWarning(chlidPBElement.log()); Debug.LogWarning("end ----------------------->>>>>>>>>>>>>>>>>>>>>"); getAllChild(chlidPBElement); } }
static public string toLuaMsgCheckResult(PBMessage pbMessage) { string checkResult = checkResultTp; string checkResultItem = ""; foreach (PBElement pElement in pbMessage.child) { if (pElement.pb_type != PBElement.type_PBAttribute) { continue; } PBAttribute attribute = (PBAttribute)pElement; if (attribute.name == "result") { PBElement pbEnum = pbMessage.getChildByName(attribute.type); if (pbEnum == null) { Debug.LogError("not find !!!! = > " + attribute.type); } else { /* * static public string checkResultItemTp = "\tif msg.result == $enumValue$ then\n"+ * "\t\twarn('$Notes$');\n"+ * "\tend\n"; */ foreach (PBElement pbKeyValue in pbEnum.child) { PBKeyValue keyValue = (PBKeyValue)pbKeyValue; checkResultItem += checkResultItemTp.Replace("$enumValue$", keyValue.value).Replace("$Notes$", keyValue.Notes); } } } } return(checkResult.Replace("$checkResultItem$", checkResultItem)); }
public void read() { List <CodeKeyword> codekeyStack = new List <CodeKeyword>(); List <CodeSymbol> symbolStack = new List <CodeSymbol>(); List <PBElement> elementStack = new List <PBElement>(); elementStack.Add(this); if (charArr == null) { charArr = code.ToCharArray(); } PBElement curPBElement = null; int startIndex = 0; for (int i = 0; i < code.Length; i++) { startIndex = i; CodeSymbol curSymbol = FindNextSymbol(code, startIndex); int Index = curSymbol.Index; if (Index > 0) { //跳过注释 if (curSymbol.Symbol == '/') { if (charArr [curSymbol.Index + 1] == '*') { while (Index < charArr.Length) { curSymbol = FindNextSymbol(code, Index + 1, '/'); Index = curSymbol.Index; if (Index == -1) { Debug.LogErrorFormat("{0} not find '/' end", name); return; } if (charArr [curSymbol.Index - 1] == '*') { break; } } i = Index; Debug.LogWarningFormat("{0} jump /**/ index {1} ", name, Index); continue; } } string key = code.Substring(startIndex, Index - startIndex); if (curPBElement != null && key.StartsWith("//")) { // curPBElement.Notes = key; } if (key == "") { } else { //关键字压入 codekeyStack.Add(new CodeKeyword(startIndex, key)); } if (key.Equals("import")) { //PBFile pbFile = new PBFile (); PBImportFile pushPBImportFile = new PBImportFile(); pushPBImportFile.startIndex = startIndex; elementStack.Add(pushPBImportFile); curPBElement = pushPBImportFile; } else if (key.Equals("package")) { PBPackage pushPBPackage = new PBPackage(); pushPBPackage.startIndex = startIndex; elementStack.Add(pushPBPackage); curPBElement = pushPBPackage; } else if (key.Equals("required") || key.Equals("optional") || key.Equals("repeated")) { PBAttribute pushPBAttribute = new PBAttribute(); pushPBAttribute.startIndex = startIndex; elementStack.Add(pushPBAttribute); curPBElement = pushPBAttribute; } else //enum压入 if (key == "enum") { PBEnum pushPBElement = new PBEnum(); pushPBElement.pbFile = this; pushPBElement.name = key; pushPBElement.startIndex = Index; elementStack.Add(pushPBElement); curPBElement = pushPBElement; } else //message压入 if (key == "message") { PBMessage pushPBMessage = new PBMessage(); pushPBMessage.pbFile = this; pushPBMessage.name = key; pushPBMessage.startIndex = Index; elementStack.Add(pushPBMessage); curPBElement = pushPBMessage; if (codekeyStack.Count >= 2 && codekeyStack[codekeyStack.Count - 2].value.StartsWith("//")) { pushPBMessage.Notes = codekeyStack[codekeyStack.Count - 2].value; } } /* * if(curSymbol.Symbol == '='){ * string pname = (string)codekeyStack[codekeyStack.Count-1]; * Debug.LogWarning(" >> pname :))))) --------> " + pname); * }else */ if (curSymbol.Symbol == '{') { CodeKeyword ptype = codekeyStack[codekeyStack.Count - 2]; CodeKeyword pname = codekeyStack[codekeyStack.Count - 1]; //Debug.LogWarning(" >> Index :))))) --------> " + pname.Index + ", >> pname :))))) --------> " + pname.value ); //压入符号栈 symbolStack.Add(curSymbol); } else if (curSymbol.Symbol == '}') { //块结束 CodeSymbol pushSymbol = symbolStack[symbolStack.Count - 1]; if (pushSymbol.Symbol == '{') { symbolStack.RemoveAt(symbolStack.Count - 1); //弹出符号栈 PBElement popUpPBElement = elementStack[elementStack.Count - 1]; popUpPBElement.endIndex = Index; popUpPBElement.cut(code); elementStack.RemoveAt(elementStack.Count - 1); if (elementStack.Count > 0) { elementStack[elementStack.Count - 1].addChild(popUpPBElement); } } else { Debug.LogError("Symbol Error { "); } } else if (curSymbol.Symbol == '[') { symbolStack.Add(curSymbol); PBKeyValue pushPBKeyValue = new PBKeyValue(); pushPBKeyValue.startIndex = Index; elementStack.Add(pushPBKeyValue); } else if (curSymbol.Symbol == ']') { CodeSymbol pushSymbol = symbolStack[symbolStack.Count - 1]; if (pushSymbol.Symbol == '[') { symbolStack.RemoveAt(symbolStack.Count - 1); //弹出 PBElement popUpPBElement = elementStack[elementStack.Count - 1]; popUpPBElement.endIndex = Index; popUpPBElement.cut(code); elementStack.RemoveAt(elementStack.Count - 1); if (elementStack.Count > 0) { elementStack[elementStack.Count - 1].addChild(popUpPBElement); } } else { Debug.LogError("Symbol Error [ "); } } else if (curSymbol.Symbol == ';') { //弹出 PBElement popUpPBElement = elementStack[elementStack.Count - 1]; if (popUpPBElement.pb_type == PBElement.type_PBPackage) { popUpPBElement.endIndex = Index; popUpPBElement.cut(code); this.package = (popUpPBElement as PBPackage).pbPackageName; elementStack.RemoveAt(elementStack.Count - 1); } else if (popUpPBElement.pb_type == PBElement.type_PBImportFile) { popUpPBElement.endIndex = Index; popUpPBElement.cut(code); PBFile pbFile = new PBFile(); pbFile.name = (popUpPBElement as PBImportFile).pbFilePath; pbFile.readFile(pbFile.name); pbFile.read(); PBFileImportDic.Add(pbFile.name, pbFile); elementStack.RemoveAt(elementStack.Count - 1); } else //枚举 属性 if (popUpPBElement.pb_type == PBElement.type_PBEnum) { PBKeyValue PBKeyValue = new PBKeyValue(); PBKeyValue.key = codekeyStack[codekeyStack.Count - 2].value; PBKeyValue.value = codekeyStack[codekeyStack.Count - 1].value; PBKeyValue.startIndex = codekeyStack[codekeyStack.Count - 2].Index; PBKeyValue.endIndex = Index; PBKeyValue.cut(code); popUpPBElement.addChild(PBKeyValue); curPBElement = PBKeyValue; codekeyStack.RemoveAt(codekeyStack.Count - 1); codekeyStack.RemoveAt(codekeyStack.Count - 1); CodeSymbol nextSymbol = FindNextSymbol(code, Index + 1); string nextKey = code.Substring(Index + 1, nextSymbol.Index - (Index + 1)); if (curPBElement != null && nextKey.StartsWith("//")) { curPBElement.Notes = nextKey; } } else //message 属性 if (popUpPBElement.pb_type == PBElement.type_PBAttribute) { popUpPBElement.endIndex = Index; popUpPBElement.cut(code); elementStack.RemoveAt(elementStack.Count - 1); curPBElement = popUpPBElement; if (elementStack.Count > 0) { elementStack[elementStack.Count - 1].addChild(popUpPBElement); } CodeSymbol nextSymbol = PBFile.FindNextSymbol(code, Index + 1); string nextKey = code.Substring(Index + 1, nextSymbol.Index - (Index + 1)); if (curPBElement != null && nextKey.StartsWith("//")) { curPBElement.Notes = nextKey; } } } } i = Index; } //getAllChild(this); }
public void addChild(PBElement element) { child.Add(element); }
public void addPBElementDic(string key, PBElement pbElement) { PBElementDic.Add(key, pbElement); }