From 050fbc347e2c994d5489a1118862e1934354d03d Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 26 Oct 2021 09:41:18 +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=96=E5=AE=B9=E5=99=A8=E7=B1=BB=E5=9E=8B=E7=9A=84tag?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=EF=BC=8C=E7=BB=88=E4=BA=8E=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E5=8C=BA=E5=88=86=E5=AE=B9=E5=99=A8=E8=87=AA?= =?UTF-8?q?=E8=BA=AB=E5=8F=8A=E5=85=83=E7=B4=A0=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?tag=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataVisitors/ValidatorVisitor.cs | 1 + .../Source/Utils/ValidatorUtil.cs | 11 -------- .../Source/Defs/DefAssemblyBase.cs | 27 +++++++------------ src/Luban.Job.Common/Source/Utils/DefUtil.cs | 16 +++++++++++ 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs index e2a5d54..ea87b1c 100644 --- a/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs +++ b/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs @@ -172,6 +172,7 @@ namespace Luban.Job.Cfg.DataVisitors { fieldType.Apply(this, fieldValue); } + _path.Pop(); } } diff --git a/src/Luban.Job.Cfg/Source/Utils/ValidatorUtil.cs b/src/Luban.Job.Cfg/Source/Utils/ValidatorUtil.cs index 0d39a7b..0de9493 100644 --- a/src/Luban.Job.Cfg/Source/Utils/ValidatorUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/ValidatorUtil.cs @@ -25,17 +25,6 @@ namespace Luban.Job.Cfg.Utils private static void CreateValidatorsForArrayLike(TType containerType, TType elementType) { - if (containerType.Tags.TryGetValue("ref", out var refStr)) - { - elementType.Tags.Add("ref", refStr); - containerType.Tags.Remove("ref"); - } - if (containerType.Tags.TryGetValue("path", out var pathStr)) - { - elementType.Tags.Add("path", pathStr); - containerType.Tags.Remove("path"); - } - CreateValidatorsForType(elementType); CreateValidatorsForType(containerType); } diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index a816fd6..b17835d 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -132,9 +132,10 @@ namespace Luban.Job.Common.Defs int sepIndex = DefUtil.IndexOfIncludeBrace(type, ','); if (sepIndex > 0) { - var (containerAndElementType, tags) = DefUtil.ParseType(type); - string containerType = containerAndElementType.Substring(0, sepIndex).Trim(); - return CreateContainerType(module, containerType, tags, containerAndElementType.Substring(sepIndex + 1, containerAndElementType.Length - sepIndex - 1).Trim()); + string containerTypeAndTags = DefUtil.TrimBracePairs(type.Substring(0, sepIndex)); + var elementTypeAndTags = type.Substring(sepIndex + 1); + var (containerType, containerTags) = DefUtil.ParseType(containerTypeAndTags); + return CreateContainerType(module, containerType, containerTags, elementTypeAndTags.Trim()); } else { @@ -146,17 +147,7 @@ namespace Luban.Job.Common.Defs { bool nullable; // 去掉 rawType 两侧的匹配的 () - while (rawType.Length > 0 && rawType[0] == '(') - { - if (rawType[rawType.Length - 1] == ')') - { - rawType = rawType.Substring(1, rawType.Length - 2); - } - else - { - throw new Exception($"type:{rawType} brace not match"); - } - } + rawType = DefUtil.TrimBracePairs(rawType); var (type, tags) = DefUtil.ParseType(rawType); #if !LUBAN_LITE @@ -226,12 +217,14 @@ namespace Luban.Job.Common.Defs protected TMap CreateMapType(string module, Dictionary tags, string keyValueType, bool isTreeMap) { - string[] elementTypes = keyValueType.Split(',').Select(s => s.Trim()).ToArray(); - if (elementTypes.Length != 2) + int typeSepIndex = DefUtil.IndexOfIncludeBrace(keyValueType, ','); + if (typeSepIndex <= 0 || typeSepIndex >= keyValueType.Length - 1) { throw new ArgumentException($"invalid map element type:'{keyValueType}'"); } - return TMap.Create(false, tags, CreateNotContainerType(module, elementTypes[0]), CreateNotContainerType(module, elementTypes[1]), isTreeMap); + return TMap.Create(false, tags, + CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim()), + CreateNotContainerType(module, keyValueType.Substring(typeSepIndex + 1).Trim()), isTreeMap); } protected TType CreateContainerType(string module, string containerType, Dictionary containerTags, string elementType) diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index abff816..fd090dd 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -58,6 +58,22 @@ namespace Luban.Job.Common.Utils return -1; } + public static string TrimBracePairs(string rawType) + { + while (rawType.Length > 0 && rawType[0] == '(') + { + if (rawType[rawType.Length - 1] == ')') + { + rawType = rawType.Substring(1, rawType.Length - 2); + } + else + { + throw new Exception($"type:{rawType} brace not match"); + } + } + return rawType; + } + public static (string, Dictionary) ParseType(string s) { int sepIndex = s.IndexOfAny(s_attrSep);