@@ -90,6 +90,9 @@ static int g_stringContext;
90
90
91
91
static QValueStack<uint> g_indents; // !< Tracks indentation levels for scoping in python
92
92
93
+ static QCString g_docBlock; // !< contents of all lines of a documentation block
94
+ static bool g_endComment;
95
+
93
96
static void endFontClass ();
94
97
static void adjustScopesAndSuites (unsigned indentLength);
95
98
@@ -361,11 +364,13 @@ static void startCodeLine()
361
364
Definition *d = g_sourceFileDef->getSourceDefinition (g_yyLineNr);
362
365
// printf("startCodeLine %d d=%p\n",g_yyLineNr,d);
363
366
// g_code->startLineNumber();
367
+
364
368
if (!g_includeCodeFragment && d && d->isLinkableInProject ())
365
369
{
366
370
g_currentDefinition = d;
367
371
g_currentMemberDef = g_sourceFileDef->getSourceMember (g_yyLineNr);
368
372
// g_insideBody = FALSE;
373
+ g_endComment = FALSE ;
369
374
g_searchingForBody = TRUE ;
370
375
g_realScope = d->name ().copy ();
371
376
g_classScope = d->name ().copy ();
@@ -467,13 +472,34 @@ static void writeMultiLineCodeLink(CodeOutputInterface &ol,
467
472
}
468
473
}
469
474
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
+ }
470
495
471
496
static void codifyLines (char *text)
472
497
{
473
498
// printf("codifyLines(%d,\"%s\")\n",g_yyLineNr,text);
474
499
char *p=text,*sp=p;
475
500
char c;
476
501
bool done=FALSE ;
502
+ const char * tmp_currentFontClass = g_currentFontClass;
477
503
while (!done)
478
504
{
479
505
sp=p;
@@ -483,7 +509,15 @@ static void codifyLines(char *text)
483
509
g_yyLineNr++;
484
510
*(p-1 )=' \0 ' ;
485
511
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
+ }
487
521
}
488
522
else
489
523
{
@@ -493,6 +527,13 @@ static void codifyLines(char *text)
493
527
}
494
528
}
495
529
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
+ }
496
537
497
538
static bool getLinkInScope (const QCString &c, // scope
498
539
const QCString &m, // member
@@ -796,22 +837,6 @@ static void findMemberLink(CodeOutputInterface &ol,char *symName)
796
837
codify (symName);
797
838
}
798
839
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
-
815
840
#undef YY_INPUT
816
841
#define YY_INPUT (buf,result,max_size ) result=yyread(buf,max_size);
817
842
@@ -842,7 +867,7 @@ PARAMNONEMPTY [^ \t\n():]
842
867
IDENTIFIER ({LETTER}|" _" )({LETTER}|{DIGIT}|" _" )*
843
868
BORDER ([^A-Za-z0-9 ])
844
869
845
- POUNDCOMMENT "#" .*
870
+ POUNDCOMMENT "## "
846
871
847
872
TRISINGLEQUOTE " ' ' ' "
848
873
TRIDOUBLEQUOTE "\"\"\" "
@@ -938,7 +963,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
938
963
939
964
940
965
%option noyywrap
941
- %option nounput
966
+ %option stack
942
967
943
968
%x Body
944
969
@@ -960,6 +985,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
960
985
%x DoubleQuoteString
961
986
%x TripleString
962
987
988
+ %x DocBlock
963
989
%%
964
990
965
991
<Body,Suite>{
@@ -1176,11 +1202,16 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
1176
1202
1177
1203
1178
1204
{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;
1184
1215
}
1185
1216
1186
1217
{NEWLINE} {
@@ -1349,6 +1380,28 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
1349
1380
codify (yytext);
1350
1381
BEGIN (DoubleQuoteString);
1351
1382
}
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
+ }
1352
1405
<*>{POUNDCOMMENT} {
1353
1406
if (YY_START==SingleQuoteString ||
1354
1407
YY_START==DoubleQuoteString ||
@@ -1357,14 +1410,31 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
1357
1410
{
1358
1411
REJECT;
1359
1412
}
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
+ }
1362
1425
startFontClass (" comment" );
1363
- codifyLines (yytext);
1364
- endFontClass ();
1426
+ codifyLines (yytext);
1427
+ endFontClass ();
1365
1428
}
1366
1429
<*>{NEWLINE} {
1367
- codifyLines (yytext);
1430
+ if (g_endComment)
1431
+ {
1432
+ g_endComment=FALSE ;
1433
+ }
1434
+ else
1435
+ {
1436
+ codifyLines (yytext);
1437
+ }
1368
1438
// printf("[pycode] %d NEWLINE [line %d] no match\n",
1369
1439
// YY_START, g_yyLineNr);
1370
1440
@@ -1385,6 +1455,17 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBUT
1385
1455
BEGIN (Body);
1386
1456
}
1387
1457
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
+ }
1388
1469
%%
1389
1470
1390
1471
/ * @ ----------------------------------------------------------------------------
0 commit comments