【优化】优化容器类型的tag解析,终于可以正确区分容器自身及元素类型的tag定义
parent
18678059f4
commit
050fbc347e
|
|
@ -172,6 +172,7 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
{
|
{
|
||||||
fieldType.Apply(this, fieldValue);
|
fieldType.Apply(this, fieldValue);
|
||||||
}
|
}
|
||||||
|
_path.Pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,6 @@ namespace Luban.Job.Cfg.Utils
|
||||||
|
|
||||||
private static void CreateValidatorsForArrayLike(TType containerType, TType elementType)
|
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(elementType);
|
||||||
CreateValidatorsForType(containerType);
|
CreateValidatorsForType(containerType);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,10 @@ namespace Luban.Job.Common.Defs
|
||||||
int sepIndex = DefUtil.IndexOfIncludeBrace(type, ',');
|
int sepIndex = DefUtil.IndexOfIncludeBrace(type, ',');
|
||||||
if (sepIndex > 0)
|
if (sepIndex > 0)
|
||||||
{
|
{
|
||||||
var (containerAndElementType, tags) = DefUtil.ParseType(type);
|
string containerTypeAndTags = DefUtil.TrimBracePairs(type.Substring(0, sepIndex));
|
||||||
string containerType = containerAndElementType.Substring(0, sepIndex).Trim();
|
var elementTypeAndTags = type.Substring(sepIndex + 1);
|
||||||
return CreateContainerType(module, containerType, tags, containerAndElementType.Substring(sepIndex + 1, containerAndElementType.Length - sepIndex - 1).Trim());
|
var (containerType, containerTags) = DefUtil.ParseType(containerTypeAndTags);
|
||||||
|
return CreateContainerType(module, containerType, containerTags, elementTypeAndTags.Trim());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -146,17 +147,7 @@ namespace Luban.Job.Common.Defs
|
||||||
{
|
{
|
||||||
bool nullable;
|
bool nullable;
|
||||||
// 去掉 rawType 两侧的匹配的 ()
|
// 去掉 rawType 两侧的匹配的 ()
|
||||||
while (rawType.Length > 0 && rawType[0] == '(')
|
rawType = DefUtil.TrimBracePairs(rawType);
|
||||||
{
|
|
||||||
if (rawType[rawType.Length - 1] == ')')
|
|
||||||
{
|
|
||||||
rawType = rawType.Substring(1, rawType.Length - 2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"type:{rawType} brace not match");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var (type, tags) = DefUtil.ParseType(rawType);
|
var (type, tags) = DefUtil.ParseType(rawType);
|
||||||
|
|
||||||
#if !LUBAN_LITE
|
#if !LUBAN_LITE
|
||||||
|
|
@ -226,12 +217,14 @@ namespace Luban.Job.Common.Defs
|
||||||
|
|
||||||
protected TMap CreateMapType(string module, Dictionary<string, string> tags, string keyValueType, bool isTreeMap)
|
protected TMap CreateMapType(string module, Dictionary<string, string> tags, string keyValueType, bool isTreeMap)
|
||||||
{
|
{
|
||||||
string[] elementTypes = keyValueType.Split(',').Select(s => s.Trim()).ToArray();
|
int typeSepIndex = DefUtil.IndexOfIncludeBrace(keyValueType, ',');
|
||||||
if (elementTypes.Length != 2)
|
if (typeSepIndex <= 0 || typeSepIndex >= keyValueType.Length - 1)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"invalid map element type:'{keyValueType}'");
|
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<string, string> containerTags, string elementType)
|
protected TType CreateContainerType(string module, string containerType, Dictionary<string, string> containerTags, string elementType)
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,22 @@ namespace Luban.Job.Common.Utils
|
||||||
return -1;
|
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<string, string>) ParseType(string s)
|
public static (string, Dictionary<string, string>) ParseType(string s)
|
||||||
{
|
{
|
||||||
int sepIndex = s.IndexOfAny(s_attrSep);
|
int sepIndex = s.IndexOfAny(s_attrSep);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue