19 #define YY_BUF_SIZE 10*1024*1024
22%option never-interactive
23%option prefix="commentcnvYY"
25%option extra-type="struct commentcnvYY_state *"
29#define YY_TYPEDEF_YY_SCANNER_T
59#define YY_NO_UNISTD_H 1
156static void replaceAliases(
yyscan_t yyscanner,std::string_view s,
bool replaceCppComment=
false,
bool replaceCComment=
false);
165#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
This is an alternative implementation of QCString.
Token literal values and constants.
Some helper functions for std::string.
A bunch of utility functions.
173MAILADDR ("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\-]+
200DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
201HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
202OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
203BINARY_INTEGER "0"[bB][01][01']*[01]?
204INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
208DIGIT_SEQ [0-9][0-9']*[0-9]?
209FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
210FP_EXP [eE][+-]?{DIGIT_SEQ}
211DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
212DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
214HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
215HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
216BIN_EXP [pP][+-]?{DIGIT_SEQ}
217HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
218HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
220FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
221FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
222FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
223NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
225RAWBEGIN (u|U|L|u8)?R\"[^ \t\(\)\\]{0,16}"("
226RAWEND ")"[^ \t\(\)\\]{0,16}\"
228FILEICHAR [a-z_A-Z0-9\x80-\xFF\\:\\\/\-\+=&#@]
229FILEECHAR [a-z_A-Z0-9\x80-\xFF\-\+=&#@]
230FILECHARS {FILEICHAR}*{FILEECHAR}+
231HFILEMASK {FILEICHAR}*("."{FILEICHAR}+)+{FILECHARS}*
232VFILEMASK {FILECHARS}("."{FILECHARS})*
233FILEMASK {VFILEMASK}|{HFILEMASK}
261 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
265 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
269<Scan>[^"'!\/\n\\#,\-=; \t@$]* {
277 if (yyextra->lang!=SrcLangExt::Python)
283 yyextra->pythonDocString =
TRUE;
284 yyextra->pythonDocStringChar = yytext[0];
285 yyextra->nestingCount=1;
289 yyextra->commentStack.push(yyextra->lineNr);
294 if (yyextra->lang!=SrcLangExt::Python)
304 yyextra->pythonDocString =
TRUE;
305 yyextra->pythonDocStringChar = yytext[0];
306 yyextra->nestingCount=1;
310 yyextra->commentStack.push(yyextra->lineNr);
#define Config_getBool(name)
313<Scan>{B}*![><!]/.*\n {
314 if (yyextra->lang!=SrcLangExt::Fortran)
320 yyextra->nestingCount=0;
322 yyextra->specialComment=
true;
324 yyextra->blockHeadCol=yyextra->col-2;
326 yyextra->commentStack.push(yyextra->lineNr);
329<Scan>[Cc\*][><!]/.*\n {
330 if (yyextra->lang!=SrcLangExt::Fortran)
337 if (yyextra->isFixedForm && (yyextra->col == 0))
339 yyextra->nestingCount=0;
341 yyextra->specialComment=
true;
343 yyextra->blockHeadCol=yyextra->col-1;
345 yyextra->commentStack.push(yyextra->lineNr);
354 if (yyextra->lang!=SrcLangExt::Fortran)
364 if (yyextra->lang!=SrcLangExt::Fortran)
370 if (yyextra->col == 0)
381 if (yyextra->lang!=SrcLangExt::CSharp) REJECT
383 yyextra->stringContext = YY_START;
384 BEGIN(SkipVerbString);
388 yyextra->stringContext = YY_START;
393 yyextra->charContext = YY_START;
394 if (yyextra->lang!=SrcLangExt::VHDL)
402<Scan>{CPPC}[!/]/.*\n[ \t]*{CPPC}[!/][ \t]*{CMD}"}" {
404 yyextra->inSpecialComment=
true;
405 yyextra->blockHeadCol=yyextra->col+1;
406 yyextra->insertCppCommentMarker=
true;
408 yyextra->readLineCtx=YY_START;
411<Scan>{CPPC}"!"/.*\n[ \t]*{CPPC}[\/!][^\/] |
412<Scan>({CPPC}"/"[/]*)/[^/].*\n[ \t]*{CPPC}[\/!][^\/] {
413 if (yyextra->mlBrief)
422 while (i<(
int)yyleng && yytext[i]==
'/') i++;
424 yyextra->blockHeadCol=yyextra->col+1;
425 if (yytext[2] ==
'!')
434 yyextra->inSpecialComment=
TRUE;
436 yyextra->readLineCtx=SComment;
440<Scan>{CPPC}"##Documentation"{ANYopt}/\n {
441 if (yyextra->mlBrief) REJECT;
443 yyextra->blockHeadCol=yyextra->col+1;
446 yyextra->inRoseComment=
TRUE;
449<Scan>{CPPC}[!\/]/.*\n[ \t]*{CPPC}[|\/][ \t]*{CMD}"}" {
450 yyextra->inSpecialComment=yytext[2]==
'/' || yytext[2]==
'!';
451 if (yyextra->inSpecialComment)
453 yyextra->blockHeadCol=yyextra->col+1;
456 yyextra->readLineCtx=YY_START;
459<Scan>{CPPC}[!/]/.*\n {
460 yyextra->inSpecialComment=
true;
461 yyextra->blockHeadCol=yyextra->col+1;
462 yyextra->insertCppCommentMarker=
true;
464 yyextra->readLineCtx=YY_START;
468 yyextra->inSpecialComment=
false;
470 yyextra->readLineCtx=YY_START;
477 if (yyextra->lang==SrcLangExt::Python)
481 yyextra->specialComment=(int)yyleng==3;
482 yyextra->nestingCount=1;
485 if (yyextra->specialComment)
487 yyextra->blockHeadCol=0;
494 yyextra->commentStack.push(yyextra->lineNr);
497 if (yyextra->lang!=SrcLangExt::PHP)
504 if (yyextra->lang!=SrcLangExt::Python)
510 yyextra->nestingCount=0;
512 yyextra->specialComment=(int)yyleng==2;
513 if (yyextra->specialComment)
515 yyextra->blockHeadCol=yyextra->col;
517 yyextra->commentStack.push(yyextra->lineNr);
522<Scan>"--"[^!][^\n]* {
523 if (yyextra->lang!=SrcLangExt::VHDL)
533 if (yyextra->lang!=SrcLangExt::VHDL)
539 yyextra->specialComment=
true;
540 yyextra->blockHeadCol=yyextra->col;
541 yyextra->vhdl =
TRUE;
542 yyextra->nestingCount=0;
544 yyextra->commentStack.push(yyextra->lineNr);
550 if (yyextra->lang!=SrcLangExt::Fortran)
556 yyextra->nestingCount=0;
558 yyextra->specialComment=
true;
559 yyextra->blockHeadCol=yyextra->col;
560 yyextra->commentStack.push(yyextra->lineNr);
QCString extractEndRawStringDelimiter(const char *rawEnd)
572<RawString>[^)\n]+ {
copyToOutput(yyscanner,yytext,yyleng); }
576<CComment,CNComment,ReadLine,IncludeFile>{MAILADDR} |
577<CComment,CNComment,ReadLine,IncludeFile>"<"{MAILADDR}">" {
580<CComment,IncludeFile>"{"[ \t]*"@code"/[ \t\n] {
582 yyextra->lastCommentContext = YY_START;
583 yyextra->javaBlock=1;
584 yyextra->blockName=
QCString(
"end")+&yytext[1];
585 yyextra->inVerbatim=
true;
586 yyextra->verbatimLine=yyextra->lineNr;
589<CComment,IncludeFile>"{"[ \t]*"@literal"/[ \t\n] {
591 yyextra->lastCommentContext = YY_START;
592 yyextra->javaBlock=1;
593 yyextra->blockName=
QCString(
"end")+&yytext[1];
594 yyextra->inVerbatim=
true;
595 yyextra->verbatimLine=yyextra->lineNr;
598<CComment,ReadLine,IncludeFile>{CMD}"ilinebr"[ \t]+("```"[`]*|"~~~"[~]*) {
604 yyextra->lastCommentContext = YY_START;
605 yyextra->javaBlock=0;
607 yyextra->inVerbatim=
true;
608 yyextra->verbatimLine=yyextra->lineNr;
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
QCString right(size_t len) const
611<CComment,ReadLine,IncludeFile>^[ \t]*("```"[`]*|"~~~"[~]*) {
617 yyextra->lastCommentContext = YY_START;
618 yyextra->javaBlock=0;
620 yyextra->inVerbatim=
true;
621 yyextra->verbatimLine=yyextra->lineNr;
QCString left(size_t len) const
624<CComment,ReadLine,IncludeFile>{CMD}("dot"|"code"|"msc"|"startuml")/[^a-z_A-Z0-9] {
626 yyextra->lastCommentContext = YY_START;
627 yyextra->javaBlock=0;
628 if (
qstrcmp(&yytext[1],
"startuml")==0)
630 yyextra->blockName=
"enduml";
634 yyextra->blockName=
QCString(
"end")+&yytext[1];
636 yyextra->inVerbatim=
true;
637 yyextra->verbatimLine=yyextra->lineNr;
int qstrcmp(const char *str1, const char *str2)
640<CComment,ReadLine,IncludeFile>"\\`" {
643<CComment,ReadLine,IncludeFile>"```" {
646<CComment,ReadLine,IncludeFile>"`"{1,2} {
652 yyextra->lastCommentContext = YY_START;
653 yyextra->javaBlock=0;
654 yyextra->blockName=yytext;
655 yyextra->inVerbatim=
true;
656 yyextra->verbatimLine=yyextra->lineNr;
659<CComment,ReadLine,IncludeFile>{CMD}("f$"|"f["|"f{"|"f(") {
661 yyextra->blockName=&yytext[1];
662 if (yyextra->blockName.at(1)==
'[')
664 yyextra->blockName.at(1)=
']';
666 else if (yyextra->blockName.at(1)==
'{')
668 yyextra->blockName.at(1)=
'}';
670 else if (yyextra->blockName.at(1)==
'(')
672 yyextra->blockName.at(1)=
')';
674 yyextra->lastCommentContext = YY_START;
675 yyextra->inVerbatim=
true;
676 yyextra->verbatimLine=yyextra->lineNr;
679<CComment,ReadLine,IncludeFile>"<!--!" {
680 if (yyextra->inVerbatim) REJECT;
682 yyextra->inHtmlDoxygenCommand=
true;
684<CComment,ReadLine,IncludeFile>"-->" {
685 if (yyextra->inHtmlDoxygenCommand)
687 yyextra->inHtmlDoxygenCommand=
false;
694<CComment,ReadLine,IncludeFile>"<!--" {
696 yyextra->blockName=
"-->";
697 yyextra->lastCommentContext = YY_START;
698 yyextra->inVerbatim=
true;
699 yyextra->verbatimLine=yyextra->lineNr;
702<CComment,ReadLine,IncludeFile>{CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] {
704 yyextra->blockName=
QCString(
"end")+&yytext[1];
705 yyextra->lastCommentContext = YY_START;
706 yyextra->inVerbatim=
true;
707 yyextra->verbatimLine=yyextra->lineNr;
719<Verbatim>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") {
721 if (&yytext[1]==yyextra->blockName)
723 yyextra->inVerbatim=
false;
724 BEGIN(yyextra->lastCommentContext);
729 if (yytext==yyextra->blockName)
731 yyextra->inVerbatim=
false;
732 BEGIN(yyextra->lastCommentContext);
736 if (yyextra->javaBlock==0)
742 yyextra->javaBlock++;
747 if (yyextra->javaBlock==0)
753 yyextra->javaBlock--;
754 if (yyextra->javaBlock==0)
757 yyextra->inVerbatim=
false;
758 BEGIN(yyextra->lastCommentContext);
766<VerbatimCode>("```"[`]*|"~~~"[~]*) {
767 if (yytext[0]==
'`' && (yyextra->blockName==
"`" || yyextra->blockName==
"``"))
771 yyextra->inVerbatim=
false;
772 BEGIN(yyextra->lastCommentContext);
777 if (yytext[0]==yyextra->blockName[0])
779 yyextra->inVerbatim=
false;
780 BEGIN(yyextra->lastCommentContext);
786 if (yyextra->blockName==
"``")
788 yyextra->inVerbatim=
false;
789 BEGIN(yyextra->lastCommentContext);
794 if (yyextra->blockName==
"`")
796 yyextra->inVerbatim=
false;
797 BEGIN(yyextra->lastCommentContext);
800<VerbatimCode>"`"{1,2} {
802 if (yytext==yyextra->blockName)
804 yyextra->inVerbatim=
false;
805 BEGIN(yyextra->lastCommentContext);
808<VerbatimCode>{CMD}("enddot"|"endcode"|"endmsc"|"enduml")/("{")? {
810 if (&yytext[1]==yyextra->blockName)
812 yyextra->inVerbatim=
false;
813 BEGIN(yyextra->lastCommentContext);
816<VerbatimCode>^[ \t]*{CPPC}[\!\/]? {
817 if (!yyextra->inSpecialComment || yyextra->mlBrief)
824 while (yytext[l]==
' ' || yytext[l]==
'\t')
839<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]* {
842<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n{B}*"//" {
843 if (yyextra->lastCommentContext!=ReadLine)
852<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n {
853 if (yyextra->lastCommentContext==ReadLine)
855 yyextra->inVerbatim=
false;
856 BEGIN(yyextra->lastCommentContext);
860<Verbatim,VerbatimCode>\n {
862 if (yyextra->lastCommentContext == IncludeFile)
867<Verbatim>^[ \t]*{CPPC}[/!] {
868 if (yyextra->blockName==
"enddot" || yyextra->blockName==
"endmsc" || yyextra->blockName==
"enduml" || yyextra->blockName.at(0)==
'f')
872 while (yytext[l]==
' ' || yytext[l]==
'\t')
884<Verbatim,VerbatimCode>. {
888 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
900 BEGIN(yyextra->stringContext);
908<SkipVerbString>[^"\n]+ {
911<SkipVerbString>\"\" {
914<SkipVerbString>"\"" {
916 BEGIN(yyextra->stringContext);
925 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
937 BEGIN(yyextra->charContext);
946<CComment,CNComment>[^ `~<\\!@*\n{\"'\/-`]* {
949<CComment,CNComment>^{B}*"*"+[^*\/<\\@\n{\"`]* {
950 if (yyextra->lang==SrcLangExt::Markdown) REJECT;
952 if (yyextra->col>yyextra->blockHeadCol)
955 yyextra->blockHeadCol=yyextra->col;
961 if (yyextra->lang!=SrcLangExt::Python)
965 else if (yyextra->pythonDocStringChar != yytext[0])
971 yyextra->nestingCount--;
972 yyextra->pythonDocString =
FALSE;
973 yyextra->pythonDocStringChar =
'\0';
978<CComment,CNComment>\n {
981 if (yyextra->lang==SrcLangExt::Fortran)
986<CComment,CNComment>"/""/"+/"*/" {
990<CComment,CNComment>"/"+"*" {
991 if (yyextra->lang==SrcLangExt::Python ||
992 yyextra->lang==SrcLangExt::Markdown)
996 yyextra->nestingCount++;
997 yyextra->commentStack.push(yyextra->lineNr);
1000<CComment,CNComment>^{B}*"*"+"/" |
1001<CComment,CNComment>"*"+"/" {
1002 if (yyextra->lang==SrcLangExt::Python ||
1003 yyextra->lang==SrcLangExt::Markdown)
1010 yyextra->nestingCount--;
1011 if (yyextra->nestingCount<=0)
1018 yyextra->commentStack.pop();
1023<CComment,CNComment>"\n"/[ \t]*"#" {
1024 if (yyextra->lang!=SrcLangExt::VHDL)
1032 yyextra->vhdl =
FALSE;
1042<CComment,CNComment>"\n"/[ \t]*"-" {
1043 if (yyextra->lang!=SrcLangExt::Python || yyextra->pythonDocString)
1053<CComment,CNComment>"\n"/[ \t]*[^ \t#\-] {
1054 if (yyextra->lang==SrcLangExt::Python)
1056 if (yyextra->pythonDocString)
1066 else if (yyextra->lang==SrcLangExt::VHDL)
1070 yyextra->vhdl =
FALSE;
1096<CComment,CNComment>{CMD}"~"[a-z_A-Z-]* {
1097 if (yyextra->lang!=SrcLangExt::Markdown) REJECT;
1104 warn(yyextra->fileName,yyextra->lineNr,
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
bool isEmpty() const
Returns TRUE iff the string is empty.
#define Config_getEnumAsString(name)
#define Config_isAvailableEnum(name, value)
#define warn(file, line, fmt,...)
int qstricmp(const char *s1, const char *s2)
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...
1110<CComment,CNComment>{CMD}{CMD} |
1111<CComment,CNComment>. {
1114<SkipLang>{CMD}"~"[a-zA-Z-]* {
1118 warn(yyextra->fileName,yyextra->lineNr,
1127<SkipLang>[^*@\\\n]* {
1134<SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n {
1137<SComment>\n[ \t]*{CPPC}"/"{SLASHopt}/\n {
1140<SComment>^[ \t]*{CPPC}"/"[^\/\n]/.*\n {
1142 yyextra->readLineCtx=YY_START;
1143 YY_CURRENT_BUFFER->yy_at_bol=1;
1146<SComment>\n[ \t]*{CPPC}[\/!]("<")?[ \t]*{CMD}"}".*\n {
1150 yyextra->inSpecialComment=
false;
1151 yyextra->inRoseComment=
false;
1154<SComment>\n[ \t]*{CPPC}"/"[^\\@\/\n]/.*\n {
1156 yyextra->readLineCtx=YY_START;
1157 YY_CURRENT_BUFFER->yy_at_bol=1;
1160<SComment>^[ \t]*{CPPC}"!" |
1161<SComment>^[ \t]*{CPPC}"!<"/.*\n |
1162<SComment>^[ \t]*{CPPC}"!"[^<]/.*\n {
1164 yyextra->readLineCtx=YY_START;
1165 YY_CURRENT_BUFFER->yy_at_bol=1;
1168<SComment>\n[ \t]*{CPPC}"!" |
1169<SComment>\n[ \t]*{CPPC}"!<"/.*\n |
1170<SComment>\n[ \t]*{CPPC}"!"[^<\n]/.*\n {
1172 yyextra->readLineCtx=YY_START;
1173 YY_CURRENT_BUFFER->yy_at_bol=1;
1176<SComment>^[ \t]*{CPPC}"##"/.*\n {
1177 if (!yyextra->inRoseComment)
1184 yyextra->readLineCtx=YY_START;
1185 YY_CURRENT_BUFFER->yy_at_bol=1;
1189<SComment>\n[ \t]*{CPPC}"##"/.*\n {
1190 if (!yyextra->inRoseComment)
1197 yyextra->readLineCtx=YY_START;
1198 YY_CURRENT_BUFFER->yy_at_bol=1;
1205 yyextra->inSpecialComment=
FALSE;
1206 yyextra->inRoseComment=
FALSE;
1207 yyextra->insertCppCommentMarker=
false;
1208 yyextra->readLineCtx = Scan;
1218<ReadLine,CopyLine>"*" {
1221<ReadLine,CopyLine>{RL} {
1224<ReadLine,CopyLine>{RL}/{B}{CMD}"ilinebr"{B} {
1227<ReadLine,CopyLine>{RLopt}/\n {
1229 yyextra->insertCppCommentMarker=
false;
1230 BEGIN(yyextra->readLineCtx);
1232<CComment,CNComment,ReadLine>"\<" {
1235<CComment,CNComment,ReadLine>{CMD}{CMD}[~a-z_A-Z][a-z_A-Z0-9]*[ \t]* {
1239<CComment,ReadLine,IncludeFile>{CMD}("include"{OPTS}|"includedoc"{OPTS}*) {
1240 if (!
parseIncludeOptions(yyscanner,std::string_view{yytext,
static_cast<size_t>(yyleng)})) REJECT;
1241 yyextra->includeCtx = YY_START;
1242 yyextra->firstIncludeLine =
true;
1243 yyextra->insertCommentCol = yyextra->col;
1244 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1246 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1251<CComment,ReadLine,IncludeFile>{CMD}("snippet"{OPTS}|"snippetdoc"{OPTS}*) {
1252 if (!
parseIncludeOptions(yyscanner,std::string_view{yytext,
static_cast<size_t>(yyleng)})) REJECT;
1253 yyextra->includeCtx = YY_START;
1254 yyextra->firstIncludeLine =
true;
1255 yyextra->insertCommentCol = yyextra->col;
1256 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1258 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1263<IncludeDoc,SnippetDoc>{B}*
1264<IncludeDoc>{FILEMASK}|"\""[^\n\"]+"\"" {
1268 fileName=fileName.
mid(1,fileName.
length()-2);
1276 BEGIN(yyextra->includeCtx);
size_t length() const
Returns the length of the string, not counting the 0-terminator.
1279<SnippetDoc>({FILEMASK}|"\""[^\n\"]+"\""){B}+ {
1280 yyextra->snippetFileName=yytext;
1281 yyextra->snippetFileName=yyextra->snippetFileName.stripWhiteSpace();
1282 if (yyextra->snippetFileName ==
"this") yyextra->snippetFileName=yyextra->fileName;
1283 yyextra->snippetName =
"";
1284 BEGIN(SnippetDocTag);
1286<SnippetDocTag>[^\\@\n]+ {
1287 yyextra->snippetName += yytext;
1289<SnippetDocTag>{CMD} {
1290 yyextra->snippetName += yytext;
1292<SnippetDocTag>(\n|{CMD}"ilinebr") {
1293 for (
int i=(
int)yyleng-1;i>=0;i--) unput(yytext[i]);
1294 yyextra->snippetName = yyextra->snippetName.stripWhiteSpace();
1295 QCString blockId =
"["+yyextra->snippetName+
"]";
1302 BEGIN(yyextra->includeCtx);
1306<IncludeDoc,SnippetDoc>\n {
1311 BEGIN(yyextra->includeCtx);
1313<IncludeDoc,SnippetDoc>. {
1315 BEGIN(yyextra->includeCtx);
1317<CComment,ReadLine,IncludeFile>{CMD}"cond"/[^a-z_A-Z0-9] {
1318 yyextra->condCtx = YY_START;
1321<CComment,ReadLine,IncludeFile>{CMD}"endcond"/[^a-z_A-Z0-9] {
1322 bool oldSkip=yyextra->skip;
1324 if (YY_START==CComment && oldSkip && !yyextra->skip)
1327 if (yyextra->lang!=SrcLangExt::Python &&
1328 yyextra->lang!=SrcLangExt::VHDL &&
1329 yyextra->lang!=SrcLangExt::Markdown &&
1330 yyextra->lang!=SrcLangExt::Fortran)
1332 yyextra->outBuf+=
'/';
1333 yyextra->outBuf+=
'*';
1335 if (yyextra->specialComment)
1337 yyextra->outBuf+=
'*';
1343<CondLine>[!()&| \ta-z_A-Z0-9.\-]+ {
1346<CComment,ReadLine,IncludeFile>{CMD}"cond"{WSopt}/\n {
1347 yyextra->condCtx=YY_START;
1355<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]* {
1356 bool inCppComment = YY_START==ReadLine && yyextra->readLineCtx==SComment;
1357 bool inCComment = YY_START==CComment && yyextra->blockHeadCol>0;
1360<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{B}?{CMD}"ilinebr"{B}{CMD}"ialias{" {
1361 yyextra->lastBlockContext=YY_START;
1362 yyextra->blockCount=1;
1363 int extraSpace = (yytext[0]==
' '? 1:0);
1364 yyextra->aliasString=yytext+9+extraSpace;
1365 yyextra->aliasCmd=yytext+9+extraSpace;
1366 yyextra->lastEscaped=0;
1367 BEGIN( ReadAliasArgs );
1369<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]*"{" {
1370 yyextra->lastBlockContext=YY_START;
1371 yyextra->blockCount=1;
1372 yyextra->aliasString=yytext;
1373 yyextra->aliasCmd=yytext;
1374 yyextra->lastEscaped=0;
1375 BEGIN( ReadAliasArgs );
1377<ReadAliasArgs>^[ \t]*"*" {
1379 if (indent>yyextra->blockHeadCol)
1381 yyextra->aliasString+=yytext;
1388<ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]* {
1390<ReadAliasArgs>[^{}\n\\\*]+ {
1391 yyextra->aliasString+=yytext;
1392 yyextra->lastEscaped=
FALSE;
1394<ReadAliasArgs>"\\" {
1395 if (yyextra->lastEscaped) yyextra->lastEscaped=
FALSE;
1396 else yyextra->lastEscaped=
TRUE;
1397 yyextra->aliasString+=yytext;
1399<ReadAliasArgs>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") {
1400 yyextra->aliasString+=yytext;
1401 if (yyextra->inVerbatim && &yytext[1]==yyextra->blockName)
1410 yyextra->inVerbatim=
false;
1411 BEGIN(yyextra->lastCommentContext);
1415 yyextra->aliasString+=yytext;
1416 yyextra->lastEscaped=
FALSE;
1417 if (yyextra->inVerbatim)
1421 BEGIN( yyextra->lastBlockContext );
1425 yyextra->aliasString+=yytext;
1426 if (!yyextra->lastEscaped) yyextra->blockCount++;
1427 yyextra->lastEscaped=
FALSE;
1430 yyextra->aliasString+=yytext;
1431 if (!yyextra->lastEscaped) yyextra->blockCount--;
1432 if (yyextra->blockCount==0)
1434 bool inCppComment = yyextra->lastBlockContext==ReadLine && yyextra->readLineCtx==SComment;
1435 bool inCComment = yyextra->lastBlockContext==CComment && yyextra->blockHeadCol>0;
1436 replaceAliases(yyscanner,yyextra->aliasString.view(),inCppComment,inCComment);
1437 BEGIN( yyextra->lastBlockContext );
1439 yyextra->lastEscaped=
FALSE;
1442 yyextra->aliasString+=yytext;
1443 yyextra->lastEscaped=
FALSE;
1450 yyextra->insertCppCommentMarker=
false;
1451 BEGIN(yyextra->readLineCtx);
1453<ReadLine>{CMD}{CMD} |
1468 if (YY_START == ReadAliasArgs)
1470 warn(yyextra->fileName,yyextra->lineNr,
1471 "Reached end of file while still searching closing '}}' of an alias argument (probable start: '{}')",
1474 else if (YY_START==Verbatim || YY_START==VerbatimCode)
1476 warn(yyextra->fileName,yyextra->lineNr,
1477 "Reached end of file while still searching closing '{}' of a verbatim block starting at line {}",
1478 yyextra->blockName,yyextra->verbatimLine);
1480 if (yyextra->includeStack.empty())
1482 yyextra->insertCppCommentMarker=
false;
1487 std::unique_ptr<commentcnv_FileState> &fs = yyextra->includeStack.back();
1488 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
1489 yy_switch_to_buffer(fs->bufState, yyscanner);
1490 yy_delete_buffer(oldBuf, yyscanner);
1491 BEGIN(fs->oldState);
1492 yyextra->fileName = fs->oldFileName;
1493 yyextra->lineNr = fs->oldLineNr;
1494 yyextra->inBuf = fs->oldFileBuf;
1495 yyextra->inBufPos = fs->oldFileBufPos;
1496 yyextra->includeCtx = fs->oldIncludeCtx;
1498 if (fs->oldRaiseLvl!=yyextra->raiseLevel)
1500 lineStr+=
"\\iraise " + std::to_string(fs->oldRaiseLvl)+
" ";
1502 if (fs->oldRaiseLbl!=yyextra->raiseLabel)
1504 lineStr+=
"\\iprefix \"" + fs->oldRaiseLbl +
"\" ";
1506 lineStr+=
"\\ilinebr ";
1507 yyextra->raiseLevel = fs->oldRaiseLvl;
1508 yyextra->raiseLabel = fs->oldRaiseLbl;
1510 yyextra->includeStack.pop_back();
QCString & setNum(short n)
std::string_view view() const
1522 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1525 size_t optIdxStart = s.find(
'{');
1526 size_t optIdxEnd = optIdxStart!=std::string::npos ? s.find(
"}",optIdxStart+1) : std::string::npos;
1527 std::string cmdName;
1529 if (optIdxStart == std::string::npos)
1536 optList =
split(std::string{s.substr(optIdxStart+1,optIdxEnd-optIdxStart-1)},
",");
1538 bool isDoc = cmdName==
"includedoc" || cmdName==
"snippetdoc";
1539 for (
const auto &opt : optList)
1550 for (
const auto &opt : optList)
1553 size_t posEqual = locOpt.find(
'=');
1554 std::string_view option = posEqual!=std::string::npos ?
stripWhiteSpace(locOpt.substr(0,posEqual)) : locOpt;
1555 std::string_view value = posEqual!=std::string::npos ?
stripWhiteSpace(locOpt.substr(posEqual+1)) : std::string_view();
1557 if (option==std::string_view{
"doc"} && value.empty())
1560 else if (option==std::string_view{
"raise"} && !value.empty())
1562 yyextra->raiseIncrement = atoi(value.data());
1565 warn(yyextra->fileName,yyextra->lineNr,
"Raising section level from {} to {}, exceeds allowed range [0-{}], adjusting",
1570 else if (option==std::string_view{
"prefix"} && !value.empty())
1572 yyextra->raisePrefix = value;
1576 warn(yyextra->fileName,yyextra->lineNr,
"Unsupported option '{}' for {} command",option, cmdName);
1587 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1588 if (s.empty())
return;
1590 size_t len = s.length();
1593 while (p<len && (c=s[p]) && (c==
' ' || c==
'\t' || c==
'\n'))
1596 if (c==
'\n') { yyextra->lineNr++; yyextra->col=0; }
else { yyextra->col++; }
1601 while (p<len && (c=s[p]) && (c==
'/' || c==
'!' || c==
'#'))
1605 if (p<len && s[p]==
'<')
1619 yyextra->outBuf+=
' ';
1623 if (blanks>1) { yyextra->outBuf+=
'*'; yyextra->col++; }
1624 yyextra->outBuf+=
' ';
1628 yyextra->outBuf+=s.substr(p);
1629 yyextra->col+=s.substr(p).length();
1641 else if (c==
'\t') col+=tabSize-(col%tabSize);
1650 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1651 size_t len = s.length();
1654 for (
size_t i=0;i<len;i++)
1659 yyextra->outBuf+=
'\n';
1664 yyextra->col+=tabSize-(yyextra->col%tabSize);
1675 for (
size_t i=0;i<len;i++)
1679 case '\n': yyextra->col=0;
1681 yyextra->lineNr++;
break;
1682 case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize);
break;
1683 default: yyextra->col++;
break;
1691 copyToOutput(yyscanner,std::string_view{s,(size_t)len});
1696 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1697 while (!yyextra->commentStack.empty()) yyextra->commentStack.pop();
1702 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1705 bool expResult = prs.
parse(yyextra->fileName,yyextra->lineNr,sectId);
1706 yyextra->condStack.emplace(yyextra->lineNr,sectId,yyextra->skip);
1715 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1716 if (yyextra->condStack.empty())
1718 warn(yyextra->fileName,yyextra->lineNr,
"Found \\endcond command without matching \\cond");
1719 yyextra->skip=
FALSE;
1725 yyextra->condStack.pop();
1732 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1733 bool oldSkip=yyextra->skip;
1735 if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
1736 !oldSkip && yyextra->skip)
1738 if (yyextra->lang!=SrcLangExt::Python &&
1739 yyextra->lang!=SrcLangExt::VHDL &&
1740 yyextra->lang!=SrcLangExt::Markdown &&
1741 yyextra->lang!=SrcLangExt::Fortran)
1743 yyextra->outBuf+=
'*';
1744 yyextra->outBuf+=
'/';
1748 if (yyextra->readLineCtx==SComment)
1754 BEGIN(yyextra->condCtx);
1769 int m1 = text.
find(marker);
1770 if (m1==-1)
return result;
1771 int m2 = text.
find(marker,m1+
static_cast<int>(marker.
length()));
1772 if (m2==-1)
return result;
1776 while (!found && (i=text.
find(
'\n',p))!=-1)
1778 found = (p<=m1 && m1<i);
1786 while ((i=text.
find(
'\n',p))!=-1)
1806 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1807 int startCol=yyextra->blockHeadCol;
1808 int contentCol=yyextra->insertCommentCol;
1809 int markerSpace=contentCol-startCol;
1813 if (yyextra->lang==SrcLangExt::Python)
1815 if (yyextra->pythonDocString)
1824 else if (yyextra->lang==SrcLangExt::Fortran)
1828 else if (yyextra->lang==SrcLangExt::Markdown)
1832 else if (yyextra->insertCppCommentMarker)
1847 for (;i<startCol;i++)
1851 if (
static_cast<int>(marker.length())<=markerSpace && !yyextra->firstIncludeLine)
1856 for (;i<contentCol;i++)
1860 yyextra->firstIncludeLine =
false;
1866 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1874 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"included file name '{}' is ambiguous"
1877 bool alreadyProcessed = std::any_of(
1878 yyextra->includeStack.begin(),
1879 yyextra->includeStack.end(),
1880 [&absFileName,&blockId](
const auto &lfs)
1881 { return lfs->fileName==absFileName && lfs->blockId==blockId; }
1884 if (alreadyProcessed)
1888 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"recursive usage of '\\snippet{{doc}}' block with name '{}' and file name '{}', skipping",
1889 blockId,absFileName);
1893 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"recursive usage of '\\include{{doc}}' with file name '{}', skipping", absFileName);
1898 auto fs = std::make_unique<commentcnv_FileState>();
1901 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"\\{}{{doc}} file '{}' could not be read",blockId.
isEmpty()?
"include":
"snippet",absFileName);
1912 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"block marked with {} for \\snippet{{doc}} should appear twice in file {}, found it {:d} times, skipping",
1913 blockId,absFileName,count);
1919 fs->fileBuf.clear();
1922 fs->fileBuf.append(incText.
str());
1925 int oldRaiseLevel = yyextra->raiseLevel;
1926 QCString oldRaiseLabel = yyextra->raiseLabel;
1927 yyextra->raiseLevel+=yyextra->raiseIncrement;
1928 yyextra->raiseLabel+=yyextra->raisePrefix;
1929 QCString lineStr=
" \\ifile \""+absFileName+
"\" \\iline " + std::to_string(lineNr)+
" ";
1930 if (yyextra->raiseLevel>0)
1932 lineStr+=
"\\iraise " + std::to_string(yyextra->raiseLevel)+
" ";
1934 if (!yyextra->raiseLabel.isEmpty())
1936 lineStr+=
"\\iprefix \"" + yyextra->raiseLabel +
"\" ";
1938 lineStr+=
"\\ilinebr ";
1941 fs->fileName = absFileName;
1942 fs->bufState = YY_CURRENT_BUFFER;
1943 fs->oldLineNr = yyextra->lineNr;
1944 fs->oldFileName = yyextra->fileName;
1945 fs->oldState = yyextra->includeCtx;
1946 fs->oldFileBuf = yyextra->inBuf;
1947 fs->oldFileBufPos = yyextra->inBufPos;
1948 fs->oldIncludeCtx = yyextra->includeCtx;
1949 fs->oldRaiseLvl = oldRaiseLevel;
1950 fs->oldRaiseLbl = oldRaiseLabel;
1951 fs->blockId = blockId;
1952 yy_switch_to_buffer(yy_create_buffer(
nullptr,
YY_BUF_SIZE, yyscanner),yyscanner);
1953 yyextra->fileName = absFileName;
1954 yyextra->lineNr = lineNr;
1955 yyextra->inBuf = &fs->fileBuf;
1956 yyextra->inBufPos = 0;
1957 yyextra->includeStack.push_back(std::move(fs));
1963 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"\\{}{{doc}} file '{}' not found",blockId.
isEmpty()?
"include":
"snippet",inc);
1974 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1975 if (s.empty())
return;
1976 size_t pos = s.find(
'{');
1977 std::string cmd { s.substr(1, pos!=std::string::npos ? pos-1 : s.length()-1) };
1978 auto &expAlias = yyextra->expandedAliases;
1979 if (std::find(expAlias.begin(),expAlias.end(),cmd)!=std::end(expAlias))
1984 else if (cmd==
"ialias")
1986 if (s.length()>cmd.length()+3)
1988 std::string value { s.substr(cmd.length()+2,s.length()-cmd.length()-3) };
1990 expAlias.erase(std::remove(expAlias.begin(),expAlias.end(),value),expAlias.end());
1995 if (yyextra->inVerbatim)
1998 std::string blk = yyextra->blockName.str();
1999 assert(!blk.empty());
2000 bool isNamedCommand=
isId(blk[0]);
2003 while ((i=result.find(blk,p))!=std::string::npos && !found)
2005 found = !isNamedCommand ||
2006 (i>0 && (result[i-1]==
'\\' || result[i-1]==
'@') && !
isId(result[i+blk.length()]));
2007 p = i+yyextra->blockName.length();
2019 size_t numSpaces = yyextra->blockHeadCol>1 ? yyextra->blockHeadCol-1 : 0;
2020 std::string spaces(numSpaces,
' ');
2021 if (replaceCppComment)
2025 std::string replacement =
"\n"+spaces+
"///";
2028 else if (replaceCComment)
2030 std::string replacement =
"\n"+spaces+
" * ";
2033 expAlias.push_back(cmd);
2035 result +=
" \\ilinebr \\ialias{";
2038 for (
int i=(
int)result.length()-1; i>=0; i--)
2052 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2053 int bytesInBuf =
static_cast<int>(yyextra->inBuf->size())-yyextra->inBufPos;
2054 int bytesToCopy = std::min(max_size,bytesInBuf);
2055 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
2056 yyextra->inBufPos+=bytesToCopy;
2062 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2063 if (yyextra->mlBrief || yyextra->skip)
2071 if (i==yyextra->blockHeadCol || i+1==yyextra->blockHeadCol)
2078 for (i=(
int)yyleng-1;i>=0;i--) unput(yytext[i]);
2079 yyextra->inSpecialComment=
FALSE;
2096 commentcnvYYlex_init_extra(&extra,&yyscanner);
2100 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2102 yyextra->inBufPos = 0;
2105 yyextra->skip =
FALSE;
2106 yyextra->fileName = fileName;
2108 yyextra->pythonDocString =
FALSE;
2109 yyextra->lineNr = 1;
2110 yyextra->raiseLevel = 0;
2111 yyextra->raiseLabel =
"";
2112 yyextra->raiseIncrement = 0;
2113 yyextra->raisePrefix =
"";
2114 yyextra->insertCppCommentMarker=
false;
2115 yyextra->expandedAliases.clear();
2116 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2118 yyextra->vhdl =
FALSE;
2121 yyextra->isFixedForm =
FALSE;
2122 if (yyextra->lang==SrcLangExt::Fortran)
2128 if (yyextra->lang==SrcLangExt::Markdown)
2130 yyextra->nestingCount=0;
2132 yyextra->commentStack.push(yyextra->lineNr);
2139 while (!yyextra->condStack.empty())
2144 warn(yyextra->fileName,ctx.
lineNr,
"Conditional section{}does not have "
2145 "a corresponding \\endcond command within this file.",sectionInfo.
data());
2146 yyextra->condStack.pop();
2148 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2152 while (!yyextra->commentStack.empty())
2154 int lineNr = yyextra->commentStack.top();
2155 if (!first) lines +=
", ";
2158 yyextra->commentStack.pop();
2160 warn(yyextra->fileName,yyextra->lineNr,
"Reached end of file while still inside a (nested) comment. "
2161 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2163 yyextra->nestingCount = 0;
2167 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2170 commentcnvYYlex_destroy(yyscanner);
2176#include "commentcnv.l.h"
std::string resolveAliasCmd(std::string_view aliasCmd)
Copyright (C) 1997-2015 by Dimitri van Heesch.
bool parse(const QCString &fileName, int lineNr, const QCString &expr)
Copyright (C) 1997-2015 by Dimitri van Heesch.
static bool isFlagSet(const DebugMask mask)
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
static FileNameLinkedMap * exampleNameLinkedMap
Minimal replacement for QFileInfo.
int find(char c, int index=0, bool cs=TRUE) const
const std::string & str() const
QCString & sprintf(const char *format,...)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
int contains(char c, bool cs=TRUE) const
static constexpr int MaxLevel
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
#define Config_getInt(name)
std::vector< std::string > StringVector
#define warn_doc_error(file, line, fmt,...)
const char * qPrint(const char *s)
std::string substituteStringView(std::string_view s, std::string_view toReplace, std::string_view replaceWith)
Returns a new string where occurrences of substring toReplace in string s are replaced by string repl...
QCString findFilePath(const QCString &file, bool &ambig)
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
int lineBlock(const QCString &text, const QCString &marker)
Returns the line number of the line following the line with the marker.
bool readInputFile(const QCString &fileName, std::string &contents, bool filter, bool isSourceCode)
read a file name fileName and optionally filter and transcode it
bool recognizeFixedForm(const QCString &contents, FortranFormat format)
QCString showFileDefMatches(const FileNameLinkedMap *fnMap, const QCString &n)
StringVector split(const std::string &s, const std::string &delimiter)
split input string s by string delimiter delimiter.
FortranFormat convertFileNameFortranParserCode(QCString fn)