Skip to content

Commit 1f5e54c

Browse files
committed
issue #10702 @include{doc}
1 parent 42d0f98 commit 1f5e54c

File tree

1 file changed

+75
-49
lines changed

1 file changed

+75
-49
lines changed

src/commentcnv.l

Lines changed: 75 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ struct commentcnvYY_state
107107
int javaBlock = 0;
108108
bool specialComment = FALSE;
109109
bool inVerbatim = false;
110-
QCString incPrefix;
110+
bool firstIncludeLine = false;
111+
bool insertCppCommentMarker = false;
111112
QCString aliasCmd;
112113
QCString aliasString;
113114
int blockCount = 0;
@@ -251,7 +252,6 @@ SLASHopt [/]*
251252
clearCommentStack(yyscanner); /* to be on the save side */
252253
copyToOutput(yyscanner,yytext,yyleng);
253254
BEGIN(CComment);
254-
yyextra->incPrefix = "";
255255
yyextra->commentStack.push(yyextra->lineNr);
256256
}
257257
}
@@ -273,7 +273,6 @@ SLASHopt [/]*
273273
clearCommentStack(yyscanner); /* to be on the save side */
274274
copyToOutput(yyscanner,yytext,yyleng);
275275
BEGIN(CComment);
276-
yyextra->incPrefix = "";
277276
yyextra->commentStack.push(yyextra->lineNr);
278277
}
279278
}
@@ -287,9 +286,10 @@ SLASHopt [/]*
287286
copyToOutput(yyscanner,yytext,yyleng);
288287
yyextra->nestingCount=0; // Fortran doesn't have an end comment
289288
clearCommentStack(yyscanner); /* to be on the save side */
290-
BEGIN(CComment);
291-
yyextra->incPrefix = yytext;
289+
yyextra->specialComment=true;
290+
yyextra->insertCommentCol=yyextra->col;
292291
yyextra->commentStack.push(yyextra->lineNr);
292+
BEGIN(CComment);
293293
}
294294
}
295295
<Scan>[Cc\*][><!]/.*\n {
@@ -305,9 +305,10 @@ SLASHopt [/]*
305305
copyToOutput(yyscanner,yytext,yyleng);
306306
yyextra->nestingCount=0; // Fortran doesn't have an end comment
307307
clearCommentStack(yyscanner); /* to be on the save side */
308-
BEGIN(CComment);
309-
yyextra->incPrefix = yytext;
308+
yyextra->specialComment=true;
309+
yyextra->insertCommentCol=yyextra->col;
310310
yyextra->commentStack.push(yyextra->lineNr);
311+
BEGIN(CComment);
311312
}
312313
else
313314
{
@@ -403,6 +404,8 @@ SLASHopt [/]*
403404
}
404405
<Scan>{CPPC}[!/]/.*\n { /* one line special C++ comment */
405406
yyextra->inSpecialComment=true;
407+
yyextra->insertCommentCol=yyextra->col+yyleng;
408+
yyextra->insertCppCommentMarker=true;
406409
copyToOutput(yyscanner,yytext,yyleng);
407410
yyextra->readLineCtx=YY_START;
408411
BEGIN(ReadLine);
@@ -426,9 +429,14 @@ SLASHopt [/]*
426429
clearCommentStack(yyscanner); /* to be on the save side */
427430
copyToOutput(yyscanner,yytext,yyleng);
428431
if (yyextra->specialComment)
432+
{
433+
yyextra->insertCommentCol=yyextra->col;
429434
BEGIN(CComment);
435+
}
430436
else
437+
{
431438
BEGIN(CNComment);
439+
}
432440
yyextra->commentStack.push(yyextra->lineNr);
433441
}
434442
<Scan>"#"[^\n]*\n {
@@ -448,8 +456,13 @@ SLASHopt [/]*
448456
copyToOutput(yyscanner,yytext,yyleng);
449457
yyextra->nestingCount=0; // Python doesn't have an end comment for #
450458
clearCommentStack(yyscanner); /* to be on the save side */
451-
BEGIN(CComment);
459+
yyextra->specialComment=(int)yyleng==2;
460+
if (yyextra->specialComment)
461+
{
462+
yyextra->insertCommentCol=yyextra->col;
463+
}
452464
yyextra->commentStack.push(yyextra->lineNr);
465+
BEGIN(CComment);
453466
}
454467
}
455468
<Scan>"--"[^!][^\n]* {
@@ -473,8 +486,8 @@ SLASHopt [/]*
473486
copyToOutput(yyscanner,yytext,yyleng);
474487
yyextra->nestingCount=0; // VHDL doesn't have an end comment
475488
clearCommentStack(yyscanner); /* to be on the save side */
476-
BEGIN(CComment);
477489
yyextra->commentStack.push(yyextra->lineNr);
490+
BEGIN(CComment);
478491
}
479492
}
480493
<Scan>{B}*![><!] {
@@ -487,9 +500,10 @@ SLASHopt [/]*
487500
copyToOutput(yyscanner,yytext,yyleng);
488501
yyextra->nestingCount=0; // Fortran doesn't have an end comment
489502
clearCommentStack(yyscanner); /* to be on the save side */
490-
BEGIN(CComment);
491-
yyextra->incPrefix = yytext;
503+
yyextra->specialComment=true;
504+
yyextra->insertCommentCol=yyextra->col;
492505
yyextra->commentStack.push(yyextra->lineNr);
506+
BEGIN(CComment);
493507
}
494508
}
495509
<CComment,CNComment,ReadLine,IncludeFile>{MAILADDR} |
@@ -684,7 +698,10 @@ SLASHopt [/]*
684698
}
685699
<Verbatim,VerbatimCode>\n { /* new line in verbatim block */
686700
copyToOutput(yyscanner,yytext,yyleng);
687-
insertCommentStart(yyscanner);
701+
if (yyextra->lastCommentContext == IncludeFile)
702+
{
703+
insertCommentStart(yyscanner);
704+
}
688705
}
689706
<Verbatim>^[ \t]*{CPPC}[/!] {
690707
if (yyextra->blockName=="enddot" || yyextra->blockName=="endmsc" || yyextra->blockName=="enduml" || yyextra->blockName.at(0)=='f')
@@ -765,17 +782,6 @@ SLASHopt [/]*
765782
copyToOutput(yyscanner,yytext,yyleng);
766783
}
767784
768-
<CComment>{B}*"#"("#")? {
769-
if (yyextra->lang!=SrcLangExt::Python)
770-
{
771-
REJECT;
772-
}
773-
else
774-
{
775-
yyextra->incPrefix = yytext;
776-
copyToOutput(yyscanner,yytext,yyleng);
777-
}
778-
}
779785
<CComment,CNComment>[^ `~<\\!@*\n{\"'\/]* { /* anything that is not a '*' or command */
780786
copyToOutput(yyscanner,yytext,yyleng);
781787
}
@@ -918,7 +924,7 @@ SLASHopt [/]*
918924
BEGIN(SkipString);
919925
}
920926
*/
921-
<CComment,CNComment>. {
927+
<CComment,CNComment>. {
922928
copyToOutput(yyscanner,yytext,yyleng);
923929
}
924930
<SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n {
@@ -936,8 +942,8 @@ SLASHopt [/]*
936942
/* See Bug 752712: end the multiline comment when finding a @} or \} command */
937943
copyToOutput(yyscanner," */");
938944
copyToOutput(yyscanner,yytext,yyleng);
939-
yyextra->inSpecialComment=FALSE;
940-
yyextra->inRoseComment=FALSE;
945+
yyextra->inSpecialComment=false;
946+
yyextra->inRoseComment=false;
941947
BEGIN(Scan);
942948
}
943949
<SComment>\n[ \t]*{CPPC}"/"[^\/\n]/.*\n {
@@ -988,6 +994,7 @@ SLASHopt [/]*
988994
copyToOutput(yyscanner,yytext,yyleng);
989995
yyextra->inSpecialComment=FALSE;
990996
yyextra->inRoseComment=FALSE;
997+
yyextra->insertCppCommentMarker=false;
991998
yyextra->readLineCtx = Scan; // reset, otherwise there will be problems with:
992999
// static void handleCondSectionId
9931000
BEGIN(Scan);
@@ -1006,6 +1013,7 @@ SLASHopt [/]*
10061013
}
10071014
<ReadLine,CopyLine>{RLopt}/\n {
10081015
copyToOutput(yyscanner,yytext,yyleng);
1016+
yyextra->insertCppCommentMarker=false;
10091017
BEGIN(yyextra->readLineCtx);
10101018
}
10111019
<CComment,CNComment,ReadLine>"\\<" { /* escaped html comment */
@@ -1016,10 +1024,22 @@ SLASHopt [/]*
10161024
}
10171025
<CComment,ReadLine,IncludeFile>[\\@]("include{"{B}*"doc"{B}*"}"|"includedoc") {
10181026
yyextra->includeCtx = YY_START;
1027+
yyextra->firstIncludeLine = true;
1028+
if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1029+
{
1030+
yyextra->insertCommentCol = yyextra->blockHeadCol+3;
1031+
yyextra->insertCppCommentMarker = yyextra->mlBrief;
1032+
}
10191033
BEGIN(IncludeDoc);
10201034
}
10211035
<CComment,ReadLine,IncludeFile>[\\@]("snippet{"{B}*"doc"{B}*"}"|"snippetdoc") {
10221036
yyextra->includeCtx = YY_START;
1037+
yyextra->firstIncludeLine = true;
1038+
if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1039+
{
1040+
yyextra->insertCommentCol = yyextra->blockHeadCol+3;
1041+
yyextra->insertCppCommentMarker = yyextra->mlBrief;
1042+
}
10231043
BEGIN(SnippetDoc);
10241044
}
10251045
<IncludeDoc,SnippetDoc>{B}*
@@ -1029,14 +1049,6 @@ SLASHopt [/]*
10291049
{
10301050
fileName=fileName.mid(1,fileName.length()-2); // strip quotes
10311051
}
1032-
if (yyextra->includeCtx==ReadLine)
1033-
{
1034-
yyextra->insertCommentCol = yyextra->blockHeadCol+3;
1035-
}
1036-
else
1037-
{
1038-
yyextra->insertCommentCol = 0;
1039-
}
10401052
if (readIncludeFile(yyscanner,fileName,""))
10411053
{
10421054
BEGIN(IncludeFile);
@@ -1054,14 +1066,6 @@ SLASHopt [/]*
10541066
fileName=fileName.left(i).stripWhiteSpace();
10551067
//printf("yytext='%s' i=%d fileName='%s' blockId='%s'\n",yytext,i,qPrint(fileName),qPrint(blockId));
10561068
if (fileName == "this") fileName=yyextra->fileName;
1057-
if (yyextra->includeCtx==ReadLine)
1058-
{
1059-
yyextra->insertCommentCol = yyextra->blockHeadCol+3;
1060-
}
1061-
else
1062-
{
1063-
yyextra->insertCommentCol = 0;
1064-
}
10651069
if (readIncludeFile(yyscanner,fileName,blockId))
10661070
{
10671071
BEGIN(IncludeFile);
@@ -1192,6 +1196,7 @@ SLASHopt [/]*
11921196
}
11931197
<CopyLine>\n {
11941198
copyToOutput(yyscanner,yytext,yyleng);
1199+
yyextra->insertCppCommentMarker=false;
11951200
BEGIN(yyextra->readLineCtx);
11961201
}
11971202
<ReadLine>``` {
@@ -1222,6 +1227,7 @@ SLASHopt [/]*
12221227
}
12231228
if (yyextra->includeStack.empty())
12241229
{
1230+
yyextra->insertCppCommentMarker=false;
12251231
yyterminate();
12261232
}
12271233
else // switch back to parent file
@@ -1236,10 +1242,8 @@ SLASHopt [/]*
12361242
yyextra->inBuf = fs->oldFileBuf;
12371243
yyextra->inBufPos = fs->oldFileBufPos;
12381244
yyextra->includeCtx = fs->oldIncludeCtx;
1239-
yyextra->incPrefix = fs->oldIncPrefix;
1240-
QCString lineStr=yyextra->incPrefix + " \\ilinebr \\ifile \""+yyextra->fileName+"\" \\iline "+QCString().setNum(yyextra->lineNr)+" ";
1245+
QCString lineStr= " \\ilinebr \\ifile \""+yyextra->fileName+"\" \\iline "+QCString().setNum(yyextra->lineNr)+" ";
12411246
copyToOutput(yyscanner,lineStr.view());
1242-
yyextra->incPrefix = "";
12431247
yyextra->includeStack.pop_back();
12441248
//printf("<<EOF>> switch back to %s line %d inbufPos=%d outbufPos=%d\n",
12451249
// qPrint(yyextra->fileName),yyextra->lineNr,yyextra->inBufPos,yyextra->outBuf.curPos());
@@ -1468,13 +1472,35 @@ static QCString extractBlock(const QCString &text,const QCString &marker,int &bl
14681472
static void insertCommentStart(yyscan_t yyscanner)
14691473
{
14701474
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1471-
if (yyextra->insertCommentCol>=3)
1475+
//printf("insertCommentStart col=%d mlBrief=%d insertCppCommentMarker=%d\n",yyextra->insertCommentCol,yyextra->mlBrief,yyextra->insertCppCommentMarker);
1476+
if (yyextra->insertCommentCol>=2)
14721477
{
1473-
for (int i=0;i<yyextra->insertCommentCol-3;i++)
1478+
int count=yyextra->insertCommentCol-2;
1479+
std::string marker;
1480+
if (yyextra->lang==SrcLangExt::Python) // need to insert #
1481+
{
1482+
marker="# ";
1483+
}
1484+
else if (yyextra->lang==SrcLangExt::Fortran) // need to insert !!
1485+
{
1486+
marker="!! ";
1487+
}
1488+
else if (yyextra->insertCppCommentMarker) // need to insert ///
1489+
{
1490+
count--;
1491+
marker="/// ";
1492+
}
1493+
else // need to insert *
1494+
{
1495+
marker="* ";
1496+
}
1497+
for (int i=0;i<count;i++)
14741498
{
14751499
copyToOutput(yyscanner," ");
14761500
}
1477-
copyToOutput(yyscanner," * ");
1501+
// first line is placed after \ilinebr, so omit the *
1502+
copyToOutput(yyscanner,yyextra->firstIncludeLine ? " " : marker);
1503+
yyextra->firstIncludeLine = false;
14781504
}
14791505
}
14801506

@@ -1553,7 +1579,6 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
15531579
fs->oldFileBuf = yyextra->inBuf;
15541580
fs->oldFileBufPos = yyextra->inBufPos;
15551581
fs->oldIncludeCtx = yyextra->includeCtx;
1556-
fs->oldIncPrefix = yyextra->incPrefix;
15571582
yy_switch_to_buffer(yy_create_buffer(0, YY_BUF_SIZE, yyscanner),yyscanner);
15581583
yyextra->fileName = absFileName;
15591584
yyextra->lineNr = lineNr;
@@ -1704,6 +1729,7 @@ void convertCppComments(const std::string &inBuf,std::string &outBuf,const std::
17041729
yyextra->lang = getLanguageFromFileName(fileName);
17051730
yyextra->pythonDocString = FALSE;
17061731
yyextra->lineNr = 1;
1732+
yyextra->insertCppCommentMarker=false;
17071733
yyextra->expandedAliases.clear();
17081734
while (!yyextra->condStack.empty()) yyextra->condStack.pop();
17091735
clearCommentStack(yyscanner);

0 commit comments

Comments
 (0)