Added paragaph array to clang comment parser

This commit is contained in:
Bartek Kryza
2022-09-22 19:33:08 +02:00
parent 9bb2a6e8c9
commit 7b20a491b4
5 changed files with 50 additions and 1 deletions

View File

@@ -121,6 +121,27 @@ generate notes in the PlantUML diagram from code comments (see also test case [t
{% endif %}
{% endfor %}
```
Currently there are 2 available comment parsers:
* `plain` - default
* `clang`
They can be selected using `comment_parser` config option.
#### `plain` comment parser
This parser provides only 2 options to the Jinja context:
* `comment.raw` - raw comment text, including comment markers such as `///` or `/**`
* `comment.formatted` - formatted entire comment
#### `clang` comment parser
This parser uses Clang comment parsing API to extract commands from the command:
* `comment.raw` - raw comment text, including comment markers such as `///` or `/**`
* `comment.formatted` - formatted entire comment
* `comment.<command>.<N>` - where command is the command used in the command e.g. `brief`, `todo`, etc.
and `N` is the index of the command in the array (each comment can have multiple instances of the
same command such as `\todo`)
* `comment.text` - entire text of the comment that is not attached to any command
* `comment.paragraph.<N>` - array of plain text paragraphs, for instance if you don't use `\brief`
commands but often provide brief description as first sentence of the comment separated with a new line
from the rest of the comment
## Example complete config

View File

@@ -69,6 +69,11 @@ void clang_visitor::visit(
cmt["text"] =
cmt["text"].get<std::string>() + "\n" + paragraph_text;
if (!cmt.contains("paragraph"))
cmt["paragraph"] = inja::json::array();
cmt["paragraph"].push_back(paragraph_text);
}
else if (block_kind == Comment::TextCommentKind) {
// TODO

View File

@@ -24,7 +24,19 @@ diagrams:
note left of {{ alias("C") }} #AABBCC
{{ trim(comment("clanguml::t00050::C").text) }}
end note
- >
{% set cmt=comment("clanguml::t00050::G").paragraph %}
note top of {{ alias("G") }}
{{ trim(cmt.0) }}
end note
note right of {{ alias("G") }}
{{ trim(cmt.1) }}
end note
note bottom of {{ alias("G") }}
{{ trim(cmt.2) }}
end note
- >
{# Render brief comments and todos, if any were written for an element #}
{% for e in diagram.elements %}

View File

@@ -69,7 +69,7 @@ namespace utils {
class D {
};
}
} // namespace utils
/// Mollis pretium lorem primis
enum class E { E1, E2, E3 };
@@ -88,6 +88,14 @@ template <typename T, typename V, int N> class F {
V v;
};
/// This is a short description of class G.
///
/// This is an intermediate description of class G.
///
/// This is a long description of class G.
class G {
};
class NoComment {
};

View File

@@ -49,6 +49,9 @@ TEST_CASE("t00050", "[test-case][class]")
REQUIRE_THAT(puml, !HasNote(_A("E"), "bottom"));
REQUIRE_THAT(puml, !HasNote(_A("NoComment"), "top"));
REQUIRE_THAT(puml, HasNote(_A("F<T,V,int N>"), "top"));
REQUIRE_THAT(puml, HasNote(_A("G"), "top"));
REQUIRE_THAT(puml, HasNote(_A("G"), "bottom"));
REQUIRE_THAT(puml, HasNote(_A("G"), "right"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);