summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-09-13 15:03:19 -0700
committerChris Loer <chris.loer@mapbox.com>2018-09-19 14:54:38 -0700
commit2e93a9ddcf1f97188250335d991fbd7a2cc283af (patch)
tree86289e08e361a90e38c35db12501ea9b056d832d /include
parent89b075f592271bc11d58ebb7f854c453e81e3cf1 (diff)
downloadqtlocation-mapboxgl-2e93a9ddcf1f97188250335d991fbd7a2cc283af.tar.gz
[core] For string-valued properties, do coercion rather than assertion
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/style/expression/parsing_context.hpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/include/mbgl/style/expression/parsing_context.hpp b/include/mbgl/style/expression/parsing_context.hpp
index 66014e33d4..dde907ec2c 100644
--- a/include/mbgl/style/expression/parsing_context.hpp
+++ b/include/mbgl/style/expression/parsing_context.hpp
@@ -52,6 +52,25 @@ public:
} // namespace detail
+/*
+ Controls the annotation behavior of the parser when encountering an expression
+ whose type is not a subtype of the expected type. The default behavior, used
+ when optional<TypeAnnotationOption> is a nullopt, is as follows:
+
+ When we expect a number, string, boolean, or array but have a value, wrap it in an assertion.
+ When we expect a color or formatted string, but have a string or value, wrap it in a coercion.
+ Otherwise, we do static type-checking.
+
+ These behaviors are overridable for:
+ * The "coalesce" operator, which needs to omit type annotations.
+ * String-valued properties (e.g. `text-field`), where coercion is more convenient than assertion.
+*/
+enum class TypeAnnotationOption {
+ coerce,
+ assert,
+ omit
+};
+
class ParsingContext {
public:
ParsingContext() : errors(std::make_shared<std::vector<ParsingError>>()) {}
@@ -70,24 +89,18 @@ public:
const std::vector<ParsingError>& getErrors() const { return *errors; }
const std::string getCombinedErrors() const;
- enum TypeAnnotationOption {
- includeTypeAnnotations,
- omitTypeAnnotations
- };
-
/*
Parse the given style-spec JSON value as an expression.
*/
ParseResult parseExpression(const mbgl::style::conversion::Convertible& value,
- TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations);
+ optional<TypeAnnotationOption> = {});
/*
Parse the given style-spec JSON value as an expression intended to be used
in a layout or paint property. This entails checking additional constraints
that exist in that context but not, e.g., for filters.
*/
- ParseResult parseLayerPropertyExpression(const mbgl::style::conversion::Convertible& value,
- TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations);
+ ParseResult parseLayerPropertyExpression(const mbgl::style::conversion::Convertible& value);
/*
Parse a child expression. For use by individual Expression::parse() methods.
@@ -95,7 +108,7 @@ public:
ParseResult parse(const mbgl::style::conversion::Convertible&,
std::size_t,
optional<type::Type> = {},
- TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations);
+ optional<TypeAnnotationOption> = {});
/*
Parse a child expression. For use by individual Expression::parse() methods.
@@ -156,7 +169,7 @@ private:
appropriate ParseXxxx::parse(const V&, ParsingContext) method.
*/
ParseResult parse(const mbgl::style::conversion::Convertible& value,
- TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations);
+ optional<TypeAnnotationOption> = {});
std::string key;
optional<type::Type> expected;