Skip to content

Commit b314635

Browse files
author
Dimitri van Heesch
committed
Merge branch 'feature/bug_593642' of https://github.com/albert-github/doxygen into albert-github-feature/bug_593642
2 parents 9be2dc8 + 4cad0c9 commit b314635

File tree

1 file changed

+110
-29
lines changed

1 file changed

+110
-29
lines changed

src/pycode.l

Lines changed: 110 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ static int g_stringContext;
9090

9191
static QValueStack<uint> g_indents; //!< Tracks indentation levels for scoping in python
9292

93+
static QCString g_docBlock; //!< contents of all lines of a documentation block
94+
static bool g_endComment;
95+
9396
static void endFontClass();
9497
static void adjustScopesAndSuites(unsigned indentLength);
9598

@@ -361,11 +364,13 @@ static void startCodeLine()
361364
Definition *d = g_sourceFileDef->getSourceDefinition(g_yyLineNr);
362365
//printf("startCodeLine %d d=%p\n",g_yyLineNr,d);
363366
//g_code->startLineNumber();
367+
364368
if (!g_includeCodeFragment && d && d->isLinkableInProject())
365369
{
366370
g_currentDefinition = d;
367371
g_currentMemberDef = g_sourceFileDef->getSourceMember(g_yyLineNr);
368372
//g_insideBody = FALSE;
373+
g_endComment = FALSE;
369374
g_searchingForBody = TRUE;
370375
g_realScope = d->name().copy();
371376
g_classScope = d->name().copy();
@@ -467,13 +472,34 @@ static void writeMultiLineCodeLink(CodeOutputInterface &ol,
467472
}
468473
}
469474

475+
static void startFontClass(const char *s)
476+
{
477+
// if font class is already set don't stop and start it.
478+
// strcmp does not like null pointers as input.
479+
if (!g_currentFontClass || !s || strcmp(g_currentFontClass,s))
480+
{
481+
endFontClass();
482+
g_code->startFontClass(s);
483+
g_currentFontClass=s;
484+
}
485+
}
486+
487+
static void endFontClass()
488+
{
489+
if (g_currentFontClass)
490+
{
491+
g_code->endFontClass();
492+
g_currentFontClass=0;
493+
}
494+
}
470495

471496
static void codifyLines(char *text)
472497
{
473498
//printf("codifyLines(%d,\"%s\")\n",g_yyLineNr,text);
474499
char *p=text,*sp=p;
475500
char c;
476501
bool done=FALSE;
502+
const char * tmp_currentFontClass = g_currentFontClass;
477503
while (!done)
478504
{
479505
sp=p;
@@ -483,7 +509,15 @@ static void codifyLines(char *text)
483509
g_yyLineNr++;
484510
*(p-1)='\0';
485511
g_code->codify(sp);
486-
nextCodeLine();
512+
endCodeLine();
513+
if (g_yyLineNr<g_inputLines)
514+
{
515+
startCodeLine();
516+
}
517+
if (tmp_currentFontClass)
518+
{
519+
startFontClass(tmp_currentFontClass);
520+
}
487521
}
488522
else
489523
{
@@ -493,6 +527,13 @@ static void codifyLines(char *text)
493527
}
494528
}
495529

530+
static void codifyLines(QCString str)
531+
{
532+
char *tmp= (char *) malloc(str.length()+1);
533+
strcpy(tmp, str);
534+
codifyLines(tmp);
535+
free(tmp);
536+
}
496537

497538
static bool getLinkInScope(const QCString &c, // scope
498539
const QCString &m, // member
@@ -796,22 +837,6 @@ static void findMemberLink(CodeOutputInterface &ol,char *symName)
796837
codify(symName);
797838
}
798839

799-
static void startFontClass(const char *s)
800-
{
801-
endFontClass();
802-
g_code->startFontClass(s);
803-
g_currentFontClass=s;
804-
}
805-
806-
static void endFontClass()
807-
{
808-
if (g_currentFontClass)
809-
{
810-
g_code->endFontClass();
811-
g_currentFontClass=0;
812-
}
813-
}
814-
815840
#undef YY_INPUT
816841
#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
817842

