blob: 248ba4c1021a08c161e8b7b5189be74c2895a193 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#pragma once
#include <array>
#include <vector>
#include <memory>
#include <mbgl/style/expression/compound_expression.hpp>
#include <mbgl/style/expression/type.hpp>
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/conversion.hpp>
namespace mbgl {
namespace style {
namespace expression {
struct ParseCompoundExpression {
template <class V>
static ParseResult parse(const V& value, ParsingContext ctx) {
using namespace mbgl::style::conversion;
assert(isArray(value) && arrayLength(value) > 0);
const auto& name = toString(arrayMember(value, 0));
assert(name);
auto it = CompoundExpressions::definitions.find(*name);
if (it == CompoundExpressions::definitions.end()) {
ctx.error(
R"(Unknown expression ")" + *name + R"(". If you wanted a literal array, use ["literal", [...]].)",
0
);
return ParseResult();
}
const CompoundExpressions::Definition& definition = it->second;
// parse subexpressions first
std::vector<std::unique_ptr<Expression>> args;
auto length = arrayLength(value);
for (std::size_t i = 1; i < length; i++) {
auto parsed = parseExpression(arrayMember(value, i), ParsingContext(ctx, i));
if (!parsed) {
return parsed;
}
args.push_back(std::move(*parsed));
}
return CompoundExpressions::create(*name, definition, std::move(args), ctx);
}
};
} // namespace expression
} // namespace style
} // namespace mbgl
|