MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ParseFunctionList

Function ParseFunctionList

env/env_yaml.cc:238–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238absl::StatusOr<absl::flat_hash_set<std::pair<std::string, std::string>>>
239ParseFunctionList(absl::string_view yaml, const YAML::Node& standard_library,
240 absl::string_view key) {
241 absl::flat_hash_set<std::pair<std::string, std::string>> function_set;
242 const YAML::Node functions = standard_library[std::string(key)];
243 if (!functions.IsDefined()) {
244 return function_set;
245 }
246 if (!functions.IsSequence()) {
247 return YamlError(yaml, functions,
248 absl::StrCat("Node '", key, "' is not a sequence"));
249 }
250 for (const YAML::Node& function : functions) {
251 if (!function.IsMap()) {
252 return YamlError(yaml, function,
253 absl::StrCat("Entry in '", key, "' is not a map"));
254 }
255 const YAML::Node name = function["name"];
256 if (!name.IsDefined()) {
257 return YamlError(
258 yaml, function,
259 absl::StrCat("Function name in not specified in '", key, "'"));
260 }
261 if (!name.IsScalar()) {
262 return YamlError(
263 yaml, name,
264 absl::StrCat("Function name in '", key, "' entry is not a string"));
265 }
266 std::string name_str = GetString(yaml, name);
267 const YAML::Node overloads = function["overloads"];
268 if (!overloads.IsDefined()) {
269 function_set.insert(std::make_pair(name_str, ""));
270 } else {
271 if (!overloads.IsSequence()) {
272 return YamlError(
273 yaml, overloads,
274 absl::StrCat("Overloads in '", key, "' entry is not a sequence"));
275 }
276 for (const YAML::Node& overload : overloads) {
277 if (!overload.IsMap()) {
278 return YamlError(
279 yaml, overload,
280 absl::StrCat("Overload in '", key, "' entry is not a map"));
281 }
282 const YAML::Node id = overload["id"];
283 if (!id || !id.IsScalar()) {
284 return YamlError(
285 yaml, id,
286 absl::StrCat("Overload id in '", key, "' entry is not a string"));
287 }
288 function_set.insert(std::make_pair(name_str, GetString(yaml, id)));
289 }
290 }
291 }
292 return function_set;
293}
294
295absl::Status ParseStandardLibraryConfig(Config& config, absl::string_view yaml,

Callers 1

Calls 3

YamlErrorFunction · 0.85
GetStringFunction · 0.85
IsMapMethod · 0.45

Tested by

no test coverage detected