summaryrefslogtreecommitdiff
path: root/include/mbgl/style/expression/parsing_context.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/expression/parsing_context.hpp')
-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;