Skip to content

Commit ce5dbc4

Browse files
committed
issue doxygen#11644 Plain '*'-characters in ALIAS argument get removed
1 parent 32af9d5 commit ce5dbc4

File tree

3 files changed

+244
-14
lines changed

3 files changed

+244
-14
lines changed

src/commentcnv.l

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,16 @@ SLASHopt [/]*
839839
<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]* { /* any character not a backslash or new line or } */
840840
copyToOutput(yyscanner,yytext,yyleng);
841841
}
842+
<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n{B}*"//" {
843+
if (yyextra->lastCommentContext!=ReadLine)
844+
{
845+
REJECT;
846+
}
847+
else
848+
{
849+
copyToOutput(yyscanner,yytext,yyleng);
850+
}
851+
}
842852
<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n { /* premature end of comment block */
843853
if (yyextra->lastCommentContext==ReadLine)
844854
{
@@ -854,7 +864,7 @@ SLASHopt [/]*
854864
insertCommentStart(yyscanner);
855865
}
856866
}
857-
<Verbatim>^[ \t]*{CPPC}[/!] {
867+
<Verbatim>^[ \t]*{CPPC}[/!] {
858868
if (yyextra->blockName=="enddot" || yyextra->blockName=="endmsc" || yyextra->blockName=="enduml" || yyextra->blockName.at(0)=='f')
859869
{
860870
// see bug 487871, strip /// from dot images and formulas.
@@ -1344,7 +1354,7 @@ SLASHopt [/]*
13441354
}
13451355
<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]* { // expand alias without arguments
13461356
bool inCppComment = YY_START==ReadLine && yyextra->readLineCtx==SComment;
1347-
bool inCComment = YY_START==CComment;
1357+
bool inCComment = YY_START==CComment && yyextra->blockHeadCol>0;
13481358
replaceAliases(yyscanner,yytext,inCppComment,inCComment);
13491359
}
13501360
<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{B}?{CMD}"ilinebr"{B}{CMD}"ialias{" { // expand alias with arguments
@@ -1364,7 +1374,16 @@ SLASHopt [/]*
13641374
yyextra->lastEscaped=0;
13651375
BEGIN( ReadAliasArgs );
13661376
}
1367-
<ReadAliasArgs>^[ \t]*"*" { // skip leading *
1377+
<ReadAliasArgs>^[ \t]*"*" {
1378+
int indent=computeIndent(yytext)-1;
1379+
if (indent>yyextra->blockHeadCol) // assume part of block marker
1380+
{
1381+
yyextra->aliasString+=yytext;
1382+
}
1383+
else
1384+
{
1385+
// skip leading *
1386+
}
13681387
}
13691388
<ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]* { // skip leading special comments (see bug 618079)
13701389
}
@@ -1413,7 +1432,7 @@ SLASHopt [/]*
14131432
if (yyextra->blockCount==0)
14141433
{
14151434
bool inCppComment = yyextra->lastBlockContext==ReadLine && yyextra->readLineCtx==SComment;
1416-
bool inCComment = yyextra->lastBlockContext==CComment;
1435+
bool inCComment = yyextra->lastBlockContext==CComment && yyextra->blockHeadCol>0;
14171436
replaceAliases(yyscanner,yyextra->aliasString.view(),inCppComment,inCComment);
14181437
BEGIN( yyextra->lastBlockContext );
14191438
}
@@ -1994,25 +2013,22 @@ static void replaceAliases(yyscan_t yyscanner,std::string_view s,bool replaceCpp
19942013
return;
19952014
}
19962015
}
1997-
//printf("replaceAliases(%s)->'%s' replaceComment=%d\n",qPrint(s),qPrint(result),replaceComment);
2016+
//printf("replaceAliases(%s)->'%s' replaceCppComment=%d replaceCComment=%d\n",qPrint(s),qPrint(result),replaceCppComment,replaceCComment);
19982017
if (result!=s)
19992018
{
2000-
QCString spaces;
2001-
if (yyextra->blockHeadCol>1)
2002-
{
2003-
spaces.fill(' ',yyextra->blockHeadCol-1);
2004-
}
2019+
size_t numSpaces = yyextra->blockHeadCol>1 ? yyextra->blockHeadCol-1 : 0;
2020+
std::string spaces(numSpaces,' ');
20052021
if (replaceCppComment) // In case we are replacing a multiline /// comment by a C style comment
20062022
// and we have new lines in the alias argument, we need to place back a /// for each new line
20072023
// to prevent breaking the multiline comment into multiple C style comments
20082024
{
2009-
QCString replacement = "\n"+spaces+"///";
2010-
result = substituteStringView(result,"\n",replacement.view());
2025+
std::string replacement = "\n"+spaces+"///";
2026+
result = substituteStringView(result,"\n",replacement);
20112027
}
20122028
else if (replaceCComment)
20132029
{
2014-
QCString replacement = "\n"+spaces+" * ";
2015-
result = substituteStringView(result,"\n",replacement.view());
2030+
std::string replacement = "\n"+spaces+" * ";
2031+
result = substituteStringView(result,"\n",replacement);
20162032
}
20172033
expAlias.push_back(cmd);
20182034
// add a ialias command to allow expansion of cmd again

testing/112/112__aliases_8cpp.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="" xml:lang="en-US">
3+
<compounddef id="112__aliases_8cpp" kind="file" language="C++">
4+
<compoundname>112_aliases.cpp</compoundname>
5+
<sectiondef kind="func">
6+
<memberdef kind="function" id="112__aliases_8cpp_1a888d87a9f8a6e3e80d5c45e838cc0416" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
7+
<type>void</type>
8+
<definition>void foo1</definition>
9+
<argsstring>()</argsstring>
10+
<name>foo1</name>
11+
<briefdescription>
12+
</briefdescription>
13+
<detaileddescription>
14+
<para>Embedded list</para>
15+
<para>
16+
<itemizedlist>
17+
<listitem>
18+
<para>item1</para>
19+
</listitem>
20+
<listitem>
21+
<para>item2</para>
22+
</listitem>
23+
</itemizedlist>
24+
</para>
25+
<para>Verbatim section includes slashes <verbatim>/// * item1
26+
/// * item2
27+
/// </verbatim></para>
28+
<para>Code section, does not include slashes, but shows comments <programlisting><codeline><highlight class="normal">//<sp/>code<sp/>comment</highlight></codeline><codeline><highlight class="normal">int<sp/>foo();</highlight></codeline></programlisting></para>
29+
<para>Dot graph, does not include slashes <dot>
30+
// dot comment
31+
digraph G {
32+
A -&gt; B
33+
}
34+
</dot>
35+
</para>
36+
<para>
37+
<simplesect kind="note">
38+
<para>
39+
<parblock>
40+
<para>Some text<itemizedlist><listitem><para>item1</para></listitem><listitem><para>item2</para></listitem></itemizedlist>
41+
</para>
42+
<para>More text </para>
43+
</parblock>
44+
</para>
45+
</simplesect>
46+
</para>
47+
<para>
48+
<simplesect kind="note">
49+
<para>
50+
<parblock>
51+
<para>Alias with embedded verbatim section <verbatim>/// Some text
52+
/// </verbatim> </para>
53+
</parblock>
54+
</para>
55+
</simplesect>
56+
</para>
57+
</detaileddescription>
58+
<inbodydescription>
59+
</inbodydescription>
60+
<location file="112_aliases.cpp" line="46" column="10" declfile="112_aliases.cpp" declline="46" declcolumn="10"/>
61+
</memberdef>
62+
<memberdef kind="function" id="112__aliases_8cpp_1a2d19baf875d1256bf3bfe2b8d02f20ea" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
63+
<type>void</type>
64+
<definition>void foo2</definition>
65+
<argsstring>()</argsstring>
66+
<name>foo2</name>
67+
<briefdescription>
68+
</briefdescription>
69+
<detaileddescription>
70+
<para>Embedded list</para>
71+
<para>
72+
<itemizedlist>
73+
<listitem>
74+
<para>item1</para>
75+
</listitem>
76+
<listitem>
77+
<para>item2</para>
78+
</listitem>
79+
</itemizedlist>
80+
</para>
81+
<para>Verbatim section includes slashes <verbatim>* * item1
82+
* * item2
83+
* </verbatim></para>
84+
<para>Code section, does not include slashes, but shows comments <programlisting><codeline><highlight class="normal">//<sp/>code<sp/>comment</highlight></codeline><codeline><highlight class="normal">int<sp/>foo();</highlight></codeline></programlisting></para>
85+
<para>Dot graph, does not include slashes <dot>
86+
// dot comment
87+
digraph G {
88+
A -&gt; B
89+
}
90+
</dot>
91+
</para>
92+
<para>
93+
<simplesect kind="note">
94+
<para>
95+
<parblock>
96+
<para>Some text<itemizedlist><listitem><para>item1</para></listitem><listitem><para>item2</para></listitem></itemizedlist>
97+
</para>
98+
<para>More text </para>
99+
</parblock>
100+
</para>
101+
</simplesect>
102+
</para>
103+
<para>
104+
<simplesect kind="note">
105+
<para>
106+
<parblock>
107+
<para>Alias with embedded verbatim section <verbatim>* Some text
108+
* </verbatim> </para>
109+
</parblock>
110+
</para>
111+
</simplesect>
112+
</para>
113+
</detaileddescription>
114+
<inbodydescription>
115+
</inbodydescription>
116+
<location file="112_aliases.cpp" line="88" column="10" declfile="112_aliases.cpp" declline="88" declcolumn="10"/>
117+
</memberdef>
118+
</sectiondef>
119+
<briefdescription>
120+
</briefdescription>
121+
<detaileddescription>
122+
<para>objective: test multi-line alias expansion in different comment styles config: HAVE_DOT = YES config: ALIASES += "long_note{1}=@note @parblock \1 @endparblock" check: 112__aliases_8cpp.xml </para>
123+
</detaileddescription>
124+
<location file="112_aliases.cpp"/>
125+
</compounddef>
126+
</doxygen>

testing/112_aliases.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/// objective: test multi-line alias expansion in different comment styles
2+
/// config: HAVE_DOT = YES
3+
/// config: ALIASES += "long_note{1}=@note @parblock \1 @endparblock"
4+
/// check: 112__aliases_8cpp.xml
5+
/// @file
6+
7+
/// Embedded list
8+
///
9+
/// * item1
10+
/// * item2
11+
///
12+
/// Verbatim section includes slashes
13+
/// \verbatim
14+
/// * item1
15+
/// * item2
16+
/// \endverbatim
17+
///
18+
/// Code section, does not include slashes, but shows comments
19+
/// \code
20+
/// // code comment
21+
/// int foo();
22+
/// \endcode
23+
///
24+
/// Dot graph, does not include slashes
25+
/// \dot
26+
/// // dot comment
27+
/// digraph G {
28+
/// A -> B
29+
/// }
30+
/// \enddot
31+
///
32+
/// @long_note{
33+
/// Some text
34+
/// * item1
35+
/// * item2
36+
///
37+
/// More text
38+
/// }
39+
///
40+
/// @long_note{
41+
/// Alias with embedded verbatim section
42+
/// \verbatim
43+
/// Some text
44+
/// \endverbatim
45+
/// }
46+
void foo1();
47+
48+
/*! Embedded list
49+
*
50+
* * item1
51+
* * item2
52+
*
53+
* Verbatim section includes slashes
54+
* \verbatim
55+
* * item1
56+
* * item2
57+
* \endverbatim
58+
*
59+
* Code section, does not include slashes, but shows comments
60+
* \code
61+
* // code comment
62+
* int foo();
63+
* \endcode
64+
*
65+
* Dot graph, does not include slashes
66+
* \dot
67+
* // dot comment
68+
* digraph G {
69+
* A -> B
70+
* }
71+
* \enddot
72+
*
73+
* @long_note{
74+
* Some text
75+
* * item1
76+
* * item2
77+
*
78+
* More text
79+
* }
80+
*
81+
* @long_note{
82+
* Alias with embedded verbatim section
83+
* \verbatim
84+
* Some text
85+
* \endverbatim
86+
* }
87+
*/
88+
void foo2();

0 commit comments

Comments
 (0)