MCPcopy Create free account
hub / github.com/adobe/hyde / ProcessComment

Function ProcessComment

matchers/utilities.cpp:371–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369/**************************************************************************************************/
370
371hyde::optional_json ProcessComment(const ASTContext& n,
372 const FullComment* full_comment,
373 const Comment* comment) {
374 const CommandTraits& commandTraits = n.getCommentCommandTraits();
375 hyde::json::object_t result;
376
377 const auto process_comment_args = [](auto& comment_with_args) -> hyde::optional_json {
378 const unsigned arg_count = comment_with_args.getNumArgs();
379 if (arg_count == 0) return std::nullopt;
380
381 hyde::json::array_t result;
382
383 for (unsigned i{0}; i < arg_count; ++i) {
384 hyde::json::object_t args_entry;
385 args_entry["text"] = to_string_view(comment_with_args.getArgText(i));
386 result.push_back(std::move(args_entry));
387 }
388
389 return result;
390 };
391
392 const auto process_comment_children =
393 [&n, &full_comment](auto& comment_with_children) -> hyde::optional_json {
394 auto first = comment_with_children.child_begin();
395 auto last = comment_with_children.child_end();
396
397 if (first == last) return std::nullopt;
398
399 hyde::json::array_t result;
400
401 while (first != last) {
402 if (auto entry = ProcessComment(n, full_comment, *first++)) {
403 result.emplace_back(std::move(*entry));
404 }
405 }
406
407 return result;
408 };
409
410 // If the comment only has one child and it's a paragraph comment,
411 // take the text from that child and move it into the parent, then
412 // delete all the children (which is just the now-empty paragraph.)
413 const auto roll_up_single_paragraph_child =
414 [](hyde::json::object_t json) -> hyde::json::object_t {
415 if (json.count("children") != 1) return json;
416 auto& children = json["children"];
417 auto& first_child = *children.begin();
418 if (first_child["kind"] != "ParagraphComment") return json;
419 json["text"] = std::move(first_child["text"]);
420 json.erase("children");
421 return json;
422 };
423
424 const auto post_process_hyde_command = [](hyde::json::object_t json) -> hyde::json::object_t {
425 if (json["name"].get<std::string>() != "hyde") return json;
426
427 const std::string text = json["text"].get<std::string>();
428 const auto first_space = text.find_first_of(" \t\n\r\v\f"); // \v and \f? Really?

Callers 1

ProcessCommentsFunction · 0.85

Calls 2

to_string_viewFunction · 0.85
chompFunction · 0.70

Tested by

no test coverage detected