diff options
Diffstat (limited to 'include/mbgl')
-rw-r--r-- | include/mbgl/style/conversion/expression.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/expression.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse.hpp | 111 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/array_assertion.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/at.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/case.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/coalesce.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/compound_expression.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/curve.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/in.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/let.hpp | 6 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/literal.hpp | 9 | ||||
-rw-r--r-- | include/mbgl/style/expression/parse/match.hpp | 6 |
13 files changed, 19 insertions, 142 deletions
diff --git a/include/mbgl/style/conversion/expression.hpp b/include/mbgl/style/conversion/expression.hpp index 8d0c30351d..4a8cf1030e 100644 --- a/include/mbgl/style/conversion/expression.hpp +++ b/include/mbgl/style/conversion/expression.hpp @@ -12,8 +12,7 @@ namespace conversion { using namespace mbgl::style::expression; template<> struct Converter<std::unique_ptr<Expression>> { - template <class V> - optional<std::unique_ptr<Expression>> operator()(const V& value, Error& error, type::Type expected) const { + optional<std::unique_ptr<Expression>> operator()(const mbgl::style::conversion::Value& value, Error& error, type::Type expected) const { std::vector<ParsingError> errors; ParseResult parsed = parseExpression(value, ParsingContext(errors, expected)); if (parsed) { diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 8be2ae162c..e9a1cca658 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -9,8 +9,6 @@ #include <mbgl/style/expression/type.hpp> #include <mbgl/style/expression/value.hpp> #include <mbgl/style/expression/parsing_context.hpp> -#include <mbgl/style/conversion.hpp> - namespace mbgl { @@ -119,7 +117,6 @@ private: using ParseResult = optional<std::unique_ptr<Expression>>; - } // namespace expression } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/expression/parse.hpp b/include/mbgl/style/expression/parse.hpp index 2b5bab7750..ae0d62732b 100644 --- a/include/mbgl/style/expression/parse.hpp +++ b/include/mbgl/style/expression/parse.hpp @@ -1,23 +1,9 @@ #pragma once #include <memory> -#include <mbgl/style/conversion/get_json_type.hpp> -#include <mbgl/style/expression/check_subtype.hpp> +#include <mbgl/style/conversion.hpp> #include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/compound_expression.hpp> - -#include <mbgl/style/expression/parse/at.hpp> -#include <mbgl/style/expression/parse/array_assertion.hpp> -#include <mbgl/style/expression/parse/case.hpp> -#include <mbgl/style/expression/parse/coalesce.hpp> -#include <mbgl/style/expression/parse/compound_expression.hpp> -#include <mbgl/style/expression/parse/curve.hpp> -#include <mbgl/style/expression/parse/in.hpp> -#include <mbgl/style/expression/parse/let.hpp> -#include <mbgl/style/expression/parse/literal.hpp> -#include <mbgl/style/expression/parse/match.hpp> #include <mbgl/style/expression/parsing_context.hpp> -#include <mbgl/style/expression/type.hpp> namespace mbgl { @@ -32,100 +18,7 @@ using namespace mbgl::style; type (either Literal, or the one named in value[0]) and dispatching to the appropriate ParseXxxx::parse(const V&, ParsingContext) method. */ -template <class V> -ParseResult parseExpression(const V& value, ParsingContext context) -{ - using namespace mbgl::style::conversion; - - ParseResult parsed; - - if (isArray(value)) { - const std::size_t length = arrayLength(value); - if (length == 0) { - context.error(R"(Expected an array with at least one element. If you wanted a literal array, use ["literal", []].)"); - return ParseResult(); - } - - const optional<std::string> op = toString(arrayMember(value, 0)); - if (!op) { - context.error( - "Expression name must be a string, but found " + getJSONType(arrayMember(value, 0)) + - R"( instead. If you wanted a literal array, use ["literal", [...]].)", - 0 - ); - return ParseResult(); - } - - if (*op == "literal") { - if (length != 2) { - context.error( - "'literal' expression requires exactly one argument, but found " + std::to_string(length - 1) + " instead." - ); - return ParseResult(); - } - - parsed = ParseLiteral::parse(arrayMember(value, 1), context); - } else if (*op == "match") { - parsed = ParseMatch::parse(value, context); - } else if (*op == "curve") { - parsed = ParseCurve::parse(value, context); - } else if (*op == "coalesce") { - parsed = ParseCoalesce::parse(value, context); - } else if (*op == "case") { - parsed = ParseCase::parse(value, context); - } else if (*op == "array") { - parsed = ParseArrayAssertion::parse(value, context); - } else if (*op == "let") { - parsed = ParseLet::parse(value, context); - } else if (*op == "var") { - parsed = ParseVar::parse(value, context); - } else if (*op == "at") { - parsed = ParseAt::parse(value, context); - } else if (*op == "contains") { - parsed = ParseIn::parse(value, context); - } else { - parsed = ParseCompoundExpression::parse(*op, value, context); - } - } else { - if (isObject(value)) { - context.error(R"(Bare objects invalid. Use ["literal", {...}] instead.)"); - return ParseResult(); - } - - parsed = ParseLiteral::parse(value, context); - } - - if (!parsed) { - assert(context.errors.size() > 0); - } else if (context.expected) { - auto wrapForType = [&](const std::string& wrapper, std::unique_ptr<Expression> expression) { - std::vector<std::unique_ptr<Expression>> args; - args.push_back(std::move(expression)); - return createCompoundExpression(wrapper, std::move(args), context); - }; - - const type::Type actual = (*parsed)->getType(); - const type::Type expected = *context.expected; - if (expected == type::Color && (actual == type::String || actual == type::Value)) { - parsed = wrapForType("to-color", std::move(*parsed)); - } else if (expected != type::Value && actual == type::Value) { - if (expected == type::String) { - parsed = wrapForType("string", std::move(*parsed)); - } else if (expected == type::Number) { - parsed = wrapForType("number", std::move(*parsed)); - } else if (expected == type::Boolean) { - parsed = wrapForType("boolean", std::move(*parsed)); - } - } - - checkSubtype(*(context.expected), (*parsed)->getType(), context); - if (context.errors.size() > 0) { - return ParseResult(); - } - } - - return parsed; -} +ParseResult parseExpression(const mbgl::style::conversion::Value& value, ParsingContext context); } // namespace expression diff --git a/include/mbgl/style/expression/parse/array_assertion.hpp b/include/mbgl/style/expression/parse/array_assertion.hpp index e19573d23c..fe86c670b0 100644 --- a/include/mbgl/style/expression/parse/array_assertion.hpp +++ b/include/mbgl/style/expression/parse/array_assertion.hpp @@ -11,8 +11,7 @@ namespace style { namespace expression { struct ParseArrayAssertion { - template <class V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; static std::unordered_map<std::string, type::Type> itemTypes { diff --git a/include/mbgl/style/expression/parse/at.hpp b/include/mbgl/style/expression/parse/at.hpp index 22af5dc507..ed2f3c9ead 100644 --- a/include/mbgl/style/expression/parse/at.hpp +++ b/include/mbgl/style/expression/parse/at.hpp @@ -10,8 +10,7 @@ namespace style { namespace expression { struct ParseAt { - template <typename V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); diff --git a/include/mbgl/style/expression/parse/case.hpp b/include/mbgl/style/expression/parse/case.hpp index 43aa725daa..4465182f8f 100644 --- a/include/mbgl/style/expression/parse/case.hpp +++ b/include/mbgl/style/expression/parse/case.hpp @@ -10,8 +10,7 @@ namespace style { namespace expression { struct ParseCase { - template <class V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); diff --git a/include/mbgl/style/expression/parse/coalesce.hpp b/include/mbgl/style/expression/parse/coalesce.hpp index a9d3214130..2e902cdc41 100644 --- a/include/mbgl/style/expression/parse/coalesce.hpp +++ b/include/mbgl/style/expression/parse/coalesce.hpp @@ -12,8 +12,7 @@ namespace style { namespace expression { struct ParseCoalesce { - template <typename V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); auto length = arrayLength(value); diff --git a/include/mbgl/style/expression/parse/compound_expression.hpp b/include/mbgl/style/expression/parse/compound_expression.hpp index e9cc577642..ed91b14668 100644 --- a/include/mbgl/style/expression/parse/compound_expression.hpp +++ b/include/mbgl/style/expression/parse/compound_expression.hpp @@ -14,8 +14,7 @@ namespace style { namespace expression { struct ParseCompoundExpression { - template <class V> - static ParseResult parse(const std::string name, const V& value, ParsingContext ctx) { + static ParseResult parse(const std::string name, const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value) && arrayLength(value) > 0); diff --git a/include/mbgl/style/expression/parse/curve.hpp b/include/mbgl/style/expression/parse/curve.hpp index 1c7ba8d270..94d53ecef2 100644 --- a/include/mbgl/style/expression/parse/curve.hpp +++ b/include/mbgl/style/expression/parse/curve.hpp @@ -17,8 +17,7 @@ struct ParseCurve { ExponentialInterpolator, CubicBezierInterpolator>; - template <typename V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); @@ -30,7 +29,7 @@ struct ParseCurve { ctx.error("Expected an interpolation type expression."); return ParseResult(); } - const V& interp = arrayMember(value, 1); + const mbgl::style::conversion::Value& interp = arrayMember(value, 1); if (!isArray(interp) || arrayLength(interp) == 0) { ctx.error("Expected an interpolation type expression."); return ParseResult(); diff --git a/include/mbgl/style/expression/parse/in.hpp b/include/mbgl/style/expression/parse/in.hpp index 2cc5994c9f..94df87807d 100644 --- a/include/mbgl/style/expression/parse/in.hpp +++ b/include/mbgl/style/expression/parse/in.hpp @@ -10,8 +10,7 @@ namespace style { namespace expression { struct ParseIn { - template <typename V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); diff --git a/include/mbgl/style/expression/parse/let.hpp b/include/mbgl/style/expression/parse/let.hpp index a4017de41b..042c186a47 100644 --- a/include/mbgl/style/expression/parse/let.hpp +++ b/include/mbgl/style/expression/parse/let.hpp @@ -14,8 +14,7 @@ namespace style { namespace expression { struct ParseLet { - template <typename V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); @@ -61,8 +60,7 @@ struct ParseLet { }; struct ParseVar { - template <typename V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); diff --git a/include/mbgl/style/expression/parse/literal.hpp b/include/mbgl/style/expression/parse/literal.hpp index 1b4a00b074..90bea956a4 100644 --- a/include/mbgl/style/expression/parse/literal.hpp +++ b/include/mbgl/style/expression/parse/literal.hpp @@ -15,8 +15,7 @@ namespace style { namespace expression { struct ParseLiteral { - template <class V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { const optional<Value> parsedValue = parseValue(value, ctx); if (!parsedValue) { @@ -40,14 +39,14 @@ struct ParseLiteral { } return ParseResult(std::make_unique<Literal>(*parsedValue)); } - template <class V> - static optional<Value> parseValue(const V& value, ParsingContext ctx) { + + static optional<Value> parseValue(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; if (isUndefined(value)) return {Null}; if (isObject(value)) { std::unordered_map<std::string, Value> result; bool error = false; - eachMember(value, [&] (const std::string& k, const V& v) -> optional<conversion::Error> { + eachMember(value, [&] (const std::string& k, const mbgl::style::conversion::Value& v) -> optional<conversion::Error> { if (!error) { optional<Value> memberValue = parseValue(v, ctx); if (memberValue) { diff --git a/include/mbgl/style/expression/parse/match.hpp b/include/mbgl/style/expression/parse/match.hpp index cc73b76b48..6841d9b94d 100644 --- a/include/mbgl/style/expression/parse/match.hpp +++ b/include/mbgl/style/expression/parse/match.hpp @@ -12,8 +12,7 @@ namespace style { namespace expression { struct ParseMatch { - template <class V> - static ParseResult parse(const V& value, ParsingContext ctx) { + static ParseResult parse(const mbgl::style::conversion::Value& value, ParsingContext ctx) { using namespace mbgl::style::conversion; assert(isArray(value)); @@ -108,8 +107,7 @@ struct ParseMatch { } private: - template <typename V> - static optional<InputType> parseInputValue(const V& input, ParsingContext ctx, optional<type::Type>& inputType) { + static optional<InputType> parseInputValue(const mbgl::style::conversion::Value& input, ParsingContext ctx, optional<type::Type>& inputType) { using namespace mbgl::style::conversion; optional<InputType> result; optional<type::Type> type; |