From fa971c0e06b2b4b05dbf388bfbe70860e2657fe0 Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 25 Nov 2021 09:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96type=E7=9A=84=E5=B1=9E=E6=80=A7=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=AD=A3=E7=A1=AE=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E6=8B=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs | 9 +++++---- src/Luban.Job.Cfg/Source/Validators/PathValidator.cs | 3 ++- src/Luban.Job.Cfg/Source/Validators/RefValidator.cs | 4 +++- src/Luban.Job.Cfg/Source/Validators/SetValidator.cs | 3 ++- src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs | 4 ++-- src/Luban.Job.Common/Source/Utils/DefUtil.cs | 4 ++-- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs index 303ad0c..fbeec21 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs @@ -339,7 +339,7 @@ namespace Luban.Job.Cfg.Defs case "path": case "range": { - cf.Type = cf.Type + "&" + attrs[i]; + cf.Type = cf.Type + "&(" + attrs[i] + ")"; break; } case "group": @@ -665,16 +665,17 @@ namespace Luban.Job.Cfg.Defs { ValidAttrKeys(defineFile, e, _fieldOptionalAttrs, _fieldRequireAttrs); - string refStr = XmlUtil.GetOptionalAttribute(e, "ref"); string typeStr = XmlUtil.GetRequiredAttribute(e, "type"); + + string refStr = XmlUtil.GetOptionalAttribute(e, "ref"); if (!string.IsNullOrWhiteSpace(refStr)) { - typeStr = typeStr + "&ref=" + refStr; + typeStr = typeStr + "&(ref=" + refStr + ")"; } string pathStr = XmlUtil.GetOptionalAttribute(e, "path"); if (!string.IsNullOrWhiteSpace(pathStr)) { - typeStr = typeStr + "&path=" + pathStr; + typeStr = typeStr + "&(path=" + pathStr + ")"; } return CreateField(defineFile, XmlUtil.GetRequiredAttribute(e, "name"), diff --git a/src/Luban.Job.Cfg/Source/Validators/PathValidator.cs b/src/Luban.Job.Cfg/Source/Validators/PathValidator.cs index badbf0d..84a9167 100644 --- a/src/Luban.Job.Cfg/Source/Validators/PathValidator.cs +++ b/src/Luban.Job.Cfg/Source/Validators/PathValidator.cs @@ -2,6 +2,7 @@ using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.Defs; using Luban.Job.Common.Defs; using Luban.Job.Common.Types; +using Luban.Job.Common.Utils; using System; using System.Collections.Generic; using System.Text.RegularExpressions; @@ -163,7 +164,7 @@ namespace Luban.Job.Cfg.Validators public PathValidator(TType type, string pathPattern) { Type = type; - this.RawPattern = pathPattern; + this.RawPattern = DefUtil.TrimBracePairs(pathPattern); } public void Validate(ValidatorContext ctx, TType type, DType data) diff --git a/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs b/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs index b40e5e8..51edf62 100644 --- a/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs +++ b/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs @@ -1,8 +1,10 @@ using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.DataVisitors; using Luban.Job.Cfg.Defs; +using Luban.Job.Cfg.Utils; using Luban.Job.Common.Defs; using Luban.Job.Common.Types; +using Luban.Job.Common.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -31,7 +33,7 @@ namespace Luban.Job.Cfg.Validators public RefValidator(TType type, string tablesStr) { Type = type; - this.Tables = new List(tablesStr.Split(',')); + this.Tables = new List(DefUtil.TrimBracePairs(tablesStr).Split(',')); } public void Validate(ValidatorContext ctx, TType type, DType key) diff --git a/src/Luban.Job.Cfg/Source/Validators/SetValidator.cs b/src/Luban.Job.Cfg/Source/Validators/SetValidator.cs index bf84466..b4f4728 100644 --- a/src/Luban.Job.Cfg/Source/Validators/SetValidator.cs +++ b/src/Luban.Job.Cfg/Source/Validators/SetValidator.cs @@ -2,6 +2,7 @@ using Luban.Job.Cfg.Datas; using Luban.Job.Common.Defs; using Luban.Job.Common.Types; +using Luban.Job.Common.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -23,7 +24,7 @@ namespace Luban.Job.Cfg.Validators { _type = ttype; _datas = new HashSet(); - _valueSetStr = param; + _valueSetStr = DefUtil.TrimBracePairs(param); } public void Compile(DefFieldBase def) diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 9ad7906..57f1ddb 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -143,7 +143,7 @@ namespace Luban.Job.Common.Defs public TType CreateType(string module, string type) { - int sepIndex = DefUtil.IndexOfIncludeBrace(type, ','); + int sepIndex = DefUtil.IndexOfElementTypeSep(type); if (sepIndex > 0) { string containerTypeAndTags = DefUtil.TrimBracePairs(type.Substring(0, sepIndex)); @@ -232,7 +232,7 @@ namespace Luban.Job.Common.Defs protected TMap CreateMapType(string module, Dictionary tags, string keyValueType, bool isTreeMap) { - int typeSepIndex = DefUtil.IndexOfIncludeBrace(keyValueType, ','); + int typeSepIndex = DefUtil.IndexOfElementTypeSep(keyValueType); if (typeSepIndex <= 0 || typeSepIndex >= keyValueType.Length - 1) { throw new ArgumentException($"invalid map element type:'{keyValueType}'"); diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index ade78c7..62cbfd4 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -39,7 +39,7 @@ namespace Luban.Job.Common.Utils return am; } - public static int IndexOfIncludeBrace(string s, char sep) + public static int IndexOfElementTypeSep(string s) { int braceDepth = 0; for (int i = 0; i < s.Length; i++) @@ -54,7 +54,7 @@ namespace Luban.Job.Common.Utils --braceDepth; } - if (braceDepth == 0 && (c == sep)) + if (braceDepth == 0 && (c == ',' || c == ';')) { return i; }