Skip to content

Commit 38ee114

Browse files
committed
issue #10935 \snippet{doc} tag in Doxygen v1.11 adds incorrect paragraph with a break before snippet text
1 parent 7673d22 commit 38ee114

File tree

5 files changed

+138
-86
lines changed

5 files changed

+138
-86
lines changed

src/commentcnv.l

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ struct commentcnvYY_state
9898
std::string &outBuf;
9999
int inBufPos = 0;
100100
int col = 0;
101-
int blockHeadCol = 0;
102-
int insertCommentCol = 0;
101+
int blockHeadCol = 0; // column at which the start of a special comment block was found
102+
int insertCommentCol = 0; // column at which an include or snippet command was found
103103
bool mlBrief = FALSE;
104104
int readLineCtx = 0;
105105
int includeCtx = 0;
@@ -305,13 +305,13 @@ SLASHopt [/]*
305305
}
306306
else
307307
{
308-
copyToOutput(yyscanner,yytext,yyleng);
309308
yyextra->nestingCount=0; // Fortran doesn't have an end comment
310309
clearCommentStack(yyscanner); /* to be on the save side */
311310
yyextra->specialComment=true;
312-
yyextra->insertCommentCol=yyextra->col;
313-
yyextra->commentStack.push(yyextra->lineNr);
311+
copyToOutput(yyscanner,yytext,yyleng);
312+
yyextra->blockHeadCol=yyextra->col-2;
314313
BEGIN(CComment);
314+
yyextra->commentStack.push(yyextra->lineNr);
315315
}
316316
}
317317
<Scan>[Cc\*][><!]/.*\n {
@@ -324,13 +324,13 @@ SLASHopt [/]*
324324
/* check for fixed format; we might have some conditional as part of multiline if like C<5 .and. & */
325325
if (yyextra->isFixedForm && (yyextra->col == 0))
326326
{
327-
copyToOutput(yyscanner,yytext,yyleng);
328327
yyextra->nestingCount=0; // Fortran doesn't have an end comment
329328
clearCommentStack(yyscanner); /* to be on the save side */
330329
yyextra->specialComment=true;
331-
yyextra->insertCommentCol=yyextra->col;
332-
yyextra->commentStack.push(yyextra->lineNr);
330+
copyToOutput(yyscanner,yytext,yyleng);
331+
yyextra->blockHeadCol=yyextra->col-1;
333332
BEGIN(CComment);
333+
yyextra->commentStack.push(yyextra->lineNr);
334334
}
335335
else
336336
{
@@ -400,7 +400,7 @@ SLASHopt [/]*
400400
{
401401
while (i<(int)yyleng && yytext[i]=='/') i++;
402402
}
403-
yyextra->blockHeadCol=yyextra->col;
403+
yyextra->blockHeadCol=yyextra->col+1;
404404
copyToOutput(yyscanner,"/**");
405405
if (i<yyleng) replaceAliases(yyscanner,yytext+i);
406406
yyextra->inSpecialComment=TRUE;
@@ -412,21 +412,25 @@ SLASHopt [/]*
412412
<Scan>{CPPC}"##Documentation"{ANYopt}/\n { /* Start of Rational Rose ANSI C++ comment block */
413413
if (yyextra->mlBrief) REJECT;
414414
int i=17; //=strlen("//##Documentation");
415-
yyextra->blockHeadCol=yyextra->col;
415+
yyextra->blockHeadCol=yyextra->col+1;
416416
copyToOutput(yyscanner,"/**");
417417
if (i<yyleng) replaceAliases(yyscanner,yytext+i);
418418
yyextra->inRoseComment=TRUE;
419419
BEGIN(SComment);
420420
}
421421
<Scan>{CPPC}[!\/]/.*\n[ \t]*{CPPC}[|\/][ \t]*[@\\]"}" { // next line contains an end marker, see bug 752712
422422
yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
423+
if (yyextra->inSpecialComment)
424+
{
425+
yyextra->blockHeadCol=yyextra->col+1;
426+
}
423427
copyToOutput(yyscanner,yytext,yyleng);
424428
yyextra->readLineCtx=YY_START;
425429
BEGIN(ReadLine);
426430
}
427431
<Scan>{CPPC}[!/]/.*\n { /* one line special C++ comment */
428432
yyextra->inSpecialComment=true;
429-
yyextra->insertCommentCol=yyextra->col+yyleng;
433+
yyextra->blockHeadCol=yyextra->col+1;
430434
yyextra->insertCppCommentMarker=true;
431435
copyToOutput(yyscanner,yytext,yyleng);
432436
yyextra->readLineCtx=YY_START;
@@ -452,7 +456,7 @@ SLASHopt [/]*
452456
copyToOutput(yyscanner,yytext,yyleng);
453457
if (yyextra->specialComment)
454458
{
455-
yyextra->insertCommentCol=yyextra->col;
459+
yyextra->blockHeadCol=0;
456460
BEGIN(CComment);
457461
}
458462
else
@@ -475,15 +479,15 @@ SLASHopt [/]*
475479
}
476480
else
477481
{
478-
copyToOutput(yyscanner,yytext,yyleng);
479482
yyextra->nestingCount=0; // Python doesn't have an end comment for #
480483
clearCommentStack(yyscanner); /* to be on the save side */
481484
yyextra->specialComment=(int)yyleng==2;
482485
if (yyextra->specialComment)
483486
{
484-
yyextra->insertCommentCol=yyextra->col;
487+
yyextra->blockHeadCol=yyextra->col;
485488
}
486489
yyextra->commentStack.push(yyextra->lineNr);
490+
copyToOutput(yyscanner,yytext,yyleng);
487491
BEGIN(CComment);
488492
}
489493
}
@@ -504,11 +508,13 @@ SLASHopt [/]*
504508
}
505509
else
506510
{
511+
yyextra->specialComment=true;
512+
yyextra->blockHeadCol=yyextra->col;
507513
yyextra->vhdl = TRUE;
508-
copyToOutput(yyscanner,yytext,yyleng);
509514
yyextra->nestingCount=0; // VHDL doesn't have an end comment
510515
clearCommentStack(yyscanner); /* to be on the save side */
511516
yyextra->commentStack.push(yyextra->lineNr);
517+
copyToOutput(yyscanner,yytext,yyleng);
512518
BEGIN(CComment);
513519
}
514520
}
@@ -519,12 +525,12 @@ SLASHopt [/]*
519525
}
520526
else
521527
{
522-
copyToOutput(yyscanner,yytext,yyleng);
523528
yyextra->nestingCount=0; // Fortran doesn't have an end comment
524529
clearCommentStack(yyscanner); /* to be on the save side */
525530
yyextra->specialComment=true;
526-
yyextra->insertCommentCol=yyextra->col;
531+
yyextra->blockHeadCol=yyextra->col;
527532
yyextra->commentStack.push(yyextra->lineNr);
533+
copyToOutput(yyscanner,yytext,yyleng);
528534
BEGIN(CComment);
529535
}
530536
}
@@ -808,6 +814,11 @@ SLASHopt [/]*
808814
copyToOutput(yyscanner,yytext,yyleng);
809815
}
810816
<CComment,CNComment>"*"+[^*\/<\\@\n{\"]* { /* stars without slashes */
817+
if (yyextra->col>yyextra->blockHeadCol)
818+
{
819+
//printf("new blockHeadCol=%d\n",yyextra->blockHeadCol);
820+
yyextra->blockHeadCol=yyextra->col;
821+
}
811822
copyToOutput(yyscanner,yytext,yyleng);
812823
}
813824
<CComment>"'''" |
@@ -1046,40 +1057,16 @@ SLASHopt [/]*
10461057
copyToOutput(yyscanner,yytext,yyleng);
10471058
}
10481059

