private void DrawVal(string attrName, HowSimpleValueItem vali) { DrawIndentation(); paper.Write(attrName); paper.Write('='); DrawQuotContent(vali.Value); paper.Write(';'); DrawLine(); }
private void OutHSI() { var tHsi = hsiBuf; if (tHsi.Count == 3)//经典搭配 name="value"; { var eName = tHsi[0]; var eOp = tHsi[1]; var eVal = tHsi[2]; if (eName.type == Element.TPContent && !string.IsNullOrEmpty(eName.val.Trim()) && eOp.type == Element.TPOperator && eOp.val == "=" && eVal.type == Element.TPQuotationContent) { var resHsi = new HowSimpleValueItem(eVal.val); var key = eName.val.Trim(); if (hsoBuf.ContainsKey(key)) { var curItem = hsoBuf[key]; throw new HowSimpleObjectParsingException( string.Format("类型冲突:已有类别为{0}的变量\"{1}\",但是文档试图向其中以普通数据形式覆写数据\"{2}\",请检查数据文档的内容", curItem.ItemType.ToString(), curItem.Value, eVal)); } hsoBuf[key] = resHsi; hsiBuf.Clear(); return; } } if (tHsi.Count == 3)//数组 aryname+="value01"; { var eName = tHsi[0]; var eOp = tHsi[1]; var eVal = tHsi[2]; if (eName.type == Element.TPContent && !string.IsNullOrEmpty(eName.val.Trim()) && eOp.type == Element.TPOperator && eOp.val == "+=" && eVal.type == Element.TPQuotationContent) { var key = eName.val.Trim(); HowSimpleArrayItem ary; if (!hsoBuf.ContainsKey(key)) { hsoBuf[key] = new HowSimpleArrayItem(); } if (hsoBuf[key].ItemType != HowSimpleItemType.Ary) { var curItem = hsoBuf[key]; throw new HowSimpleObjectParsingException( string.Format("类型冲突:已有类别为{0}的变量\"{1}\",但是文档试图向其中以数组形式添加数据\"{2}\",请检查数据文档的内容", curItem.ItemType.ToString(), curItem.Value, eVal)); } ary = hsoBuf[key] as HowSimpleArrayItem; ary.Add(eVal.val); hsiBuf.Clear(); return; } } if (tHsi.Count == 5)//键值对 dictname+="value01" { var eName = tHsi[0]; var eOp1 = tHsi[1]; var eAttr = tHsi[2]; var eOp2 = tHsi[3]; var eVal = tHsi[4]; if ( eName.type == Element.TPContent && !string.IsNullOrEmpty(eName.val.Trim()) && eOp1.type == Element.TPOperator && eOp1.val == "." && eAttr.type == Element.TPContent && !string.IsNullOrEmpty(eAttr.val.Trim()) && eOp2.type == Element.TPOperator && eOp2.val == "=" && eVal.type == Element.TPQuotationContent ) { var pKey = eName.val.Trim(); var cKey = eAttr.val.Trim(); HowSimpleDictionaryItem dict; if (!hsoBuf.ContainsKey(pKey)) { hsoBuf[pKey] = new HowSimpleDictionaryItem(); } if (hsoBuf[pKey].ItemType != HowSimpleItemType.Dict) { var curItem = hsoBuf[pKey]; throw new HowSimpleObjectParsingException( string.Format("类型冲突:已有类别为{0}的变量\"{1}\",但是文档试图向其中以字典形式添加数据\"{2}\",请检查数据文档的内容", curItem.ItemType.ToString(), curItem.Value, eVal)); } dict = hsoBuf[pKey] as HowSimpleDictionaryItem; dict[cKey] = eVal.val; hsiBuf.Clear(); return; } } //非法组合 string combineStr = "<<"; for (int i = 0; i < tHsi.Count; i++) { combineStr += tHsi[i].ToString(); } combineStr += ">>"; throw new HowSimpleObjectParsingException("无效的组合:" + combineStr); }