[core] Introduce "collator" expressions
Cross platform parsing and evaluation code.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <mbgl/style/expression/collator.hpp>
|
||||
#include <mbgl/style/expression/compound_expression.hpp>
|
||||
#include <mbgl/style/expression/check_subtype.hpp>
|
||||
#include <mbgl/style/expression/util.hpp>
|
||||
@@ -481,12 +483,16 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
|
||||
|
||||
define(">", [](double lhs, double rhs) -> Result<bool> { return lhs > rhs; });
|
||||
define(">", [](const std::string& lhs, const std::string& rhs) -> Result<bool> { return lhs > rhs; });
|
||||
define(">", [](const std::string& lhs, const std::string& rhs, const Collator& c) -> Result<bool> { return c.compare(lhs, rhs) > 0; });
|
||||
define(">=", [](double lhs, double rhs) -> Result<bool> { return lhs >= rhs; });
|
||||
define(">=",[](const std::string& lhs, const std::string& rhs) -> Result<bool> { return lhs >= rhs; });
|
||||
define(">=", [](const std::string& lhs, const std::string& rhs, const Collator& c) -> Result<bool> { return c.compare(lhs, rhs) >= 0; });
|
||||
define("<", [](double lhs, double rhs) -> Result<bool> { return lhs < rhs; });
|
||||
define("<", [](const std::string& lhs, const std::string& rhs) -> Result<bool> { return lhs < rhs; });
|
||||
define("<", [](const std::string& lhs, const std::string& rhs, const Collator& c) -> Result<bool> { return c.compare(lhs, rhs) < 0; });
|
||||
define("<=", [](double lhs, double rhs) -> Result<bool> { return lhs <= rhs; });
|
||||
define("<=", [](const std::string& lhs, const std::string& rhs) -> Result<bool> { return lhs <= rhs; });
|
||||
define("<=", [](const std::string& lhs, const std::string& rhs, const Collator& c) -> Result<bool> { return c.compare(lhs, rhs) <= 0; });
|
||||
|
||||
define("!", [](bool e) -> Result<bool> { return !e; });
|
||||
|
||||
@@ -507,6 +513,10 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
|
||||
}
|
||||
return s;
|
||||
});
|
||||
define("resolved-locale", [](const Collator& collator) -> Result<std::string> {
|
||||
return collator.resolvedLocale();
|
||||
});
|
||||
|
||||
define("error", [](const std::string& input) -> Result<type::ErrorType> {
|
||||
return EvaluationError { input };
|
||||
});
|
||||
@@ -686,26 +696,35 @@ static ParseResult createCompoundExpression(const Definition& definition,
|
||||
if (definition.size() == 1) {
|
||||
ctx.appendErrors(std::move(signatureContext));
|
||||
} else {
|
||||
std::string signatures;
|
||||
std::vector<std::string> availableOverloads; // Only used if there are no overloads with matching number of args
|
||||
std::vector<std::string> overloads;
|
||||
for (const auto& signature : definition) {
|
||||
signatures += (signatures.size() > 0 ? " | " : "");
|
||||
signature->params.match(
|
||||
[&](const VarargsType& varargs) {
|
||||
signatures += "(" + toString(varargs.type) + ")";
|
||||
std::string overload = "(" + toString(varargs.type) + ")";
|
||||
overloads.push_back(overload);
|
||||
},
|
||||
[&](const std::vector<type::Type>& params) {
|
||||
signatures += "(";
|
||||
std::string overload = "(";
|
||||
bool first = true;
|
||||
for (const type::Type& param : params) {
|
||||
if (!first) signatures += ", ";
|
||||
signatures += toString(param);
|
||||
if (!first) overload += ", ";
|
||||
overload += toString(param);
|
||||
first = false;
|
||||
}
|
||||
signatures += ")";
|
||||
overload += ")";
|
||||
if (params.size() == args.size()) {
|
||||
overloads.push_back(overload);
|
||||
} else {
|
||||
availableOverloads.push_back(overload);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
std::string signatures = overloads.empty() ?
|
||||
boost::algorithm::join(availableOverloads, " | ") :
|
||||
boost::algorithm::join(overloads, " | ");
|
||||
std::string actualTypes;
|
||||
for (const auto& arg : args) {
|
||||
if (actualTypes.size() > 0) {
|
||||
|
||||
Reference in New Issue
Block a user