Skip to content

Commit b6018c3

Browse files
committed
Incorrect handling of \include{doc} for Fortran
Having: **foo.f** ``` !> \file !> !> The level 1 !> !> provoking an error \error_5_1_ftn !> !> \include{doc} kaboom_ftn.md !> \brief the fie 1 !> \details the fie 1 !> \error_11_ftn subroutine ftn_1 end subroutine ftn_1 ``` **kaboom_ftn.md** ``` # Uh-oh 1 !> !> Seems Doxygen isn't playing nice with slightly longer paths... \error_3 ``` gives the warning: ``` Error in file .../foo.f line: 17, state: 10(ModuleBody) ``` Due to the fact that the end include line is not a valid Fortran comment line (missing the `!>`) (handling in Fortran scanner analogous to the handling in scanner.l from #10490)
1 parent 351dba6 commit b6018c3

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

src/commentcnv.l

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct commentcnv_FileState
7474
YY_BUFFER_STATE bufState = 0;
7575
QCString fileName;
7676
QCString oldFileName;
77+
QCString oldIncPrefix;
7778
int oldState = 0;
7879
BufStr fileBuf;
7980
const BufStr *oldFileBuf = nullptr;
@@ -107,6 +108,7 @@ struct commentcnvYY_state
107108
int charContext = 0;
108109
int javaBlock = 0;
109110
bool specialComment = FALSE;
111+
QCString incPrefix;
110112

111113
QCString aliasString;
112114
int blockCount = 0;
@@ -269,7 +271,7 @@ SLASHopt [/]*
269271
yyextra->commentStack.push(yyextra->lineNr);
270272
}
271273
}
272-
<Scan>![><!]/.*\n {
274+
<Scan>{B}*![><!]/.*\n {
273275
if (yyextra->lang!=SrcLangExt_Fortran)
274276
{
275277
REJECT;
@@ -280,6 +282,7 @@ SLASHopt [/]*
280282
yyextra->nestingCount=0; // Fortran doesn't have an end comment
281283
clearCommentStack(yyscanner); /* to be on the save side */
282284
BEGIN(CComment);
285+
yyextra->incPrefix = yytext;
283286
yyextra->commentStack.push(yyextra->lineNr);
284287
}
285288
}
@@ -297,6 +300,7 @@ SLASHopt [/]*
297300
yyextra->nestingCount=0; // Fortran doesn't have an end comment
298301
clearCommentStack(yyscanner); /* to be on the save side */
299302
BEGIN(CComment);
303+
yyextra->incPrefix = yytext;
300304
yyextra->commentStack.push(yyextra->lineNr);
301305
}
302306
else
@@ -455,7 +459,7 @@ SLASHopt [/]*
455459
yyextra->commentStack.push(yyextra->lineNr);
456460
}
457461
}
458-
<Scan>![><!] {
462+
<Scan>{B}*![><!] {
459463
if (yyextra->lang!=SrcLangExt_Fortran)
460464
{
461465
REJECT;
@@ -466,6 +470,7 @@ SLASHopt [/]*
466470
yyextra->nestingCount=0; // Fortran doesn't have an end comment
467471
clearCommentStack(yyscanner); /* to be on the save side */
468472
BEGIN(CComment);
473+
yyextra->incPrefix = yytext;
469474
yyextra->commentStack.push(yyextra->lineNr);
470475
}
471476
}
@@ -1110,8 +1115,10 @@ SLASHopt [/]*
11101115
yyextra->inBuf = fs->oldFileBuf;
11111116
yyextra->inBufPos = fs->oldFileBufPos;
11121117
yyextra->includeCtx = fs->oldIncludeCtx;
1113-
QCString lineStr=" \\ilinebr\\ifile \""+yyextra->fileName+"\" \\iline "+QCString().setNum(yyextra->lineNr)+" ";
1118+
yyextra->incPrefix = fs->oldIncPrefix;
1119+
QCString lineStr=yyextra->incPrefix + " \\ilinebr\\ifile \""+yyextra->fileName+"\" \\iline "+QCString().setNum(yyextra->lineNr)+" ";
11141120
copyToOutput(yyscanner,lineStr.data(),lineStr.length());
1121+
yyextra->incPrefix = "";
11151122
yyextra->includeStack.pop_back();
11161123
//printf("<<EOF>> switch back to %s line %d inbufPos=%d outbufPos=%d\n",
11171124
// qPrint(yyextra->fileName),yyextra->lineNr,yyextra->inBufPos,yyextra->outBuf.curPos());
@@ -1411,6 +1418,7 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
14111418
fs->oldFileBuf = yyextra->inBuf;
14121419
fs->oldFileBufPos = yyextra->inBufPos;
14131420
fs->oldIncludeCtx = yyextra->includeCtx;
1421+
fs->oldIncPrefix = yyextra->incPrefix;
14141422
yy_switch_to_buffer(yy_create_buffer(0, YY_BUF_SIZE, yyscanner),yyscanner);
14151423
yyextra->fileName = absFileName;
14161424
yyextra->lineNr = lineNr;

src/fortranscanner.l

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static inline const char *getLexerFILE() {return __FILE__;}
262262

263263
//-----------------------------------------------------------------------------
264264
//-----------------------------------------------------------------------------
265+
CMD ("\\"|"@")
265266
IDSYM [a-z_A-Z0-9]
266267
NOTIDSYM [^a-z_A-Z0-9]
267268
SEPARATE [:, \t]
@@ -301,6 +302,14 @@ CONTAINS CONTAINS
301302
PREFIX ((NON_)?RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,4}((NON_)?RECURSIVE|IMPURE|PURE|ELEMENTAL)?
302303
SCOPENAME ({ID}{BS}"::"{BS})*
303304

305+
LINENR {B}*[1-9][0-9]*
306+
FILEICHAR [a-z_A-Z0-9\\:\\\/\-\+=&#@]
307+
FILEECHAR [a-z_A-Z0-9\-\+=&#@]
308+
FILECHARS {FILEICHAR}*{FILEECHAR}+
309+
HFILEMASK {FILEICHAR}*("."{FILEICHAR}+)+{FILECHARS}*
310+
VFILEMASK {FILECHARS}("."{FILECHARS})*
311+
FILEMASK {VFILEMASK}|{HFILEMASK}
312+
304313
%option noyywrap
305314
%option stack
306315
%option caseless
@@ -1397,13 +1406,44 @@ private {
13971406
//cout << "start DocBlock " << endl;
13981407
}
13991408

1400-
<DocBlock>.* { // contents of yyextra->current comment line
1409+
<DocBlock>{CMD}"ifile"{B}+"\""[^\n\"]+"\"" {
1410+
yyextra->fileName = &yytext[6];
1411+
yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1412+
yyextra->fileName = yyextra->fileName.mid(1,yyextra->fileName.length()-2);
1413+
yyextra->docBlock+=yytext;
1414+
}
1415+
<DocBlock>{CMD}"ifile"{B}+{FILEMASK} {
1416+
yyextra->fileName = &yytext[6];
1417+
yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1418+
yyextra->docBlock+=yytext;
1419+
}
1420+
<DocBlock>{CMD}"iline"{LINENR}/[\n\.] |
1421+
<DocBlock>{CMD}"iline"{LINENR}{B} {
1422+
bool ok = false;
1423+
int nr = QCString(&yytext[6]).toInt(&ok);
1424+
if (!ok)
1425+
{
1426+
warn(yyextra->fileName,yyextra->lineNr,"Invalid line number '%s' for iline command",yytext);
1427+
}
1428+
else
1429+
{
1430+
yyextra->lineNr = nr;
1431+
}
1432+
yyextra->docBlock+=yytext;
1433+
}
1434+
<DocBlock>({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command
1435+
yyextra->docBlock+=yytext;
1436+
}
1437+
<DocBlock>[^\\@\n]* { // contents of yyextra->current comment line
14011438
yyextra->docBlock+=yytext;
14021439
}
14031440
<DocBlock>"\n"{BS}"!"(">"|"!"+) { // comment block (next line is also comment line)
14041441
yyextra->docBlock+="\n"; // \n is necessary for lists
14051442
newLine(yyscanner);
14061443
}
1444+
<DocBlock>{CMD} {
1445+
yyextra->docBlock+=yytext;
1446+
}
14071447
<DocBlock>"\n" { // comment block ends at the end of this line
14081448
//cout <<"3=========> comment block : "<< yyextra->docBlock << endl;
14091449
yyextra->colNr -= 1;

0 commit comments

Comments
 (0)