1049-
<CComment,ReadLine,IncludeFile>{B}{B}{B}{B}[\\@]("include"{OPTS}|"includedoc"{OPTS}*) { // Markdown code section
1050-
if (Config_getBool(MARKDOWN_SUPPORT))
1051-
{
1052-
copyToOutput(yyscanner,yytext,yyleng);
1053-
}
1054-
else
1055-
{
1056-
REJECT;
1057-
}
1058-
}
1059-
<CComment,ReadLine,IncludeFile>{B}{B}{B}{B}[\\@]("snippet"{OPTS}|"snippetdoc"{OPTS}*) { // Markdown code section
1060-
if (Config_getBool(MARKDOWN_SUPPORT))
1061-
{
1062-
copyToOutput(yyscanner,yytext,yyleng);
1063-
}
1064-
else
1065-
{
1066-
REJECT;
1067-
}
1068-
}
10691060
<CComment,ReadLine,IncludeFile>[\\@]("include"{OPTS}|"includedoc"{OPTS}*) {
10701061
if (!parseIncludeOptions(yyscanner,std::string_view{yytext,static_cast<size_t>(yyleng)})) REJECT;
10711062
yyextra->includeCtx = YY_START;
10721063
yyextra->firstIncludeLine = true;
10731064
yyextra->insertCommentCol = yyextra->col;
10741065
if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
10751066
{
1076-
if (yyextra->includeCtx==ReadLine)
1077-
{
1078-
yyextra->insertCommentCol = yyextra->blockHeadCol+3;
1079-
}
10801067
yyextra->insertCppCommentMarker = yyextra->mlBrief;
10811068
}
1082-
//printf("insertCommentCol=%d\n",yyextra->insertCommentCol);
1069+
//printf("blockHeadCol=%d insertCommentCol=%d\n",yyextra->blockHeadCol, yyextra->insertCommentCol);
10831070
BEGIN(IncludeDoc);
10841071
}
10851072
<CComment,ReadLine,IncludeFile>[\\@]("snippet"{OPTS}|"snippetdoc"{OPTS}*) {
@@ -1089,13 +1076,9 @@ SLASHopt [/]*
10891076
yyextra->insertCommentCol = yyextra->col;
10901077
if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
10911078
{
1092-
if (yyextra->includeCtx==ReadLine)
1093-
{
1094-
yyextra->insertCommentCol = yyextra->blockHeadCol+3;
1095-
}
10961079
yyextra->insertCppCommentMarker = yyextra->mlBrief;
10971080
}
1098-
//printf("insertCommentCol=%d\n",yyextra->insertCommentCol);
1081+
//printf("blockHeadCol=%d insertCommentCol=%d\n",yyextra->blockHeadCol, yyextra->insertCommentCol);
10991082
BEGIN(SnippetDoc);
11001083
}
11011084
<IncludeDoc,SnippetDoc>{B}*
@@ -1169,9 +1152,11 @@ SLASHopt [/]*
11691152
{
11701153
yyextra->outBuf+='/';
11711154
yyextra->outBuf+='*';
1155+
yyextra->col+=2;
11721156
if (yyextra->specialComment)
11731157
{
11741158
yyextra->outBuf+='*';
1159+
yyextra->col++;
11751160
}
11761161
}
11771162
}
@@ -1417,7 +1402,7 @@ static void replaceCommentMarker(yyscan_t yyscanner,std::string_view s)
14171402
while (p<len && (c=s[p]) && (c==' ' || c=='\t' || c=='\n'))
14181403
{
14191404
yyextra->outBuf+=c;
1420-
if (c=='\n') yyextra->lineNr++;
1405+
if (c=='\n') { yyextra->lineNr++; yyextra->col=0; } else { yyextra->col++; }
14211406
p++;
14221407
}
14231408
// replace start of comment marker by blanks and the last character by a *
@@ -1441,13 +1426,16 @@ static void replaceCommentMarker(yyscan_t yyscanner,std::string_view s)
14411426
while (blanks>2)
14421427
{
14431428
yyextra->outBuf+=' ';
1429+
yyextra->col++;
14441430
blanks--;
14451431
}
1446-
if (blanks>1) yyextra->outBuf+='*';
1432+
if (blanks>1) { yyextra->outBuf+='*'; yyextra->col++; }
14471433
yyextra->outBuf+=' ';
1434+
yyextra->col++;
14481435
}
14491436
// copy comment line to output
14501437
yyextra->outBuf+=s.substr(p);
1438+
yyextra->col+=s.substr(p).length();
14511439
}
14521440
14531441
static inline int computeIndent(const char *s)
@@ -1563,6 +1551,7 @@ static void handleCondSectionId(yyscan_t yyscanner,const char *expression)
15631551
{
15641552
yyextra->outBuf+='*';
15651553
yyextra->outBuf+='/';
1554+
yyextra->col+=2;
15661555
}
15671556
}
15681557
if (yyextra->readLineCtx==SComment)
@@ -1624,41 +1613,53 @@ static QCString extractBlock(const QCString &text,const QCString &marker,int &bl
16241613
static void insertCommentStart(yyscan_t yyscanner)
16251614
{
16261615
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1627-
//printf("insertCommentStart col=%d mlBrief=%d insertCppCommentMarker=%d\n",yyextra->insertCommentCol,yyextra->mlBrief,yyextra->insertCppCommentMarker);
1628-
if (yyextra->insertCommentCol>=2)
1616+
int startCol=yyextra->blockHeadCol;
1617+
int contentCol=yyextra->insertCommentCol;
1618+
int markerSpace=contentCol-startCol;
1619+
//printf("insertCommentStart startCol=%d contentCol=%d mlBrief=%d insertCppCommentMarker=%d\n",
1620+
// yyextra->blockHeadCol,yyextra->insertCommentCol,yyextra->mlBrief,yyextra->insertCppCommentMarker);
1621+
std::string marker;
1622+
if (yyextra->lang==SrcLangExt::Python) // need to insert #
16291623
{
1630-
int count=yyextra->insertCommentCol;
1631-
std::string marker;
1632-
if (yyextra->lang==SrcLangExt::Python) // need to insert #
1633-
{
1634-
marker="# ";
1635-
}
1636-
else if (yyextra->lang==SrcLangExt::Fortran) // need to insert !!
1637-
{
1638-
marker="!! ";
1639-
}
1640-
else if (yyextra->lang==SrcLangExt::Markdown)
1641-
{
1642-
marker=" ";
1643-
}
1644-
else if (yyextra->insertCppCommentMarker) // need to insert ///
1645-
{
1646-
count--;
1647-
marker="/// ";
1648-
}
1649-
else // need to insert *
1650-
{
1651-
marker="* ";
1652-
}
1653-
count-=marker.length();
1654-
for (int i=0;i<count;i++)
1624+
marker="# ";
1625+
}
1626+
else if (yyextra->lang==SrcLangExt::Fortran) // need to insert !!
1627+
{
1628+
marker="!! ";
1629+
}
1630+
else if (yyextra->lang==SrcLangExt::Markdown)
1631+
{
1632+
marker=" ";
1633+
}
1634+
else if (yyextra->insertCppCommentMarker) // need to insert ///
1635+
{
1636+
marker="/// ";
1637+
if (startCol>0)
16551638
{
1656-
copyToOutput(yyscanner," ");
1639+
// insert `///` instead of '* '
1640+
startCol--;
1641+
markerSpace++;
16571642
}
1658-
// first line is placed after \ilinebr, so omit the *
1659-
copyToOutput(yyscanner,yyextra->firstIncludeLine ? " " : marker);
1660-
yyextra->firstIncludeLine = false;
16611643
}
1644+
else // need to insert *
1645+
{
1646+
marker="* ";
1647+
}
1648+
int i=0;
1649+
for (;i<startCol;i++)
1650+
{
1651+
copyToOutput(yyscanner," ");
1652+
}
1653+
if (static_cast<int>(marker.length())<=markerSpace && !yyextra->firstIncludeLine)
1654+
{
1655+
copyToOutput(yyscanner,marker);
1656+
i+=marker.length();
1657+
}
1658+
for (;i<contentCol;i++)
1659+
{
1660+
copyToOutput(yyscanner," ");
1661+
}
1662+
yyextra->firstIncludeLine = false;
16621663
}
16631664
16641665
static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCString &blockId)
@@ -1861,9 +1862,9 @@ static void replaceComment(yyscan_t yyscanner,int offset)
18611862
}
18621863
else
18631864
{
1864-
//printf("replaceComment(%s)\n",yytext);
18651865
int i=computeIndent(&yytext[offset]);
1866-
if (i==yyextra->blockHeadCol)
1866+
//printf("i=%d blockHeadCol=%d\n",i,yyextra->blockHeadCol);
1867+
if (i==yyextra->blockHeadCol || i+1==yyextra->blockHeadCol)
18671868
{
18681869
replaceCommentMarker(yyscanner,std::string_view(yytext,yyleng));
18691870
}

src/fortranscanner.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ private {
15291529
}
15301530
<DocBlock>"\\ilinebr "{BS} {
15311531
QCString indent;
1532-
int extraSpaces = std::max(0,static_cast<int>(yyleng-9-yyextra->curIndent-1));
1532+
int extraSpaces = std::max(0,static_cast<int>(yyleng-9-yyextra->curIndent-2));
15331533
indent.fill(' ',extraSpaces);
15341534
//printf("extraSpaces=%d\n",extraSpaces);
15351535
yyextra->docBlock += "\\ilinebr ";

0 commit comments

Comments
 (0)