@ -616,9 +616,10 @@ private final function bool ParseTextValue(
HashTable parsedParameters,
Command.Parameter expectedParameter)
{
local bool failedParsing;
local MutableText textValue;
local Parser.ParserState initialState;
local bool failedParsing;
local MutableText textValue;
local Parser.ParserState initialState;
local HashTable resolvedPair;
// (needs some work for reading formatting `string`s from `Text` objects)
initialState = commandParser.Skip().GetCurrentState();
@ -639,24 +640,35 @@ private final function bool ParseTextValue(
commandParser.Fail();
return false;
}
AutoResolveAlias(textValue, expectedParameter.aliasSourceName);
RecordParameter(parsedParameters, expectedParameter, textValue.IntoText());
resolvedPair = AutoResolveAlias(textValue, expectedParameter.aliasSourceName);
if (resolvedPair != none) {
RecordParameter(parsedParameters, expectedParameter, resolvedPair);
_.memory.Free(textValue);
} else {
RecordParameter(parsedParameters, expectedParameter, textValue.IntoText());
}
return true;
}
// Resolves alias with appropriate source, if parameter was specified to be
// auto-resolved.
// Resolved values is returned through first out-parameter.
private final function AutoResolveAlias(
out MutableText textValue,
Text aliasSourceName)
{
local Text resolvedValue;
// Resolves alias and returns it, along with the resolved value, if parameter was specified to be
// auto-resolved.
// Returns `none` otherwise.
private final function HashTable AutoResolveAlias(MutableText textValue, Text aliasSourceName) {
local HashTable result;
local Text resolvedValue, immutableValue;
if (textValue == none) return;
if (aliasSourceName == none) return;
if (!textValue.StartsWithS("$")) return;
if (textValue == none) return none;
if (aliasSourceName == none) return none;
// Always create `HashTable` with at least "alias" key
result = _.collections.EmptyHashTable();
immutableValue = textValue.Copy();
result.SetItem(P("alias"), immutableValue);
_.memory.Free(immutableValue);
// Add "value" key only after we've checked for "$" prefix
if (!textValue.StartsWithS("$")) {
return result;
}
if (aliasSourceName.Compare(P("weapon"))) {
resolvedValue = _.alias.ResolveWeapon(textValue, true);
}
@ -672,8 +684,9 @@ private final function AutoResolveAlias(
else {
resolvedValue = _.alias.ResolveCustom(aliasSourceName, textValue, true);
}
textValue.FreeSelf();
textValue = resolvedValue.IntoMutableText();
result.SetItem(P("value"), resolvedValue);
_.memory.Free2(resolvedValue, immutableValue);
return result;
}
// Assumes `commandParser` and `parsedParameters` are not `none`.