diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2018-04-12 16:02:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-12 16:02:48 -0400 |
commit | 352d63d2ce98286cd854b11e85d66440501a6fd0 (patch) | |
tree | 08a6cc5140ddf044590ce82a44b7f2e0a920638c /src/mbgl | |
parent | 646cbc98ddaa8f6afe84c96888c877628bf405ca (diff) | |
download | qtlocation-mapboxgl-352d63d2ce98286cd854b11e85d66440501a6fd0.tar.gz |
Don't enforce ["zoom"] constraints for filters (#11672)
* Don't enforce ["zoom"] constraints for filters
Fixes #11594
* Add a couple of comments
* Fix ambiguous constructor call
* ParsingContext(optional<Type>) => ParsingContext(Type)
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/style/conversion/filter.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/style/expression/parsing_context.cpp | 27 |
2 files changed, 29 insertions, 5 deletions
diff --git a/src/mbgl/style/conversion/filter.cpp b/src/mbgl/style/conversion/filter.cpp index fba149da12..3c941945fd 100644 --- a/src/mbgl/style/conversion/filter.cpp +++ b/src/mbgl/style/conversion/filter.cpp @@ -2,7 +2,7 @@ #include <mbgl/util/geometry.hpp> #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/expression/type.hpp> -#include <mbgl/style/conversion/expression.hpp> +#include <mbgl/style/expression/parsing_context.hpp> namespace mbgl { namespace style { @@ -236,10 +236,13 @@ optional<Filter> convertCompoundFilter(const Convertible& value, Error& error) { } optional<Filter> convertExpressionFilter(const Convertible& value, Error& error) { - optional<std::unique_ptr<Expression>> expression = convert<std::unique_ptr<Expression>>(value, error, expression::type::Boolean); + expression::ParsingContext ctx(expression::type::Boolean); + expression::ParseResult expression = ctx.parseExpression(value); if (!expression) { + error = { ctx.getCombinedErrors() }; return {}; } + return { ExpressionFilter { std::move(*expression) } }; } diff --git a/src/mbgl/style/expression/parsing_context.cpp b/src/mbgl/style/expression/parsing_context.cpp index 713c0b5d27..b522aeff9a 100644 --- a/src/mbgl/style/expression/parsing_context.cpp +++ b/src/mbgl/style/expression/parsing_context.cpp @@ -206,8 +206,16 @@ ParseResult ParsingContext::parse(const Convertible& value, TypeAnnotationOption } } - // if this is the root expression, enforce constraints on the use ["zoom"]. - if (key.size() == 0 && !isZoomConstant(**parsed)) { + return parsed; +} + +ParseResult ParsingContext::parseExpression(const Convertible& value, TypeAnnotationOption typeAnnotationOption) { + return parse(value, typeAnnotationOption); +} + +ParseResult ParsingContext::parseLayerPropertyExpression(const Convertible& value, TypeAnnotationOption typeAnnotationOption) { + ParseResult parsed = parse(value, typeAnnotationOption); + if (parsed && !isZoomConstant(**parsed)) { optional<variant<const InterpolateBase*, const Step*, ParsingError>> zoomCurve = findZoomCurve(parsed->get()); if (!zoomCurve) { error(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)"); @@ -217,10 +225,23 @@ ParseResult ParsingContext::parse(const Convertible& value, TypeAnnotationOption return ParseResult(); } } - return parsed; } +const std::string ParsingContext::getCombinedErrors() const { + std::string combinedError; + for (const ParsingError& parsingError : *errors) { + if (combinedError.size() > 0) { + combinedError += "\n"; + } + if (parsingError.key.size() > 0) { + combinedError += parsingError.key + ": "; + } + combinedError += parsingError.message; + } + return combinedError; +} + optional<std::string> ParsingContext::checkType(const type::Type& t) { assert(expected); optional<std::string> err = type::checkSubtype(*expected, t); |