1 /*****************************************************************************
5 * Copyright (C) 1997-2015 by Dimitri van Heesch.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation under the terms of the GNU General Public License is hereby
9 * granted. No representations are made about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
11 * See the GNU General Public License for more details.
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
17 %option never-interactive
18 %option prefix="commentcnvYY"
20 %option extra-type="struct commentcnvYY_state *"
33 #include <qtextstream.h>
42 #include "condparser.h"
47 #define YY_NO_UNISTD_H 1
49 #define ADDCHAR(c) yyextra->outBuf->addChar(c)
50 #define ADDARRAY(a,s) yyextra->outBuf->addArray(a,s)
52 #define USE_STATE2STRING 0
56 CondCtx(int line,QCString id,bool b)
57 : lineNr(line),sectionId(id), skip(b) {}
70 struct commentcnvYY_state
74 yy_size_t inBufPos = 0;
83 QStack<CondCtx> condStack;
84 QStack<CommentCtx> commentStack;
86 int lastCommentContext = 0;
87 bool inSpecialComment = FALSE;
88 bool inRoseComment= FALSE;
89 int stringContext = 0;
92 bool specialComment = FALSE;
96 bool lastEscaped = FALSE;
97 int lastBlockContext= 0;
98 bool pythonDocString = FALSE;
101 bool vhdl = FALSE; // for VHDL old style --! comment
103 SrcLangExt lang = SrcLangExt_Unknown;
104 bool isFixedForm = FALSE; // For Fortran
108 static const char *stateToString(int state);
110 static inline int computeIndent(const char *s);
112 static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len);
113 static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len);
114 static void startCondSection(yyscan_t yyscanner,const char *sectId);
115 static void endCondSection(yyscan_t yyscanner);
116 static void handleCondSectionId(yyscan_t yyscanner,const char *expression);
117 static void replaceAliases(yyscan_t yyscanner,const char *s);
118 static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
119 static void replaceComment(yyscan_t yyscanner,int offset);
125 #define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
130 MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z_A-Z0-9\-]+
145 //- start: NUMBER -------------------------------------------------------------------------
146 // Note same defines in code.l: keep in sync
147 DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
148 HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
149 OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
150 BINARY_INTEGER "0"[bB][01][01']*[01]?
151 INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
155 DIGIT_SEQ [0-9][0-9']*[0-9]?
156 FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
157 FP_EXP [eE][+-]?{DIGIT_SEQ}
158 DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
159 DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
161 HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
162 HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
163 BIN_EXP [pP][+-]?{DIGIT_SEQ}
164 HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
165 HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
167 FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
168 FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
169 FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
170 NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
171 //- end: NUMBER ---------------------------------------------------------------------------
175 <Scan>{NUMBER} { //Note similar code in code.l
176 if (yyextra->lang!=SrcLangExt_Cpp) REJECT;
177 copyToOutput(yyscanner,yytext,(int)yyleng);
179 <Scan>[^"'!\/\n\\#,\-=; \t]* { /* eat anything that is not " / , or \n */
180 copyToOutput(yyscanner,yytext,(int)yyleng);
182 <Scan>[,= ;\t] { /* eat , so we have a nice separator in long initialization lines */
183 copyToOutput(yyscanner,yytext,(int)yyleng);
185 <Scan>"\"\"\""! { /* start of python long comment */
186 if (yyextra->lang!=SrcLangExt_Python)
192 yyextra->pythonDocString = TRUE;
193 yyextra->nestingCount=1;
194 yyextra->commentStack.clear(); /* to be on the save side */
195 copyToOutput(yyscanner,yytext,(int)yyleng);
197 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
201 if (yyextra->lang!=SrcLangExt_Fortran)
207 copyToOutput(yyscanner,yytext,(int)yyleng);
208 yyextra->nestingCount=0; // Fortran doesn't have an end comment
209 yyextra->commentStack.clear(); /* to be on the save side */
211 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
214 <Scan>[Cc\*][><!]/.*\n {
215 if (yyextra->lang!=SrcLangExt_Fortran)
221 /* check for fixed format; we might have some conditional as part of multiline if like C<5 .and. & */
222 if (yyextra->isFixedForm && (yyextra->col == 0))
224 copyToOutput(yyscanner,yytext,(int)yyleng);
225 yyextra->nestingCount=0; // Fortran doesn't have an end comment
226 yyextra->commentStack.clear(); /* to be on the safe side */
228 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
237 if (yyextra->lang!=SrcLangExt_Fortran)
243 copyToOutput(yyscanner,yytext,(int)yyleng);
247 if (yyextra->lang!=SrcLangExt_Fortran)
253 if (yyextra->col == 0)
255 copyToOutput(yyscanner,yytext,(int)yyleng);
263 <Scan>"\"" { /* start of a string */
264 copyToOutput(yyscanner,yytext,(int)yyleng);
265 yyextra->stringContext = YY_START;
269 copyToOutput(yyscanner,yytext,(int)yyleng);
270 yyextra->charContext = YY_START;
271 if (yyextra->lang!=SrcLangExt_VHDL)
276 <Scan>\n { /* new line */
277 copyToOutput(yyscanner,yytext,(int)yyleng);
279 <Scan>"//!"/.*\n[ \t]*"//"[\/!][^\/] | /* start C++ style special comment block */
280 <Scan>("///"[/]*)/[^/].*\n[ \t]*"//"[\/!][^\/] { /* start C++ style special comment block */
281 if (yyextra->mlBrief)
283 REJECT; // bail out if we do not need to convert
290 while (i<(int)yyleng && yytext[i]=='/') i++;
292 yyextra->blockHeadCol=yyextra->col;
293 copyToOutput(yyscanner,"/**",3);
294 replaceAliases(yyscanner,yytext+i);
295 yyextra->inSpecialComment=TRUE;
297 yyextra->readLineCtx=SComment;
301 <Scan>"//##Documentation".*/\n { /* Start of Rational Rose ANSI C++ comment block */
302 if (yyextra->mlBrief) REJECT;
303 int i=17; //=strlen("//##Documentation");
304 yyextra->blockHeadCol=yyextra->col;
305 copyToOutput(yyscanner,"/**",3);
306 replaceAliases(yyscanner,yytext+i);
307 yyextra->inRoseComment=TRUE;
310 <Scan>"//"[!\/]/.*\n[ \t]*"//"[|\/][ \t]*[@\\]"}" { // next line contains an end marker, see bug 752712
311 yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
312 copyToOutput(yyscanner,yytext,(int)yyleng);
313 yyextra->readLineCtx=YY_START;
316 <Scan>"//"/.*\n { /* one line C++ comment */
317 yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
318 copyToOutput(yyscanner,yytext,(int)yyleng);
319 yyextra->readLineCtx=YY_START;
322 <Scan>"/**/" { /* avoid matching next rule for empty C comment, see bug 711723 */
323 copyToOutput(yyscanner,yytext,(int)yyleng);
325 <Scan>"/*"[*!]? { /* start of a C comment */
326 if (yyextra->lang==SrcLangExt_Python)
330 yyextra->specialComment=(int)yyleng==3;
331 yyextra->nestingCount=1;
332 yyextra->commentStack.clear(); /* to be on the save side */
333 copyToOutput(yyscanner,yytext,(int)yyleng);
335 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
338 if (yyextra->lang!=SrcLangExt_Python)
344 copyToOutput(yyscanner,yytext,(int)yyleng);
345 yyextra->nestingCount=0; // Python doesn't have an end comment for #
346 yyextra->commentStack.clear(); /* to be on the save side */
348 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
352 if (yyextra->lang!=SrcLangExt_VHDL)
358 yyextra->vhdl = TRUE;
359 copyToOutput(yyscanner,yytext,(int)yyleng);
360 yyextra->nestingCount=0; // VHDL doesn't have an end comment
361 yyextra->commentStack.clear(); /* to be on the save side */
363 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
367 if (yyextra->lang!=SrcLangExt_Fortran)
373 copyToOutput(yyscanner,yytext,(int)yyleng);
374 yyextra->nestingCount=0; // Fortran doesn't have an end comment
375 yyextra->commentStack.clear(); /* to be on the save side */
377 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
380 <CComment,ReadLine>{MAILADR} |
381 <CComment,ReadLine>"<"{MAILADR}">" { // Mail address, to prevent seeing e.g x@code-factory.org as start of a code block
382 copyToOutput(yyscanner,yytext,(int)yyleng);
384 <CComment>"{@code"/[ \t\n] {
385 copyToOutput(yyscanner,"@code",5);
386 yyextra->lastCommentContext = YY_START;
387 yyextra->javaBlock=1;
388 yyextra->blockName=&yytext[1];
391 <CComment,ReadLine>^[ \t]*("```"[`]*|"~~~"[~]*) { /* start of markdown code block */
392 if (!Config_getBool(MARKDOWN_SUPPORT))
396 copyToOutput(yyscanner,yytext,(int)yyleng);
397 yyextra->lastCommentContext = YY_START;
398 yyextra->javaBlock=0;
399 yyextra->blockName=QCString(yytext).stripWhiteSpace().left(3);
402 <CComment,ReadLine>[\\@]("dot"|"code"|"msc"|"startuml")/[^a-z_A-Z0-9] { /* start of a verbatim block */
403 copyToOutput(yyscanner,yytext,(int)yyleng);
404 yyextra->lastCommentContext = YY_START;
405 yyextra->javaBlock=0;
406 if (qstrcmp(&yytext[1],"startuml")==0)
408 yyextra->blockName="uml";
412 yyextra->blockName=&yytext[1];
416 <CComment,ReadLine>[\\@]("f$"|"f["|"f{") {
417 copyToOutput(yyscanner,yytext,(int)yyleng);
418 yyextra->blockName=&yytext[1];
419 if (yyextra->blockName.at(1)=='[')
421 yyextra->blockName.at(1)=']';
423 else if (yyextra->blockName.at(1)=='{')
425 yyextra->blockName.at(1)='}';
427 yyextra->lastCommentContext = YY_START;
430 <CComment,ReadLine>[\\@]("verbatim"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
431 copyToOutput(yyscanner,yytext,(int)yyleng);
432 yyextra->blockName=&yytext[1];
433 yyextra->lastCommentContext = YY_START;
436 <Scan>. { /* any other character */
437 copyToOutput(yyscanner,yytext,(int)yyleng);
439 <Verbatim>[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}") { /* end of verbatim block */
440 copyToOutput(yyscanner,yytext,(int)yyleng);
441 if (&yytext[1]==yyextra->blockName) // end of formula
443 BEGIN(yyextra->lastCommentContext);
445 else if (&yytext[4]==yyextra->blockName)
447 BEGIN(yyextra->lastCommentContext);
451 if (yyextra->javaBlock==0)
457 yyextra->javaBlock++;
458 copyToOutput(yyscanner,yytext,(int)yyleng);
462 if (yyextra->javaBlock==0)
468 yyextra->javaBlock--;
469 if (yyextra->javaBlock==0)
471 copyToOutput(yyscanner," @endcode ",10);
472 BEGIN(yyextra->lastCommentContext);
476 copyToOutput(yyscanner,yytext,(int)yyleng);
480 <VerbatimCode>("```"[`]*|"~~~"[~]*) { /* end of markdown code block */
481 copyToOutput(yyscanner,yytext,(int)yyleng);
482 if (yytext[0]==yyextra->blockName[0])
484 BEGIN(yyextra->lastCommentContext);
487 <VerbatimCode>[\\@]("enddot"|"endcode"|"endmsc"|"enduml") { /* end of verbatim block */
488 copyToOutput(yyscanner,yytext,(int)yyleng);
489 if (&yytext[4]==yyextra->blockName)
491 BEGIN(yyextra->lastCommentContext);
494 <VerbatimCode>^[ \t]*"//"[\!\/]? { /* skip leading comments */
495 if (!yyextra->inSpecialComment)
497 copyToOutput(yyscanner,yytext,(int)yyleng);
502 while (yytext[l]==' ' || yytext[l]=='\t')
506 copyToOutput(yyscanner,yytext,l);
507 if (yyleng-l==3) // ends with //! or ///
509 copyToOutput(yyscanner," * ",3);
513 copyToOutput(yyscanner,"//",2);
517 <Verbatim,VerbatimCode>[^`~@\/\\\n{}]* { /* any character not a backslash or new line or } */
518 copyToOutput(yyscanner,yytext,(int)yyleng);
520 <Verbatim,VerbatimCode>\n { /* new line in verbatim block */
521 copyToOutput(yyscanner,yytext,(int)yyleng);
523 <Verbatim>^[ \t]*"//"[/!] {
524 if (yyextra->blockName=="dot" || yyextra->blockName=="msc" || yyextra->blockName=="uml" || yyextra->blockName.at(0)=='f')
526 // see bug 487871, strip /// from dot images and formulas.
528 while (yytext[l]==' ' || yytext[l]=='\t')
532 copyToOutput(yyscanner,yytext,l);
533 copyToOutput(yyscanner," ",3);
535 else // even slashes are verbatim (e.g. \verbatim, \code)
540 <Verbatim,VerbatimCode>. { /* any other character */
541 copyToOutput(yyscanner,yytext,(int)yyleng);
543 <SkipString>\\. { /* escaped character in string */
544 if (yyextra->lang==SrcLangExt_Fortran)
547 copyToOutput(yyscanner,yytext,1);
551 copyToOutput(yyscanner,yytext,(int)yyleng);
554 <SkipString>"\"" { /* end of string */
555 copyToOutput(yyscanner,yytext,(int)yyleng);
556 BEGIN(yyextra->stringContext);
558 <SkipString>. { /* any other string character */
559 copyToOutput(yyscanner,yytext,(int)yyleng);
561 <SkipString>\n { /* new line inside string (illegal for some compilers) */
562 copyToOutput(yyscanner,yytext,(int)yyleng);
564 <SkipChar>\\. { /* escaped character */
565 if (yyextra->lang==SrcLangExt_Fortran)
568 copyToOutput(yyscanner,yytext,1);
572 copyToOutput(yyscanner,yytext,(int)yyleng);
575 <SkipChar>' { /* end of character literal */
576 copyToOutput(yyscanner,yytext,(int)yyleng);
577 BEGIN(yyextra->charContext);
579 <SkipChar>. { /* any other string character */
580 copyToOutput(yyscanner,yytext,(int)yyleng);
582 <SkipChar>\n { /* new line character */
583 copyToOutput(yyscanner,yytext,(int)yyleng);
586 <CComment>[^ `~<\\!@*\n{\"\/]* { /* anything that is not a '*' or command */
587 copyToOutput(yyscanner,yytext,(int)yyleng);
589 <CComment>"*"+[^*/\\@\n{\"]* { /* stars without slashes */
590 copyToOutput(yyscanner,yytext,(int)yyleng);
592 <CComment>"\"\"\"" { /* end of Python docstring */
593 if (yyextra->lang!=SrcLangExt_Python)
599 yyextra->nestingCount--;
600 yyextra->pythonDocString = FALSE;
601 copyToOutput(yyscanner,yytext,(int)yyleng);
605 <CComment>\n { /* new line in comment */
606 copyToOutput(yyscanner,yytext,(int)yyleng);
607 /* in case of Fortran always end of comment */
608 if (yyextra->lang==SrcLangExt_Fortran)
613 <CComment>"/"+"*" { /* nested C comment */
614 if (yyextra->lang==SrcLangExt_Python ||
615 yyextra->lang==SrcLangExt_Markdown)
619 yyextra->nestingCount++;
620 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
621 copyToOutput(yyscanner,yytext,(int)yyleng);
623 <CComment>"*"+"/" { /* end of C comment */
624 if (yyextra->lang==SrcLangExt_Python ||
625 yyextra->lang==SrcLangExt_Markdown)
631 copyToOutput(yyscanner,yytext,(int)yyleng);
632 yyextra->nestingCount--;
633 if (yyextra->nestingCount<=0)
639 //yyextra->nestingCount--;
640 delete yyextra->commentStack.pop();
644 /* Python an VHDL share CComment, so special attention for ending comments is required */
645 <CComment>"\n"/[ \t]*"#" {
646 if (yyextra->lang!=SrcLangExt_VHDL)
652 if (yyextra->vhdl) // inside --! comment
654 yyextra->vhdl = FALSE;
655 copyToOutput(yyscanner,yytext,(int)yyleng);
658 else // C-type comment
664 <CComment>"\n"/[ \t]*"-" {
665 if (yyextra->lang!=SrcLangExt_Python || yyextra->pythonDocString)
671 copyToOutput(yyscanner,yytext,(int)yyleng);
675 <CComment>"\n"/[ \t]*[^ \t#\-] {
676 if (yyextra->lang==SrcLangExt_Python)
678 if (yyextra->pythonDocString)
684 copyToOutput(yyscanner,yytext,(int)yyleng);
688 else if (yyextra->lang==SrcLangExt_VHDL)
690 if (yyextra->vhdl) // inside --! comment
692 yyextra->vhdl = FALSE;
693 copyToOutput(yyscanner,yytext,(int)yyleng);
696 else // C-type comment
706 /* removed for bug 674842 (bug was introduced in rev 768)
708 yyextra->charContext = YY_START;
709 copyToOutput(yyscanner,yytext,(int)yyleng);
713 yyextra->stringContext = YY_START;
714 copyToOutput(yyscanner,yytext,(int)yyleng);
719 copyToOutput(yyscanner,yytext,(int)yyleng);
721 <SComment>^[ \t]*"///"[\/]*/\n {
722 replaceComment(yyscanner,0);
724 <SComment>\n[ \t]*"///"[\/]*/\n {
725 replaceComment(yyscanner,1);
727 <SComment>^[ \t]*"///"[^\/\n]/.*\n {
728 replaceComment(yyscanner,0);
729 yyextra->readLineCtx=YY_START;
732 <SComment>\n[ \t]*"//"[\/!]("<")?[ \t]*[\\@]"}".*\n {
733 /* See Bug 752712: end the multiline comment when finding a @} or \} command */
734 copyToOutput(yyscanner," */",3);
735 copyToOutput(yyscanner,yytext,(int)yyleng);
736 yyextra->inSpecialComment=FALSE;
737 yyextra->inRoseComment=FALSE;
740 <SComment>\n[ \t]*"///"[^\/\n]/.*\n {
741 replaceComment(yyscanner,1);
742 yyextra->readLineCtx=YY_START;
745 <SComment>^[ \t]*"//!" | // just //!
746 <SComment>^[ \t]*"//!<"/.*\n | // or //!< something
747 <SComment>^[ \t]*"//!"[^<]/.*\n { // or //!something
748 replaceComment(yyscanner,0);
749 yyextra->readLineCtx=YY_START;
752 <SComment>\n[ \t]*"//!" |
753 <SComment>\n[ \t]*"//!<"/.*\n |
754 <SComment>\n[ \t]*"//!"[^<\n]/.*\n {
755 replaceComment(yyscanner,1);
756 yyextra->readLineCtx=YY_START;
759 <SComment>^[ \t]*"//##"/.*\n {
760 if (!yyextra->inRoseComment)
766 replaceComment(yyscanner,0);
767 yyextra->readLineCtx=YY_START;
771 <SComment>\n[ \t]*"//##"/.*\n {
772 if (!yyextra->inRoseComment)
778 replaceComment(yyscanner,1);
779 yyextra->readLineCtx=YY_START;
783 <SComment>\n { /* end of special comment */
784 copyToOutput(yyscanner," */",3);
785 copyToOutput(yyscanner,yytext,(int)yyleng);
786 yyextra->inSpecialComment=FALSE;
787 yyextra->inRoseComment=FALSE;
791 copyToOutput(yyscanner,"/‍**",8);
794 copyToOutput(yyscanner,"*‍/",7);
797 copyToOutput(yyscanner,yytext,(int)yyleng);
799 <ReadLine>[^\\@\n\*/]* {
800 copyToOutput(yyscanner,yytext,(int)yyleng);
802 <ReadLine>[^\\@\n\*/]*/\n {
803 copyToOutput(yyscanner,yytext,(int)yyleng);
804 BEGIN(yyextra->readLineCtx);
806 <CComment,ReadLine>[\\@][\\@][~a-z_A-Z][a-z_A-Z0-9]*[ \t]* { // escaped command
807 copyToOutput(yyscanner,yytext,(int)yyleng);
809 <CComment,ReadLine>[\\@]"cond"/[^a-z_A-Z0-9] { // conditional section
810 yyextra->condCtx = YY_START;
813 <CComment,ReadLine>[\\@]"endcond"/[^a-z_A-Z0-9] { // end of conditional section
814 bool oldSkip=yyextra->skip;
815 endCondSection(yyscanner);
816 if (YY_START==CComment && oldSkip && !yyextra->skip)
818 //printf("** Adding start of comment!\n");
819 if (yyextra->lang!=SrcLangExt_Python &&
820 yyextra->lang!=SrcLangExt_VHDL &&
821 yyextra->lang!=SrcLangExt_Markdown &&
822 yyextra->lang!=SrcLangExt_Fortran)
826 if (yyextra->specialComment)
833 <CondLine>[!()&| \ta-z_A-Z0-9.\-]+ {
834 handleCondSectionId(yyscanner,yytext);
836 <CComment,ReadLine>[\\@]"cond"[ \t\r]*/\n {
837 yyextra->condCtx=YY_START;
838 handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
840 <CondLine>. { // forgot section id?
841 handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
842 if (*yytext=='\n') yyextra->lineNr++;
844 <CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9]* { // expand alias without arguments
845 replaceAliases(yyscanner,yytext);
847 <CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9]*"{" { // expand alias with arguments
848 yyextra->lastBlockContext=YY_START;
849 yyextra->blockCount=1;
850 yyextra->aliasString=yytext;
851 yyextra->lastEscaped=0;
852 BEGIN( ReadAliasArgs );
854 <ReadAliasArgs>^[ \t]*"//"[/!]/[^\n]+ { // skip leading special comments (see bug 618079)
856 <ReadAliasArgs>"*/" { // oops, end of comment in the middle of an alias?
857 if (yyextra->lang==SrcLangExt_Python)
861 else // abort the alias, restart scanning
863 copyToOutput(yyscanner,yyextra->aliasString,yyextra->aliasString.length());
864 copyToOutput(yyscanner,yytext,(int)yyleng);
868 <ReadAliasArgs>[^{}\n\\\*]+ {
869 yyextra->aliasString+=yytext;
870 yyextra->lastEscaped=FALSE;
872 <ReadAliasArgs>"\\" {
873 if (yyextra->lastEscaped) yyextra->lastEscaped=FALSE;
874 else yyextra->lastEscaped=TRUE;
875 yyextra->aliasString+=yytext;
878 yyextra->aliasString+=yytext;
880 yyextra->lastEscaped=FALSE;
883 yyextra->aliasString+=yytext;
884 if (!yyextra->lastEscaped) yyextra->blockCount++;
885 yyextra->lastEscaped=FALSE;
888 yyextra->aliasString+=yytext;
889 if (!yyextra->lastEscaped) yyextra->blockCount--;
890 if (yyextra->blockCount==0)
892 replaceAliases(yyscanner,yyextra->aliasString);
893 BEGIN( yyextra->lastBlockContext );
895 yyextra->lastEscaped=FALSE;
898 yyextra->aliasString+=yytext;
899 yyextra->lastEscaped=FALSE;
902 copyToOutput(yyscanner,yytext,(int)yyleng);
906 copyToOutput(yyscanner,yytext,(int)yyleng);
910 static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
912 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
915 // copy leading blanks
916 while ((c=*p) && (c==' ' || c=='\t' || c=='\n'))
919 yyextra->lineNr += c=='\n';
922 // replace start of comment marker by blanks and the last character by a *
924 while ((c=*p) && (c=='/' || c=='!' || c=='#'))
928 if (*p=='<') // comment-after-item marker
933 if (c=='!') // end after first !
945 if (blanks>1) ADDCHAR('*');
948 // copy comment line to output
949 ADDARRAY(p,len-(int)(p-s));
952 static inline int computeIndent(const char *s)
955 static int tabSize=Config_getInt(TAB_SIZE);
961 else if (c=='\t') col+=tabSize-(col%tabSize);
967 static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len)
969 int tabSize=Config_getInt(TAB_SIZE);
970 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
972 if (yyextra->skip) // only add newlines.
984 yyextra->col+=tabSize-(yyextra->col%tabSize);
999 case '\n': yyextra->col=0;
1000 //fprintf(stderr,"---> copy %d\n",g_lineNr);
1001 yyextra->lineNr++; break;
1002 case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize); break;
1003 default: yyextra->col++; break;
1009 static void startCondSection(yyscan_t yyscanner,const char *sectId)
1011 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1012 //printf("startCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
1014 bool expResult = prs.parse(yyextra->fileName,yyextra->lineNr,sectId);
1015 yyextra->condStack.push(new CondCtx(yyextra->lineNr,sectId,yyextra->skip));
1016 if (!expResult) // not enabled
1022 static void endCondSection(yyscan_t yyscanner)
1024 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1025 if (yyextra->condStack.isEmpty())
1027 warn(yyextra->fileName,yyextra->lineNr,"Found \\endcond command without matching \\cond");
1028 yyextra->skip=FALSE;
1032 CondCtx *ctx = yyextra->condStack.pop();
1033 yyextra->skip=ctx->skip;
1035 //printf("endCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
1038 static void handleCondSectionId(yyscan_t yyscanner,const char *expression)
1040 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1041 bool oldSkip=yyextra->skip;
1042 startCondSection(yyscanner,expression);
1043 if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
1044 !oldSkip && yyextra->skip)
1046 if (yyextra->lang!=SrcLangExt_Python &&
1047 yyextra->lang!=SrcLangExt_VHDL &&
1048 yyextra->lang!=SrcLangExt_Markdown &&
1049 yyextra->lang!=SrcLangExt_Fortran)
1055 if (yyextra->readLineCtx==SComment)
1061 BEGIN(yyextra->condCtx);
1065 /** copies string \a s with length \a len to the output, while
1066 * replacing any alias commands found in the string.
1068 static void replaceAliases(yyscan_t yyscanner,const char *s)
1070 QCString result = resolveAliasCmd(s);
1071 //printf("replaceAliases(%s)->'%s'\n",s,result.data());
1072 copyToOutput(yyscanner,result,result.length());
1076 static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size)
1078 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1079 yy_size_t bytesInBuf = yyextra->inBuf->curPos()-yyextra->inBufPos;
1080 yy_size_t bytesToCopy = QMIN(max_size,bytesInBuf);
1081 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
1082 yyextra->inBufPos+=bytesToCopy;
1086 static void replaceComment(yyscan_t yyscanner,int offset)
1088 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1089 if (yyextra->mlBrief || yyextra->skip)
1091 copyToOutput(yyscanner,yytext,(int)yyleng);
1095 //printf("replaceComment(%s)\n",yytext);
1096 int i=computeIndent(&yytext[offset]);
1097 if (i==yyextra->blockHeadCol)
1099 replaceCommentMarker(yyscanner,yytext,(int)yyleng);
1103 copyToOutput(yyscanner," */",3);
1104 for (i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
1105 yyextra->inSpecialComment=FALSE;
1111 /*! This function does three things:
1112 * -# It converts multi-line C++ style comment blocks (that are aligned)
1113 * to C style comment blocks (if MULTILINE_CPP_IS_BRIEF is set to NO).
1114 * -# It replaces aliases with their definition (see ALIASES)
1115 * -# It handles conditional sections (cond...endcond blocks)
1117 void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
1120 commentcnvYY_state extra;
1121 commentcnvYYlex_init_extra(&extra,&yyscanner);
1123 commentcnvYYset_debug(1,yyscanner);
1125 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1126 //printf("convertCppComments(%s)\n",fileName);
1127 yyextra->inBuf = inBuf;
1128 yyextra->outBuf = outBuf;
1129 yyextra->inBufPos = 0;
1131 yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
1132 yyextra->skip = FALSE;
1133 yyextra->fileName = fileName;
1134 yyextra->lang = getLanguageFromFileName(fileName);
1135 yyextra->pythonDocString = FALSE;
1136 yyextra->lineNr = 1;
1137 yyextra->condStack.clear();
1138 yyextra->condStack.setAutoDelete(TRUE);
1139 yyextra->commentStack.clear();
1140 yyextra->commentStack.setAutoDelete(TRUE);
1141 yyextra->vhdl = FALSE;
1143 printlex(yy_flex_debug, TRUE, __FILE__, fileName);
1144 yyextra->isFixedForm = FALSE;
1145 if (yyextra->lang==SrcLangExt_Fortran)
1147 FortranFormat fmt = convertFileNameFortranParserCode(fileName);
1148 yyextra->isFixedForm = recognizeFixedForm(inBuf->data(),fmt);
1151 if (yyextra->lang==SrcLangExt_Markdown)
1153 yyextra->nestingCount=0;
1155 yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
1162 while (!yyextra->condStack.isEmpty())
1164 CondCtx *ctx = yyextra->condStack.pop();
1165 QCString sectionInfo = " ";
1166 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx->sectionId.stripWhiteSpace().data());
1167 warn(yyextra->fileName,ctx->lineNr,"Conditional section%sdoes not have "
1168 "a corresponding \\endcond command within this file.",sectionInfo.data());
1170 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt_Markdown && yyextra->lang!=SrcLangExt_Fortran)
1172 QCString tmp= "(probable line reference: ";
1174 while (!yyextra->commentStack.isEmpty())
1176 CommentCtx *ctx = yyextra->commentStack.pop();
1177 if (!first) tmp += ", ";
1178 tmp += QCString().setNum(ctx->lineNr);
1183 warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
1184 "Nesting level %d %s",yyextra->nestingCount,tmp.data());
1186 yyextra->commentStack.clear();
1187 yyextra->nestingCount = 0;
1188 if (Debug::isFlagSet(Debug::CommentCnv))
1190 yyextra->outBuf->at(yyextra->outBuf->curPos())='\0';
1191 Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: %s\n"
1192 "output=[\n%s]\n-----------\n",fileName,yyextra->outBuf->data()
1195 printlex(yy_flex_debug, FALSE, __FILE__, fileName);
1196 commentcnvYYlex_destroy(yyscanner);
1200 //----------------------------------------------------------------------------
1202 #if USE_STATE2STRING
1203 #include "commentcnv.l.h"