Browse Source

Add parsing support for JSON command arguments

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
e1943612b7
  1. 20
      sources/Commands/CommandParser.uc

20
sources/Commands/CommandParser.uc

@ -449,6 +449,9 @@ private final function bool ParseSingleValue(
else if (expectedParameter.type == CPT_Array) {
return ParseArrayValue(parsedParameters, expectedParameter);
}
else if (expectedParameter.type == CPT_JSON) {
return ParseJSONValue(parsedParameters, expectedParameter);
}
return false;
}
@ -615,6 +618,23 @@ private final function bool ParseArrayValue(
return true;
}
// Assumes `commandParser` and `parsedParameters` are not `none`.
// Parses a single JSON value into given `parsedParameters`
// hash table.
private final function bool ParseJSONValue(
HashTable parsedParameters,
Command.Parameter expectedParameter)
{
local AcediaObject jsonValue;
jsonValue = _.json.ParseWith(commandParser);
if (!commandParser.Ok()) {
return false;
}
RecordParameter(parsedParameters, expectedParameter, jsonValue);
return true;
}
// Assumes `parsedParameters` is not `none`.
// Records `value` for a given `parameter` into a given `parametersArray`.
// If parameter is not a list type - simply records `value` as value under

Loading…
Cancel
Save