From e1943612b7681d9789c4568a382d20483a4f1407 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Mon, 3 Oct 2022 04:12:49 +0700 Subject: [PATCH] Add parsing support for JSON command arguments --- sources/Commands/CommandParser.uc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sources/Commands/CommandParser.uc b/sources/Commands/CommandParser.uc index c78edfc..a3a03ba 100644 --- a/sources/Commands/CommandParser.uc +++ b/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