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 *"
23 // forward declare yyscan_t to improve type safety
24 #define YY_TYPEDEF_YY_SCANNER_T
26 typedef yyguts_t *yyscan_t;
43 #include "condparser.h"
48 #define YY_NO_UNISTD_H 1
50 #define ADDCHAR(c) yyextra->outBuf->addChar(c)
51 #define ADDARRAY(a,s) yyextra->outBuf->addArray(a,s)
53 #define USE_STATE2STRING 0
55 struct commentcnvYY_CondCtx
57 commentcnvYY_CondCtx(int line,QCString id,bool b)
58 : lineNr(line),sectionId(id), skip(b) {}
71 struct commentcnvYY_state
75 yy_size_t inBufPos = 0;
84 std::stack<commentcnvYY_CondCtx> condStack;
85 std::stack<int> commentStack;
87 int lastCommentContext = 0;
88 bool inSpecialComment = FALSE;
89 bool inRoseComment= FALSE;
90 int stringContext = 0;
93 bool specialComment = FALSE;
97 bool lastEscaped = FALSE;
98 int lastBlockContext= 0;
99 bool pythonDocString = FALSE;
102 bool vhdl = FALSE; // for VHDL old style --! comment
104 SrcLangExt lang = SrcLangExt_Unknown;
105 bool isFixedForm = FALSE; // For Fortran
109 static const char *stateToString(int state);
111 static inline int computeIndent(const char *s);
113 static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len);
114 static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len);
115 static void startCondSection(yyscan_t yyscanner,const QCString §Id);
116 static void endCondSection(yyscan_t yyscanner);
117 static void handleCondSectionId(yyscan_t yyscanner,const char *expression);
118 static void replaceAliases(yyscan_t yyscanner,const QCString &s);
119 static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
120 static void replaceComment(yyscan_t yyscanner,int offset);
121 static void clearCommentStack(yyscan_t yyscanner);
127 #define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
129 // otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
130 static inline const char *getLexerFILE() {return __FILE__;}
131 #include "doxygen_lex.h"
135 MAILADDR ("mailto:")?[a-z_A-Z0-9\x80-\xff.+-]+"@"[a-z_A-Z0-9\x80-\xff-]+("."[a-z_A-Z0-9\x80-\xff\-]+)+[a-z_A-Z0-9\x80-\xff\-]+
151 //- start: NUMBER -------------------------------------------------------------------------
152 // Note same defines in code.l: keep in sync
153 DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
154 HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
155 OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
156 BINARY_INTEGER "0"[bB][01][01']*[01]?
157 INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
161 DIGIT_SEQ [0-9][0-9']*[0-9]?
162 FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
163 FP_EXP [eE][+-]?{DIGIT_SEQ}
164 DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
165 DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
167 HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
168 HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
169 BIN_EXP [pP][+-]?{DIGIT_SEQ}
170 HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
171 HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
173 FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
174 FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
175 FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
176 NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
177 //- end: NUMBER ---------------------------------------------------------------------------
186 // Optional any character
189 // Optional white space
191 // readline non special
198 <Scan>{NUMBER} { //Note similar code in code.l
199 if (yyextra->lang!=SrcLangExt_Cpp) REJECT;
200 copyToOutput(yyscanner,yytext,(int)yyleng);
202 <Scan>[^"'!\/\n\\#,\-=; \t]* { /* eat anything that is not " / , or \n */
203 copyToOutput(yyscanner,yytext,(int)yyleng);
205 <Scan>[,= ;\t] { /* eat , so we have a nice separator in long initialization lines */
206 copyToOutput(yyscanner,yytext,(int)yyleng);
208 <Scan>"\"\"\""! { /* start of python long comment */
209 if (yyextra->lang!=SrcLangExt_Python)
215 yyextra->pythonDocString = TRUE;
216 yyextra->nestingCount=1;
217 clearCommentStack(yyscanner); /* to be on the save side */
218 copyToOutput(yyscanner,yytext,(int)yyleng);
220 yyextra->commentStack.push(yyextra->lineNr);
224 if (yyextra->lang!=SrcLangExt_Fortran)
230 copyToOutput(yyscanner,yytext,(int)yyleng);
231 yyextra->nestingCount=0; // Fortran doesn't have an end comment
232 clearCommentStack(yyscanner); /* to be on the save side */
234 yyextra->commentStack.push(yyextra->lineNr);
237 <Scan>[Cc\*][><!]/.*\n {
238 if (yyextra->lang!=SrcLangExt_Fortran)
244 /* check for fixed format; we might have some conditional as part of multiline if like C<5 .and. & */
245 if (yyextra->isFixedForm && (yyextra->col == 0))
247 copyToOutput(yyscanner,yytext,(int)yyleng);
248 yyextra->nestingCount=0; // Fortran doesn't have an end comment
249 clearCommentStack(yyscanner); /* to be on the save side */
251 yyextra->commentStack.push(yyextra->lineNr);
260 if (yyextra->lang!=SrcLangExt_Fortran)
266 copyToOutput(yyscanner,yytext,(int)yyleng);
270 if (yyextra->lang!=SrcLangExt_Fortran)
276 if (yyextra->col == 0)
278 copyToOutput(yyscanner,yytext,(int)yyleng);
286 <Scan>"\"" { /* start of a string */
287 copyToOutput(yyscanner,yytext,(int)yyleng);
288 yyextra->stringContext = YY_START;
292 copyToOutput(yyscanner,yytext,(int)yyleng);
293 yyextra->charContext = YY_START;
294 if (yyextra->lang!=SrcLangExt_VHDL)
299 <Scan>\n { /* new line */
300 copyToOutput(yyscanner,yytext,(int)yyleng);
302 <Scan>{CPPC}"!"/.*\n[ \t]*{CPPC}[\/!][^\/] | /* start C++ style special comment block */
303 <Scan>({CPPC}"/"[/]*)/[^/].*\n[ \t]*{CPPC}[\/!][^\/] { /* start C++ style special comment block */
304 if (yyextra->mlBrief)
306 REJECT; // bail out if we do not need to convert
313 while (i<(int)yyleng && yytext[i]=='/') i++;
315 yyextra->blockHeadCol=yyextra->col;
316 copyToOutput(yyscanner,"/**",3);
317 replaceAliases(yyscanner,QCString(yytext+i));
318 yyextra->inSpecialComment=TRUE;
320 yyextra->readLineCtx=SComment;
324 <Scan>{CPPC}"##Documentation"{ANYopt}/\n { /* Start of Rational Rose ANSI C++ comment block */
325 if (yyextra->mlBrief) REJECT;
326 int i=17; //=strlen("//##Documentation");
327 yyextra->blockHeadCol=yyextra->col;
328 copyToOutput(yyscanner,"/**",3);
329 replaceAliases(yyscanner,QCString(yytext+i));
330 yyextra->inRoseComment=TRUE;
333 <Scan>{CPPC}[!\/]/.*\n[ \t]*{CPPC}[|\/][ \t]*[@\\]"}" { // next line contains an end marker, see bug 752712
334 yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
335 copyToOutput(yyscanner,yytext,(int)yyleng);
336 yyextra->readLineCtx=YY_START;
339 <Scan>{CPPC}/.*\n { /* one line C++ comment */
340 yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
341 copyToOutput(yyscanner,yytext,(int)yyleng);
342 yyextra->readLineCtx=YY_START;
345 <Scan>{CCS}{CCE} { /* avoid matching next rule for empty C comment, see bug 711723 */
346 copyToOutput(yyscanner,yytext,(int)yyleng);
348 <Scan>{CCS}[*!]? { /* start of a C comment */
349 if (yyextra->lang==SrcLangExt_Python)
353 yyextra->specialComment=(int)yyleng==3;
354 yyextra->nestingCount=1;
355 clearCommentStack(yyscanner); /* to be on the save side */
356 copyToOutput(yyscanner,yytext,(int)yyleng);
357 if (yyextra->specialComment)
361 yyextra->commentStack.push(yyextra->lineNr);
364 if (yyextra->lang!=SrcLangExt_Python)
370 copyToOutput(yyscanner,yytext,(int)yyleng);
371 yyextra->nestingCount=0; // Python doesn't have an end comment for #
372 clearCommentStack(yyscanner); /* to be on the save side */
374 yyextra->commentStack.push(yyextra->lineNr);
377 <Scan>"--"[^!][^\n]* {
378 if (yyextra->lang!=SrcLangExt_VHDL)
384 copyToOutput(yyscanner,yytext,(int)yyleng);
388 if (yyextra->lang!=SrcLangExt_VHDL)
394 yyextra->vhdl = TRUE;
395 copyToOutput(yyscanner,yytext,(int)yyleng);
396 yyextra->nestingCount=0; // VHDL doesn't have an end comment
397 clearCommentStack(yyscanner); /* to be on the save side */
399 yyextra->commentStack.push(yyextra->lineNr);
403 if (yyextra->lang!=SrcLangExt_Fortran)
409 copyToOutput(yyscanner,yytext,(int)yyleng);
410 yyextra->nestingCount=0; // Fortran doesn't have an end comment
411 clearCommentStack(yyscanner); /* to be on the save side */
413 yyextra->commentStack.push(yyextra->lineNr);
416 <CComment,CNComment,ReadLine>{MAILADDR} |
417 <CComment,CNComment,ReadLine>"<"{MAILADDR}">" { // Mail address, to prevent seeing e.g x@code-factory.org as start of a code block
418 copyToOutput(yyscanner,yytext,(int)yyleng);
420 <CComment>"{"[ \t]*"@code"/[ \t\n] {
421 copyToOutput(yyscanner,"@iliteral{code}",15);
422 yyextra->lastCommentContext = YY_START;
423 yyextra->javaBlock=1;
424 yyextra->blockName=&yytext[1];
427 <CComment>"{"[ \t]*"@literal"/[ \t\n] {
428 copyToOutput(yyscanner,"@iliteral",9);
429 yyextra->lastCommentContext = YY_START;
430 yyextra->javaBlock=1;
431 yyextra->blockName=&yytext[1];
434 <CComment,ReadLine>^[ \t]*("```"[`]*|"~~~"[~]*) { /* start of markdown code block */
435 if (!Config_getBool(MARKDOWN_SUPPORT))
439 copyToOutput(yyscanner,yytext,(int)yyleng);
440 yyextra->lastCommentContext = YY_START;
441 yyextra->javaBlock=0;
442 yyextra->blockName=QCString(yytext).stripWhiteSpace().left(3);
445 <CComment,ReadLine>[\\@]("dot"|"code"|"msc"|"startuml")/[^a-z_A-Z0-9] { /* start of a verbatim block */
446 copyToOutput(yyscanner,yytext,(int)yyleng);
447 yyextra->lastCommentContext = YY_START;
448 yyextra->javaBlock=0;
449 if (qstrcmp(&yytext[1],"startuml")==0)
451 yyextra->blockName="uml";
455 yyextra->blockName=&yytext[1];
459 <CComment,ReadLine>[\\@]("f$"|"f["|"f{"|"f(") {
460 copyToOutput(yyscanner,yytext,(int)yyleng);
461 yyextra->blockName=&yytext[1];
462 if (yyextra->blockName.at(1)=='[')
464 yyextra->blockName.at(1)=']';
466 else if (yyextra->blockName.at(1)=='{')
468 yyextra->blockName.at(1)='}';
470 else if (yyextra->blockName.at(1)=='(')
472 yyextra->blockName.at(1)=')';
474 yyextra->lastCommentContext = YY_START;
477 <CComment,ReadLine>[\\@]("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
478 copyToOutput(yyscanner,yytext,(int)yyleng);
479 yyextra->blockName=&yytext[1];
480 yyextra->lastCommentContext = YY_START;
483 <Scan>"\\\"" { /* escaped double quote */
484 copyToOutput(yyscanner,yytext,(int)yyleng);
486 <Scan>"\\\\" { /* escaped backslash */
487 copyToOutput(yyscanner,yytext,(int)yyleng);
489 <Scan>. { /* any other character */
490 copyToOutput(yyscanner,yytext,(int)yyleng);
492 <Verbatim>[\\@]("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */
493 copyToOutput(yyscanner,yytext,(int)yyleng);
494 if (&yytext[1]==yyextra->blockName) // end of formula
496 BEGIN(yyextra->lastCommentContext);
498 else if (&yytext[4]==yyextra->blockName)
500 BEGIN(yyextra->lastCommentContext);
504 if (yyextra->javaBlock==0)
510 yyextra->javaBlock++;
511 copyToOutput(yyscanner,yytext,(int)yyleng);
515 if (yyextra->javaBlock==0)
521 yyextra->javaBlock--;
522 if (yyextra->javaBlock==0)
524 copyToOutput(yyscanner," @endiliteral ",14);
525 BEGIN(yyextra->lastCommentContext);
529 copyToOutput(yyscanner,yytext,(int)yyleng);
533 <VerbatimCode>("```"[`]*|"~~~"[~]*) { /* end of markdown code block */
534 copyToOutput(yyscanner,yytext,(int)yyleng);
535 if (yytext[0]==yyextra->blockName[0])
537 BEGIN(yyextra->lastCommentContext);
540 <VerbatimCode>[\\@]("enddot"|"endcode"|"endmsc"|"enduml") { /* end of verbatim block */
541 copyToOutput(yyscanner,yytext,(int)yyleng);
542 if (&yytext[4]==yyextra->blockName)
544 BEGIN(yyextra->lastCommentContext);
547 <VerbatimCode>^[ \t]*{CPPC}[\!\/]? { /* skip leading comments */
548 if (!yyextra->inSpecialComment)
550 copyToOutput(yyscanner,yytext,(int)yyleng);
555 while (yytext[l]==' ' || yytext[l]=='\t')
559 copyToOutput(yyscanner,yytext,l);
560 if (yyleng-l==3) // ends with //! or ///
562 copyToOutput(yyscanner," * ",3);
566 copyToOutput(yyscanner,"//",2);
570 <Verbatim,VerbatimCode>[^`~@\/\\\n{}]* { /* any character not a backslash or new line or } */
571 copyToOutput(yyscanner,yytext,(int)yyleng);
573 <Verbatim,VerbatimCode>\n { /* new line in verbatim block */
574 copyToOutput(yyscanner,yytext,(int)yyleng);
576 <Verbatim>^[ \t]*{CPPC}[/!] {
577 if (yyextra->blockName=="dot" || yyextra->blockName=="msc" || yyextra->blockName=="uml" || yyextra->blockName.at(0)=='f')
579 // see bug 487871, strip /// from dot images and formulas.
581 while (yytext[l]==' ' || yytext[l]=='\t')
585 copyToOutput(yyscanner,yytext,l);
586 copyToOutput(yyscanner," ",3);
588 else // even slashes are verbatim (e.g. \verbatim, \code)
593 <Verbatim,VerbatimCode>. { /* any other character */
594 copyToOutput(yyscanner,yytext,(int)yyleng);
596 <SkipString>\\. { /* escaped character in string */
597 if (yyextra->lang==SrcLangExt_Fortran || yyextra->lang==SrcLangExt_VHDL)
600 copyToOutput(yyscanner,yytext,1);
604 copyToOutput(yyscanner,yytext,(int)yyleng);
607 <SkipString>"\"" { /* end of string */
608 copyToOutput(yyscanner,yytext,(int)yyleng);
609 BEGIN(yyextra->stringContext);
611 <SkipString>. { /* any other string character */
612 copyToOutput(yyscanner,yytext,(int)yyleng);
614 <SkipString>\n { /* new line inside string (illegal for some compilers) */
615 copyToOutput(yyscanner,yytext,(int)yyleng);
617 <SkipChar>\\. { /* escaped character */
618 if (yyextra->lang==SrcLangExt_Fortran || yyextra->lang==SrcLangExt_VHDL)
621 copyToOutput(yyscanner,yytext,1);
625 copyToOutput(yyscanner,yytext,(int)yyleng);
628 <SkipChar>' { /* end of character literal */
629 copyToOutput(yyscanner,yytext,(int)yyleng);
630 BEGIN(yyextra->charContext);
632 <SkipChar>. { /* any other string character */
633 copyToOutput(yyscanner,yytext,(int)yyleng);
635 <SkipChar>\n { /* new line character */
636 copyToOutput(yyscanner,yytext,(int)yyleng);
639 <CComment,CNComment>[^ `~<\\!@*\n{\"\/]* { /* anything that is not a '*' or command */
640 copyToOutput(yyscanner,yytext,(int)yyleng);
642 <CComment,CNComment>"*"+[^*\/\\@\n{\"]* { /* stars without slashes */
643 copyToOutput(yyscanner,yytext,(int)yyleng);
645 <CComment>"\"\"\"" { /* end of Python docstring */
646 if (yyextra->lang!=SrcLangExt_Python)
652 yyextra->nestingCount--;
653 yyextra->pythonDocString = FALSE;
654 copyToOutput(yyscanner,yytext,(int)yyleng);
658 <CComment,CNComment>\n { /* new line in comment */
659 copyToOutput(yyscanner,yytext,(int)yyleng);
660 /* in case of Fortran always end of comment */
661 if (yyextra->lang==SrcLangExt_Fortran)
666 <CComment,CNComment>"/"+"*" { /* nested C comment */
667 if (yyextra->lang==SrcLangExt_Python ||
668 yyextra->lang==SrcLangExt_Markdown)
672 yyextra->nestingCount++;
673 yyextra->commentStack.push(yyextra->lineNr);
674 copyToOutput(yyscanner,yytext,(int)yyleng);
676 <CComment,CNComment>"*"+"/" { /* end of C comment */
677 if (yyextra->lang==SrcLangExt_Python ||
678 yyextra->lang==SrcLangExt_Markdown)
684 copyToOutput(yyscanner,yytext,(int)yyleng);
685 yyextra->nestingCount--;
686 if (yyextra->nestingCount<=0)
692 //yyextra->nestingCount--;
693 yyextra->commentStack.pop();
697 /* Python an VHDL share CComment,CNComment, so special attention for ending comments is required */
698 <CComment,CNComment>"\n"/[ \t]*"#" {
699 if (yyextra->lang!=SrcLangExt_VHDL)
705 if (yyextra->vhdl) // inside --! comment
707 yyextra->vhdl = FALSE;
708 copyToOutput(yyscanner,yytext,(int)yyleng);
711 else // C-type comment
717 <CComment,CNComment>"\n"/[ \t]*"-" {
718 if (yyextra->lang!=SrcLangExt_Python || yyextra->pythonDocString)
724 copyToOutput(yyscanner,yytext,(int)yyleng);
728 <CComment,CNComment>"\n"/[ \t]*[^ \t#\-] {
729 if (yyextra->lang==SrcLangExt_Python)
731 if (yyextra->pythonDocString)
737 copyToOutput(yyscanner,yytext,(int)yyleng);
741 else if (yyextra->lang==SrcLangExt_VHDL)
743 if (yyextra->vhdl) // inside --! comment
745 yyextra->vhdl = FALSE;
746 copyToOutput(yyscanner,yytext,(int)yyleng);
749 else // C-type comment
759 /* removed for bug 674842 (bug was introduced in rev 768)
760 <CComment,CNComment>"'" {
761 yyextra->charContext = YY_START;
762 copyToOutput(yyscanner,yytext,(int)yyleng);
765 <CComment,CNComment>"\"" {
766 yyextra->stringContext = YY_START;
767 copyToOutput(yyscanner,yytext,(int)yyleng);
771 <CComment,CNComment>. {
772 copyToOutput(yyscanner,yytext,(int)yyleng);
774 <SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n {
775 replaceComment(yyscanner,0);
777 <SComment>\n[ \t]*{CPPC}"/"{SLASHopt}/\n {
778 replaceComment(yyscanner,1);
780 <SComment>^[ \t]*{CPPC}"/"[^\/\n]/.*\n {
781 replaceComment(yyscanner,0);
782 yyextra->readLineCtx=YY_START;
785 <SComment>\n[ \t]*{CPPC}[\/!]("<")?[ \t]*[\\@]"}".*\n {
786 /* See Bug 752712: end the multiline comment when finding a @} or \} command */
787 copyToOutput(yyscanner," */",3);
788 copyToOutput(yyscanner,yytext,(int)yyleng);
789 yyextra->inSpecialComment=FALSE;
790 yyextra->inRoseComment=FALSE;
793 <SComment>\n[ \t]*{CPPC}"/"[^\/\n]/.*\n {
794 replaceComment(yyscanner,1);
795 yyextra->readLineCtx=YY_START;
798 <SComment>^[ \t]*{CPPC}"!" | // just //!
799 <SComment>^[ \t]*{CPPC}"!<"/.*\n | // or //!< something
800 <SComment>^[ \t]*{CPPC}"!"[^<]/.*\n { // or //!something
801 replaceComment(yyscanner,0);
802 yyextra->readLineCtx=YY_START;
805 <SComment>\n[ \t]*{CPPC}"!" |
806 <SComment>\n[ \t]*{CPPC}"!<"/.*\n |
807 <SComment>\n[ \t]*{CPPC}"!"[^<\n]/.*\n {
808 replaceComment(yyscanner,1);
809 yyextra->readLineCtx=YY_START;
812 <SComment>^[ \t]*{CPPC}"##"/.*\n {
813 if (!yyextra->inRoseComment)
819 replaceComment(yyscanner,0);
820 yyextra->readLineCtx=YY_START;
824 <SComment>\n[ \t]*{CPPC}"##"/.*\n {
825 if (!yyextra->inRoseComment)
831 replaceComment(yyscanner,1);
832 yyextra->readLineCtx=YY_START;
836 <SComment>\n { /* end of special comment */
837 copyToOutput(yyscanner," */",3);
838 copyToOutput(yyscanner,yytext,(int)yyleng);
839 yyextra->inSpecialComment=FALSE;
840 yyextra->inRoseComment=FALSE;
841 yyextra->readLineCtx = Scan; // reset, otherwise there will be problems with:
842 // static void handleCondSectionId
846 copyToOutput(yyscanner,"/‍**",8);
849 copyToOutput(yyscanner,"*‍/",7);
852 copyToOutput(yyscanner,yytext,(int)yyleng);
855 copyToOutput(yyscanner,yytext,(int)yyleng);
857 <ReadLine>{RLopt}/\n {
858 copyToOutput(yyscanner,yytext,(int)yyleng);
859 BEGIN(yyextra->readLineCtx);
861 <CComment,CNComment,ReadLine>[\\@][\\@][~a-z_A-Z][a-z_A-Z0-9]*[ \t]* { // escaped command
862 copyToOutput(yyscanner,yytext,(int)yyleng);
864 <CComment,ReadLine>[\\@]"cond"/[^a-z_A-Z0-9] { // conditional section
865 yyextra->condCtx = YY_START;
868 <CComment,ReadLine>[\\@]"endcond"/[^a-z_A-Z0-9] { // end of conditional section
869 bool oldSkip=yyextra->skip;
870 endCondSection(yyscanner);
871 if (YY_START==CComment && oldSkip && !yyextra->skip)
873 //printf("** Adding start of comment!\n");
874 if (yyextra->lang!=SrcLangExt_Python &&
875 yyextra->lang!=SrcLangExt_VHDL &&
876 yyextra->lang!=SrcLangExt_Markdown &&
877 yyextra->lang!=SrcLangExt_Fortran)
881 if (yyextra->specialComment)
888 <CondLine>[!()&| \ta-z_A-Z0-9.\-]+ {
889 handleCondSectionId(yyscanner,yytext);
891 <CComment,ReadLine>[\\@]"cond"{WSopt}/\n {
892 yyextra->condCtx=YY_START;
893 handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
896 <CondLine>. { // forgot section id?
897 handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
898 if (*yytext=='\n') { yyextra->lineNr++; copyToOutput(yyscanner,"\n",1);}
900 <CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9]* { // expand alias without arguments
901 replaceAliases(yyscanner,QCString(yytext));
903 <CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9]*"{" { // expand alias with arguments
904 yyextra->lastBlockContext=YY_START;
905 yyextra->blockCount=1;
906 yyextra->aliasString=yytext;
907 yyextra->lastEscaped=0;
908 BEGIN( ReadAliasArgs );
910 <ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]+ { // skip leading special comments (see bug 618079)
912 <ReadAliasArgs>{CCE} { // oops, end of comment in the middle of an alias?
913 if (yyextra->lang==SrcLangExt_Python)
917 else // abort the alias, restart scanning
919 copyToOutput(yyscanner,yyextra->aliasString.data(),yyextra->aliasString.length());
920 copyToOutput(yyscanner,yytext,(int)yyleng);
924 <ReadAliasArgs>[^{}\n\\\*]+ {
925 yyextra->aliasString+=yytext;
926 yyextra->lastEscaped=FALSE;
928 <ReadAliasArgs>"\\" {
929 if (yyextra->lastEscaped) yyextra->lastEscaped=FALSE;
930 else yyextra->lastEscaped=TRUE;
931 yyextra->aliasString+=yytext;
934 yyextra->aliasString+=yytext;
936 yyextra->lastEscaped=FALSE;
939 yyextra->aliasString+=yytext;
940 if (!yyextra->lastEscaped) yyextra->blockCount++;
941 yyextra->lastEscaped=FALSE;
944 yyextra->aliasString+=yytext;
945 if (!yyextra->lastEscaped) yyextra->blockCount--;
946 if (yyextra->blockCount==0)
948 replaceAliases(yyscanner,yyextra->aliasString);
949 BEGIN( yyextra->lastBlockContext );
951 yyextra->lastEscaped=FALSE;
954 yyextra->aliasString+=yytext;
955 yyextra->lastEscaped=FALSE;
958 copyToOutput(yyscanner,yytext,(int)yyleng);
962 copyToOutput(yyscanner,yytext,(int)yyleng);
965 <*>\n { fprintf(stderr,"Lex scanner %s (%s) default rule newline for state %s.\n", __FILE__, qPrint(yyextra->fileName),stateToString(YY_START));}
969 static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
971 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
974 // copy leading blanks
975 while ((c=*p) && (c==' ' || c=='\t' || c=='\n'))
978 yyextra->lineNr += c=='\n';
981 // replace start of comment marker by blanks and the last character by a *
983 while ((c=*p) && (c=='/' || c=='!' || c=='#'))
987 if (*p=='<') // comment-after-item marker
992 if (c=='!') // end after first !
1004 if (blanks>1) ADDCHAR('*');
1007 // copy comment line to output
1008 ADDARRAY(p,len-(int)(p-s));
1011 static inline int computeIndent(const char *s)
1014 int tabSize=Config_getInt(TAB_SIZE);
1020 else if (c=='\t') col+=tabSize-(col%tabSize);
1026 static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len)
1028 int tabSize=Config_getInt(TAB_SIZE);
1029 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1031 if (yyextra->skip) // only add newlines.
1043 yyextra->col+=tabSize-(yyextra->col%tabSize);
1058 case '\n': yyextra->col=0;
1059 //fprintf(stderr,"---> copy %d\n",g_lineNr);
1060 yyextra->lineNr++; break;
1061 case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize); break;
1062 default: yyextra->col++; break;
1068 static void clearCommentStack(yyscan_t yyscanner)
1070 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1071 while (!yyextra->commentStack.empty()) yyextra->commentStack.pop();
1074 static void startCondSection(yyscan_t yyscanner,const QCString §Id)
1076 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1077 //printf("startCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
1079 bool expResult = prs.parse(yyextra->fileName,yyextra->lineNr,sectId);
1080 yyextra->condStack.push(commentcnvYY_CondCtx(yyextra->lineNr,sectId,yyextra->skip));
1081 if (!expResult) // not enabled
1087 static void endCondSection(yyscan_t yyscanner)
1089 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1090 if (yyextra->condStack.empty())
1092 warn(yyextra->fileName,yyextra->lineNr,"Found \\endcond command without matching \\cond");
1093 yyextra->skip=FALSE;
1097 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
1098 yyextra->skip=ctx.skip;
1099 yyextra->condStack.pop();
1101 //printf("endCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
1104 static void handleCondSectionId(yyscan_t yyscanner,const char *expression)
1106 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1107 bool oldSkip=yyextra->skip;
1108 startCondSection(yyscanner,QCString(expression));
1109 if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
1110 !oldSkip && yyextra->skip)
1112 if (yyextra->lang!=SrcLangExt_Python &&
1113 yyextra->lang!=SrcLangExt_VHDL &&
1114 yyextra->lang!=SrcLangExt_Markdown &&
1115 yyextra->lang!=SrcLangExt_Fortran)
1121 if (yyextra->readLineCtx==SComment)
1127 BEGIN(yyextra->condCtx);
1131 /** copies string \a s with length \a len to the output, while
1132 * replacing any alias commands found in the string.
1134 static void replaceAliases(yyscan_t yyscanner,const QCString &s)
1136 QCString result = resolveAliasCmd(s);
1137 //printf("replaceAliases(%s)->'%s'\n",s,result.data());
1138 copyToOutput(yyscanner,result.data(),result.length());
1142 static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size)
1144 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1145 yy_size_t bytesInBuf = yyextra->inBuf->curPos()-yyextra->inBufPos;
1146 yy_size_t bytesToCopy = std::min(max_size,bytesInBuf);
1147 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
1148 yyextra->inBufPos+=bytesToCopy;
1152 static void replaceComment(yyscan_t yyscanner,int offset)
1154 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1155 if (yyextra->mlBrief || yyextra->skip)
1157 copyToOutput(yyscanner,yytext,(int)yyleng);
1161 //printf("replaceComment(%s)\n",yytext);
1162 int i=computeIndent(&yytext[offset]);
1163 if (i==yyextra->blockHeadCol)
1165 replaceCommentMarker(yyscanner,yytext,(int)yyleng);
1169 copyToOutput(yyscanner," */",3);
1170 for (i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
1171 yyextra->inSpecialComment=FALSE;
1177 /*! This function does three things:
1178 * -# It converts multi-line C++ style comment blocks (that are aligned)
1179 * to C style comment blocks (if MULTILINE_CPP_IS_BRIEF is set to NO).
1180 * -# It replaces aliases with their definition (see ALIASES)
1181 * -# It handles conditional sections (cond...endcond blocks)
1183 void convertCppComments(BufStr *inBuf,BufStr *outBuf,const QCString &fileName)
1186 commentcnvYY_state extra;
1187 commentcnvYYlex_init_extra(&extra,&yyscanner);
1189 commentcnvYYset_debug(1,yyscanner);
1191 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1192 //printf("convertCppComments(%s)\n",fileName);
1193 yyextra->inBuf = inBuf;
1194 yyextra->outBuf = outBuf;
1195 yyextra->inBufPos = 0;
1197 yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
1198 yyextra->skip = FALSE;
1199 yyextra->fileName = fileName;
1200 yyextra->lang = getLanguageFromFileName(fileName);
1201 yyextra->pythonDocString = FALSE;
1202 yyextra->lineNr = 1;
1203 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
1204 clearCommentStack(yyscanner);
1205 yyextra->vhdl = FALSE;
1207 printlex(yy_flex_debug, TRUE, __FILE__, qPrint(fileName));
1208 yyextra->isFixedForm = FALSE;
1209 if (yyextra->lang==SrcLangExt_Fortran)
1211 FortranFormat fmt = convertFileNameFortranParserCode(fileName);
1212 yyextra->isFixedForm = recognizeFixedForm(QCString(inBuf->data()),fmt);
1215 if (yyextra->lang==SrcLangExt_Markdown)
1217 yyextra->nestingCount=0;
1219 yyextra->commentStack.push(yyextra->lineNr);
1226 while (!yyextra->condStack.empty())
1228 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
1229 QCString sectionInfo(" ");
1230 if (ctx.sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx.sectionId.stripWhiteSpace().data());
1231 warn(yyextra->fileName,ctx.lineNr,"Conditional section%sdoes not have "
1232 "a corresponding \\endcond command within this file.",sectionInfo.data());
1233 yyextra->condStack.pop();
1235 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt_Markdown && yyextra->lang!=SrcLangExt_Fortran)
1237 QCString tmp("(probable line reference: ");
1239 while (!yyextra->commentStack.empty())
1241 int lineNr = yyextra->commentStack.top();
1242 if (!first) tmp += ", ";
1243 tmp += QCString().setNum(lineNr);
1245 yyextra->commentStack.pop();
1248 warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
1249 "Nesting level %d %s",yyextra->nestingCount,tmp.data());
1251 yyextra->nestingCount = 0;
1252 if (Debug::isFlagSet(Debug::CommentCnv))
1254 yyextra->outBuf->at(yyextra->outBuf->curPos())='\0';
1255 Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: %s\n"
1256 "output=[\n%s]\n-----------\n",qPrint(fileName),yyextra->outBuf->data()
1259 printlex(yy_flex_debug, FALSE, __FILE__, qPrint(fileName));
1260 commentcnvYYlex_destroy(yyscanner);
1264 //----------------------------------------------------------------------------
1266 #if USE_STATE2STRING
1267 #include "commentcnv.l.h"