blob: 22af5dc5077fffae393f80c02340b3bfa1af4eb4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#pragma once
#include <mbgl/style/expression/parse.hpp>
#include <mbgl/style/expression/at.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/expression/type.hpp>
namespace mbgl {
namespace style {
namespace expression {
struct ParseAt {
template <typename V>
static ParseResult parse(const V& value, ParsingContext ctx) {
using namespace mbgl::style::conversion;
assert(isArray(value));
std::size_t length = arrayLength(value);
if (length != 3) {
ctx.error("Expected 2 arguments, but found " + std::to_string(length - 1) + " instead.");
return ParseResult();
}
ParseResult index = parseExpression(arrayMember(value, 1), ParsingContext(ctx, 1, {type::Number}));
ParseResult input = parseExpression(arrayMember(value, 2),
ParsingContext(ctx, 2, {type::Array(ctx.expected ? *ctx.expected : type::Value)}));
if (!index || !input) return ParseResult();
return ParseResult(std::make_unique<At>(std::move(*index), std::move(*input)));
}
};
} // namespace expression
} // namespace style
} // namespace mbgl
|