27 const auto len = requirements.length();
28 if (len >= 2 && ((requirements[0] ==
'\'' && requirements[len - 1] ==
'\'') ||
29 (requirements[0] ==
'"' && requirements[len - 1] ==
'"')))
30 requirements = requirements.substr(1, len - 2);
34 if (requirements.length() == 0)
38 Expression <- _ Bool _ LogicOperator _ Expression / Bool _ 39 Bool <- Comparison / '!' Bool / '!' Identifier / Identifier / '(' _ Expression _ ')' 40 Comparison <- Identifier _ Operator _ Version / Identifier _ Operator _ String 41 String <- [a-zA-Z0-9_-]+ 42 Identifier <- [a-zA-Z][a-zA-Z0-9_]* 45 Version <- Number '.' Version / Number 50 if (!static_cast<bool>(parser))
53 parser[
"Number"] = [](
const SemanticValues & vs) {
return vs.token_to_number<
int>(); };
55 parser[
"Version"] = [](
const SemanticValues & vs)
61 std::vector<int> ret{std::any_cast<
int>(vs[0])};
62 const auto & vs1 = std::any_cast<std::vector<int>>(vs[1]);
63 ret.insert(ret.end(), vs1.begin(), vs1.end());
68 return std::vector<int>{std::any_cast<
int>(vs[0])};
81 parser[
"LogicOperator"] = [](
const SemanticValues & vs)
83 const auto op = vs.token();
101 parser[
"Operator"] = [](
const SemanticValues & vs)
103 const auto op = vs.token();
107 return OP_GREATER_EQ;
114 if (op ==
"=" || op ==
"==")
119 parser[
"String"] = [](
const SemanticValues & vs) {
return vs.token_to_string(); };
120 parser[
"Identifier"] = [](
const SemanticValues & vs) {
return vs.token_to_string(); };
122 parser[
"Comparison"] = [&app_capabilities](
const SemanticValues & vs)
124 const auto left = std::any_cast<std::string>(vs[0]);
125 const auto op = std::any_cast<Operator>(vs[1]);
128 const auto it = app_capabilities.find(left);
129 if (it == app_capabilities.end())
132 return CheckState::UNKNOWN;
135 const auto & [app_value, doc] = it->second;
138 if (std::holds_alternative<bool>(app_value) && std::get<bool>(app_value) ==
false)
142 auto comp = [](
int i,
auto a,
auto b)
167 const auto right = std::any_cast<std::vector<int>>(vs[2]);
168 if (std::holds_alternative<int>(app_value))
170 if (right.size() != 1)
178 std::vector<int> app_value_version;
180 if (!std::holds_alternative<std::string>(app_value))
182 right.size() == 1 ?
"Cannot compare capability " + left +
" to a number." 183 :
"Cannot compare capability " + left +
" to a version number.");
186 std::get<std::string>(app_value), app_value_version,
"."))
196 const auto right = std::any_cast<std::string>(vs[2]);
198 if (!std::holds_alternative<std::string>(app_value))
210 parser[
"Bool"] = [&app_capabilities](
const SemanticValues & vs)
219 switch (std::any_cast<CheckState>(vs[0]))
230 return CheckState::UNKNOWN;
235 const auto it = app_capabilities.find(std::any_cast<std::string>(vs[0]));
236 if (it != app_capabilities.end())
238 const auto app_value = it->second.first;
239 if (std::holds_alternative<bool>(app_value) && std::get<bool>(app_value) ==
false)
248 const auto it = app_capabilities.find(std::any_cast<std::string>(vs[0]));
249 if (it != app_capabilities.end())
251 const auto app_value = it->second.first;
252 if (std::holds_alternative<bool>(app_value) && std::get<bool>(app_value) ==
false)
264 parser[
"Expression"] = [](
const SemanticValues & vs)
270 const auto left = std::any_cast<
CheckState>(vs[0]);
271 const auto op = std::any_cast<LogicOperator>(vs[1]);
272 const auto right = std::any_cast<
CheckState>(vs[2]);
282 if (left == state || right == state)
292 if (left == state || right == state)
310 parser.enable_packrat_parsing();
313 if (!parser.parse(requirements, state))
319 return {state, reason, doc};
std::string toLower(const std::string &name)
Convert supplied string to lower case.
bool tokenizeAndConvert(const std::string &str, std::vector< T > &tokenized_vector, const std::string &delimiter=" \\\)
tokenizeAndConvert splits a string using delimiter and then converts to type T.
CheckState
Return state for check.
std::tuple< CheckState, std::string, std::string > Result
Result from a capability check: the state, the reason, and the documentation.
The registry is used as a global singleton to collect information on all available MooseObject and Ac...
Result check(std::string requirements, const Registry &capabilities)
Checks if a set of requirements is satisified by the given capability registry.
Shared code for the Capabilities Registry and the python bindings to the Capabilities system...