summaryrefslogtreecommitdiff
path: root/include/mbgl/style/expression/parse.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/expression/parse.hpp')
-rw-r--r--include/mbgl/style/expression/parse.hpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/include/mbgl/style/expression/parse.hpp b/include/mbgl/style/expression/parse.hpp
index 1f5802d4fb..cba2231988 100644
--- a/include/mbgl/style/expression/parse.hpp
+++ b/include/mbgl/style/expression/parse.hpp
@@ -37,7 +37,8 @@ ParseResult parseExpression(const V& value, const ParsingContext& context)
using namespace mbgl::style::conversion;
if (isArray(value)) {
- if (arrayLength(value) == 0) {
+ const std::size_t length = arrayLength(value);
+ if (length == 0) {
CompileError error = {
"Expected an array with at least one element. If you wanted a literal array, use [\"literal\", []].",
context.key()
@@ -55,6 +56,14 @@ ParseResult parseExpression(const V& value, const ParsingContext& context)
return error;
}
+ if (*op == "literal") {
+ if (length != 2) return CompileError {
+ "'literal' expression requires exactly one argument, but found " + std::to_string(length - 1) + " instead.",
+ context.key()
+ };
+ return LiteralExpression::parse(arrayMember(value, 1), ParsingContext(context, {1}, {"literal"}));
+ }
+
if (*op == "+") return LambdaExpression::parse<PlusExpression>(value, context);
if (*op == "-") return LambdaExpression::parse<MinusExpression>(value, context);
if (*op == "*") return LambdaExpression::parse<TimesExpression>(value, context);