Skip to content

Commit 467121e

Browse files
committed
prioritize matching data keys over script keys
1 parent 5997be6 commit 467121e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

SharpDenizenTools/ScriptAnalysis/ScriptChecker.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class ScriptChecker
4444
/// <summary>Keys that always mean a section is a script.</summary>
4545
public static string[] AlwaysScriptKeys = ["script", "scripts", "subscripts", "subtasks", "inject", "injects", "injectables", "subprocedures"];
4646

47+
/// <summary>Keys that always mean simple data.</summary>
48+
public static string[] AlwaysDataKeys = ["data", "description"];
49+
4750
/// <summary>A non-complete set of Denizen commands that can end with a colon and contain arguments, for checking certain syntax errors.</summary>
4851
public static HashSet<string> CommandsWithColonsAndArguments =
4952
[
@@ -1029,7 +1032,11 @@ void checkBasicList(List<object> list, bool canBeScript)
10291032
}
10301033
if (valueAtKey is List<object> listAtKey)
10311034
{
1032-
if (MatchesSet(keyName, script.KnownType.ScriptKeys) || MatchesSet(keyName, AlwaysScriptKeys))
1035+
if (MatchesSet(keyName, AlwaysDataKeys) || typeString.Text == "data")
1036+
{
1037+
checkBasicList(listAtKey, false);
1038+
}
1039+
else if (MatchesSet(keyName, script.KnownType.ScriptKeys) || MatchesSet(keyName, AlwaysScriptKeys))
10331040
{
10341041
checkAsScript(listAtKey);
10351042
}
@@ -1041,11 +1048,6 @@ void checkBasicList(List<object> list, bool canBeScript)
10411048
{
10421049
warnScript(Warnings, keyLine.Line, "list_should_be_value", $"Bad key `{keyName.Replace('`', '\'')}` (was expected to be a direct Value, but was instead a list - check `!lang {typeString.Text} script containers` for format rules)!");
10431050
}
1044-
else if (typeString.Text == "data" || keyName == "data" || keyName == "description")
1045-
{
1046-
// Always allow 'data'
1047-
checkBasicList(listAtKey, false);
1048-
}
10491051
else if (script.KnownType.Strict)
10501052
{
10511053
warnScript(Warnings, keyLine.Line, "unknown_key_" + typeString.Text, $"Unexpected list key `{keyName.Replace('`', '\'')}` (unrecognized - check `!lang {typeString.Text} script containers` for format rules)!");
@@ -1129,15 +1131,15 @@ void checkSubMaps(Dictionary<LineTrackedString, object> subMap, bool canBeScript
11291131
if (script.KnownType.ValueKeys.Contains(keyText) || script.KnownType.ListKeys.Contains(keyText) || script.KnownType.ScriptKeys.Contains(keyText) || AlwaysScriptKeys.Contains(keyName)
11301132
|| script.KnownType.ValueKeys.Contains("*") || script.KnownType.ListKeys.Contains("*") || script.KnownType.ScriptKeys.Contains("*"))
11311133
{
1132-
checkSubMaps(keyPairMap, typeString.Text != "data" && keyName != "data");
1134+
checkSubMaps(keyPairMap, typeString.Text != "data" && !MatchesSet(keyName, AlwaysDataKeys));
11331135
}
11341136
else if (script.KnownType.Strict && keyName != "data")
11351137
{
11361138
warnScript(Warnings, keyLine.Line, "unknown_key_" + typeString.Text, $"Unexpected submapping key `{keyName.Replace('`', '\'')}` (unrecognized - check `!lang {typeString.Text} script containers` for format rules)!");
11371139
}
11381140
else
11391141
{
1140-
checkSubMaps(keyPairMap, typeString.Text != "data" && !keyName.StartsWith("definemap") && keyName != "data");
1142+
checkSubMaps(keyPairMap, typeString.Text != "data" && !keyName.StartsWith("definemap") && !MatchesSet(keyName, AlwaysDataKeys));
11411143
}
11421144
}
11431145
}
@@ -1906,7 +1908,11 @@ void procAsScript(List<object> list)
19061908
}
19071909
if (valueAtKey is List<object> listAtKey)
19081910
{
1909-
if (MatchesSet(keyName, script.KnownType.ScriptKeys) || MatchesSet(keyName, AlwaysScriptKeys))
1911+
if (MatchesSet(keyName, AlwaysDataKeys))
1912+
{
1913+
// ignore
1914+
}
1915+
else if (MatchesSet(keyName, script.KnownType.ScriptKeys) || MatchesSet(keyName, AlwaysScriptKeys))
19101916
{
19111917
procAsScript(listAtKey);
19121918
}

0 commit comments

Comments
 (0)