Skip to content

Commit ba5f3d7

Browse files
authored
Merge pull request #507 from CactusPuppy/475-workshopsettingcombo-and-workshopsettinghero-only-accept-string-literals-for-category-and-name-arguments
475 workshopsettingcombo and workshopsettinghero only accept string literals for category and name arguments
2 parents 2cb84e3 + 4870321 commit ba5f3d7

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Deltinteger/Deltinteger/Parse/Parameters/AlternateParameterTypes.cs

+24-4
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,23 @@ public ConstStringParameter(string name, string documentation, ITypeSupplier typ
106106

107107
public override object Validate(ParseInfo parseInfo, IExpression value, DocRange valueRange, object additionalData)
108108
{
109-
StringAction str = value as StringAction;
110-
if (str == null && valueRange != null) parseInfo.Script.Diagnostics.Error("Expected string constant.", valueRange);
111-
return str?.Value;
109+
// ConstantExpressionResolver.Resolve's callback will be called after this function runs,
110+
// so we store the value in an object reference whose value will be set later.
111+
var promise = new ConstStringResolver();
112+
113+
// Resolve the expression.
114+
ConstantExpressionResolver.Resolve(value, expr =>
115+
{
116+
// If the resulting expression is a string,
117+
if (expr is StringAction stringAction)
118+
// Resolve the value.
119+
promise.Resolve(stringAction.Value);
120+
// Otherwise, add an error.
121+
else if (valueRange != null)
122+
parseInfo.Script.Diagnostics.Error("Expected string constant", valueRange);
123+
});
124+
125+
return promise?.Value;
112126
}
113127

114128
public override IWorkshopTree Parse(ActionSet actionSet, IExpression expression, object additionalParameterData) => null;
@@ -142,6 +156,12 @@ public override object Validate(ParseInfo parseInfo, IExpression value, DocRange
142156
public override IWorkshopTree Parse(ActionSet actionSet, IExpression expression, object additionalParameterData) => null;
143157
}
144158

159+
class ConstStringResolver
160+
{
161+
public string Value { get; private set; }
162+
public void Resolve(string value) => Value = value;
163+
}
164+
145165
class ConstHeroValueResolver
146166
{
147167
public string Hero { get; private set; }
@@ -352,4 +372,4 @@ public override object Validate(ParseInfo parseInfo, IExpression value, DocRange
352372
return GetFile(parseInfo, filepath, uri => new LoadedFile(uri)).GetContent();
353373
}
354374
}
355-
}
375+
}

0 commit comments

Comments
 (0)