@@ -842,7 +867,7 @@ PARAMNONEMPTY [^ \t\n():]
842867
IDENTIFIER ({LETTER}|"_")({LETTER}|{DIGIT}|"_")*
843868
BORDER ([^A-Za-z0-9])
844869

845-
POUNDCOMMENT "#".*
870+
POUNDCOMMENT "##"
846871
847872
TRISINGLEQUOTE "'''"
848873
TRIDOUBLEQUOTE "\"\"\""
@@ -938,7 +963,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
938963

939964

940965
%option noyywrap
941-
%option nounput
966+
%option stack
942967

943968
%x Body
944969

@@ -960,6 +985,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
960985
%x DoubleQuoteString
961986
%x TripleString
962987

988+
%x DocBlock
963989
%%
964990

965991
<Body,Suite>{
@@ -1176,11 +1202,16 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
11761202

11771203

11781204
{POUNDCOMMENT} {
1179-
// This eats EVERYTHING
1180-
// except the newline
1181-
startFontClass("comment");
1182-
codifyLines(yytext);
1183-
endFontClass();
1205+
if (YY_START==SingleQuoteString ||
1206+
YY_START==DoubleQuoteString ||
1207+
YY_START==TripleString
1208+
)
1209+
{
1210+
REJECT;
1211+
}
1212+
yy_push_state(YY_START);
1213+
BEGIN(DocBlock);
1214+
g_docBlock=yytext;
11841215
}
11851216

11861217
{NEWLINE} {
@@ -1349,6 +1380,28 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
13491380
codify(yytext);
13501381
BEGIN(DoubleQuoteString);
13511382
}
1383+
<DocBlock>.* { // contents of current comment line
1384+
g_docBlock+=yytext;
1385+
}
1386+
<DocBlock>"\n"{B}("#") { // comment block (next line is also comment line)
1387+
g_docBlock+=yytext;
1388+
}
1389+
<DocBlock>{NEWLINE} { // comment block ends at the end of this line
1390+
// remove special comment (default config)
1391+
if (Config_getBool("STRIP_CODE_COMMENTS"))
1392+
{
1393+
g_yyLineNr+=((QCString)g_docBlock).contains('\n');
1394+
g_endComment=TRUE;
1395+
}
1396+
else // do not remove comment
1397+
{
1398+
startFontClass("comment");
1399+
codifyLines(g_docBlock);
1400+
endFontClass();
1401+
}
1402+
unput(*yytext);
1403+
yy_pop_state();
1404+
}
13521405
<*>{POUNDCOMMENT} {
13531406
if (YY_START==SingleQuoteString ||
13541407
YY_START==DoubleQuoteString ||
@@ -1357,14 +1410,31 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
13571410
{
13581411
REJECT;
13591412
}
1360-
// This eats EVERYTHING
1361-
// except the newline
1413+
yy_push_state(YY_START);
1414+
BEGIN(DocBlock);
1415+
g_docBlock=yytext;
1416+
}
1417+
<*>"#".* { // normal comment
1418+
if (YY_START==SingleQuoteString ||
1419+
YY_START==DoubleQuoteString ||
1420+
YY_START==TripleString
1421+
)
1422+
{
1423+
REJECT;
1424+
}
13621425
startFontClass("comment");
1363-
codifyLines(yytext);
1364-
endFontClass();
1426+
codifyLines(yytext);
1427+
endFontClass();
13651428
}
13661429
<*>{NEWLINE} {
1367-
codifyLines(yytext);
1430+
if (g_endComment)
1431+
{
1432+
g_endComment=FALSE;
1433+
}
1434+
else
1435+
{
1436+
codifyLines(yytext);
1437+
}
13681438
//printf("[pycode] %d NEWLINE [line %d] no match\n",
13691439
// YY_START, g_yyLineNr);
13701440

@@ -1385,6 +1455,17 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
13851455
BEGIN(Body);
13861456
}
13871457

1458+
<*><<EOF>> {
1459+
if (YY_START == DocBlock) {
1460+
if (!Config_getBool("STRIP_CODE_COMMENTS"))
1461+
{
1462+
startFontClass("comment");
1463+
codifyLines(g_docBlock);
1464+
endFontClass();
1465+
}
1466+
}
1467+
yyterminate();
1468+
}
13881469
%%
13891470

13901471
/*@ ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)