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 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
628 yyextra->lastCommentContext = YY_START;
629 yyextra->javaBlock=0;
630 if (
qstrcmp(&yytext[1],
"startuml")==0)
632 yyextra->blockName=
"enduml";
636 yyextra->blockName=
QCString(
"end")+&yytext[1];
638 yyextra->inVerbatim=
true;
639 yyextra->verbatimLine=yyextra->lineNr;
int qstrcmp(const char *str1, const char *str2)
643<CComment,ReadLine,IncludeFile>"\\`" {
646<CComment,ReadLine,IncludeFile>"```" {
649<CComment,ReadLine,IncludeFile>"`"{1,2} {
655 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
657 yyextra->lastCommentContext = YY_START;
658 yyextra->javaBlock=0;
659 yyextra->blockName=yytext;
660 yyextra->inVerbatim=
true;
661 yyextra->verbatimLine=yyextra->lineNr;
665<CComment,ReadLine,IncludeFile>{CMD}("f$"|"f["|"f{"|"f(") {
667 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
669 yyextra->blockName=&yytext[1];
670 if (yyextra->blockName.at(1)==
'[')
672 yyextra->blockName.at(1)=
']';
674 else if (yyextra->blockName.at(1)==
'{')
676 yyextra->blockName.at(1)=
'}';
678 else if (yyextra->blockName.at(1)==
'(')
680 yyextra->blockName.at(1)=
')';
682 yyextra->lastCommentContext = YY_START;
683 yyextra->inVerbatim=
true;
684 yyextra->verbatimLine=yyextra->lineNr;
688<CComment,ReadLine,IncludeFile>"<!--!" {
689 if (yyextra->inVerbatim) REJECT;
691 yyextra->inHtmlDoxygenCommand=
true;
693<CComment,ReadLine,IncludeFile>"-->" {
694 if (yyextra->inHtmlDoxygenCommand)
696 yyextra->inHtmlDoxygenCommand=
false;
703<CComment,ReadLine,IncludeFile>"<!--" {
705 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
707 yyextra->blockName=
"-->";
708 yyextra->lastCommentContext = YY_START;
709 yyextra->inVerbatim=
true;
710 yyextra->verbatimLine=yyextra->lineNr;
714<CComment,ReadLine,IncludeFile>{CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] {
716 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
718 yyextra->blockName=
QCString(
"end")+&yytext[1];
719 yyextra->lastCommentContext = YY_START;
720 yyextra->inVerbatim=
true;
721 yyextra->verbatimLine=yyextra->lineNr;
734<Verbatim>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") {
736 if (&yytext[1]==yyextra->blockName)
738 yyextra->inVerbatim=
false;
739 BEGIN(yyextra->lastCommentContext);
744 if (yytext==yyextra->blockName)
746 yyextra->inVerbatim=
false;
747 BEGIN(yyextra->lastCommentContext);
751 if (yyextra->javaBlock==0)
757 yyextra->javaBlock++;
762 if (yyextra->javaBlock==0)
768 yyextra->javaBlock--;
769 if (yyextra->javaBlock==0)
772 yyextra->inVerbatim=
false;
773 BEGIN(yyextra->lastCommentContext);
781<VerbatimCode>("```"[`]*|"~~~"[~]*) {
782 if (yytext[0]==
'`' && (yyextra->blockName==
"`" || yyextra->blockName==
"``"))
790 if (yytext[0]==yyextra->blockName[0])
792 yyextra->inVerbatim=
false;
793 BEGIN(yyextra->lastCommentContext);
801 yyextra->inVerbatim=
false;
802 BEGIN(yyextra->lastCommentContext);
809 yyextra->inVerbatim=
false;
810 BEGIN(yyextra->lastCommentContext);
813<VerbatimCode>"`"{1,2} {
815 if (yytext==yyextra->blockName)
817 yyextra->inVerbatim=
false;
818 BEGIN(yyextra->lastCommentContext);
821<VerbatimCode>{CMD}("enddot"|"endcode"|"endmsc"|"enduml")/("{")? {
823 if (&yytext[1]==yyextra->blockName)
825 yyextra->inVerbatim=
false;
826 BEGIN(yyextra->lastCommentContext);
829<VerbatimCode>^[ \t]*{CPPC}[\!\/]? {
830 if (!yyextra->inSpecialComment || yyextra->mlBrief)
837 while (yytext[l]==
' ' || yytext[l]==
'\t')
852<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]* {
855<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n{B}*"//" {
856 if (yyextra->lastCommentContext!=ReadLine)
865<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n {
866 if (yyextra->lastCommentContext==ReadLine)
868 yyextra->inVerbatim=
false;
869 BEGIN(yyextra->lastCommentContext);
873<Verbatim,VerbatimCode>\n {
875 if (yyextra->lastCommentContext == IncludeFile)
880<Verbatim>^[ \t]*{CPPC}[/!] {
881 if (yyextra->blockName==
"enddot" || yyextra->blockName==
"endmsc" || yyextra->blockName==
"enduml" || yyextra->blockName.at(0)==
'f')
885 while (yytext[l]==
' ' || yytext[l]==
'\t')
897<Verbatim,VerbatimCode>. {
901 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
913 BEGIN(yyextra->stringContext);
921<SkipVerbString>[^"\n]+ {
924<SkipVerbString>\"\" {
927<SkipVerbString>"\"" {
929 BEGIN(yyextra->stringContext);
938 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
950 BEGIN(yyextra->charContext);
959<CComment,CNComment>[^ `~<\\!@*\n{\"'\/-`]* {
962<CComment,CNComment>^{B}*"*"+[^*\/<\\@\n{\"`]* {
963 if (yyextra->lang==SrcLangExt::Markdown) REJECT;
965 if (yyextra->col>yyextra->blockHeadCol)
968 yyextra->blockHeadCol=yyextra->col;
974 if (yyextra->lang!=SrcLangExt::Python)
978 else if (yyextra->pythonDocStringChar != yytext[0])
984 yyextra->nestingCount--;
985 yyextra->pythonDocString =
FALSE;
986 yyextra->pythonDocStringChar =
'\0';
991<CComment,CNComment>\n {
994 if (yyextra->lang==SrcLangExt::Fortran)
999<CComment,CNComment>"/""/"+/"*/" {
1003<CComment,CNComment>"/"+"*" {
1004 if (yyextra->lang==SrcLangExt::Python ||
1005 yyextra->lang==SrcLangExt::Markdown)
1009 yyextra->nestingCount++;
1010 yyextra->commentStack.push(yyextra->lineNr);
1013<CComment,CNComment>^{B}*"*"+"/" |
1014<CComment,CNComment>"*"+"/" {
1015 if (yyextra->lang==SrcLangExt::Python ||
1016 yyextra->lang==SrcLangExt::Markdown)
1023 yyextra->nestingCount--;
1024 if (yyextra->nestingCount<=0)
1031 yyextra->commentStack.pop();
1036<CComment,CNComment>"\n"/[ \t]*"#" {
1037 if (yyextra->lang!=SrcLangExt::VHDL)
1045 yyextra->vhdl =
FALSE;
1055<CComment,CNComment>"\n"/[ \t]*"-" {
1056 if (yyextra->lang!=SrcLangExt::Python || yyextra->pythonDocString)
1066<CComment,CNComment>"\n"/[ \t]*[^ \t#\-] {
1067 if (yyextra->lang==SrcLangExt::Python)
1069 if (yyextra->pythonDocString)
1079 else if (yyextra->lang==SrcLangExt::VHDL)
1083 yyextra->vhdl =
FALSE;
1109<CComment,CNComment>{CMD}"~"[a-z_A-Z-]* {
1110 if (yyextra->lang!=SrcLangExt::Markdown) REJECT;
1117 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...
1123<CComment,CNComment>{CMD}{CMD} |
1124<CComment,CNComment>. {
1127<SkipLang>{CMD}"~"[a-zA-Z-]* {
1131 warn(yyextra->fileName,yyextra->lineNr,
1140<SkipLang>[^*@\\\n]* {
1147<SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n {
1150<SComment>\n[ \t]*{CPPC}"/"{SLASHopt}/\n {
1153<SComment>^[ \t]*{CPPC}"/"[^\/\n]/.*\n {
1155 yyextra->readLineCtx=YY_START;
1156 YY_CURRENT_BUFFER->yy_at_bol=1;
1159<SComment>\n[ \t]*{CPPC}[\/!]("<")?[ \t]*{CMD}"}".*\n {
1163 yyextra->inSpecialComment=
false;
1164 yyextra->inRoseComment=
false;
1167<SComment>\n[ \t]*{CPPC}"/"[^\\@\/\n]/.*\n {
1169 yyextra->readLineCtx=YY_START;
1170 YY_CURRENT_BUFFER->yy_at_bol=1;
1173<SComment>^[ \t]*{CPPC}"!" |
1174<SComment>^[ \t]*{CPPC}"!<"/.*\n |
1175<SComment>^[ \t]*{CPPC}"!"[^<]/.*\n {
1177 yyextra->readLineCtx=YY_START;
1178 YY_CURRENT_BUFFER->yy_at_bol=1;
1181<SComment>\n[ \t]*{CPPC}"!" |
1182<SComment>\n[ \t]*{CPPC}"!<"/.*\n |
1183<SComment>\n[ \t]*{CPPC}"!"[^<\n]/.*\n {
1185 yyextra->readLineCtx=YY_START;
1186 YY_CURRENT_BUFFER->yy_at_bol=1;
1189<SComment>^[ \t]*{CPPC}"##"/.*\n {
1190 if (!yyextra->inRoseComment)
1197 yyextra->readLineCtx=YY_START;
1198 YY_CURRENT_BUFFER->yy_at_bol=1;
1202<SComment>\n[ \t]*{CPPC}"##"/.*\n {
1203 if (!yyextra->inRoseComment)
1210 yyextra->readLineCtx=YY_START;
1211 YY_CURRENT_BUFFER->yy_at_bol=1;
1218 yyextra->inSpecialComment=
FALSE;
1219 yyextra->inRoseComment=
FALSE;
1220 yyextra->insertCppCommentMarker=
false;
1221 yyextra->readLineCtx = Scan;
1225<ReadLine,CopyLine>{CCS}"*" {
1228<ReadLine,CopyLine>{CCE} {
1231<ReadLine,CopyLine>"*" {
1234<ReadLine,CopyLine>{RL} {
1237<ReadLine,CopyLine>{RL}/{B}{CMD}"ilinebr"{B} {
1240<ReadLine,CopyLine>{RLopt}/\n {
1242 yyextra->insertCppCommentMarker=
false;
1243 BEGIN(yyextra->readLineCtx);
1245<CComment,CNComment,ReadLine>"\<" {
1248<CComment,CNComment,ReadLine>{CMD}{CMD}[~a-z_A-Z][a-z_A-Z0-9]*[ \t]* {
1252<CComment,ReadLine,IncludeFile>{CMD}("include"{OPTS}|"includedoc"{OPTS}*) {
1253 if (!
parseIncludeOptions(yyscanner,std::string_view{yytext,
static_cast<size_t>(yyleng)})) REJECT;
1254 yyextra->includeCtx = YY_START;
1255 yyextra->firstIncludeLine =
true;
1256 yyextra->insertCommentCol = yyextra->col;
1257 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1259 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1264<CComment,ReadLine,IncludeFile>{CMD}("snippet"{OPTS}|"snippetdoc"{OPTS}*) {
1265 if (!
parseIncludeOptions(yyscanner,std::string_view{yytext,
static_cast<size_t>(yyleng)})) REJECT;
1266 yyextra->includeCtx = YY_START;
1267 yyextra->firstIncludeLine =
true;
1268 yyextra->insertCommentCol = yyextra->col;
1269 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1271 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1276<IncludeDoc,SnippetDoc>{B}*
1277<IncludeDoc>{FILEMASK}|"\""[^\n\"]+"\"" {
1281 fileName=fileName.
mid(1,fileName.
length()-2);
1289 BEGIN(yyextra->includeCtx);
size_t length() const
Returns the length of the string, not counting the 0-terminator.
1292<SnippetDoc>({FILEMASK}|"\""[^\n\"]+"\""){B}+ {
1293 yyextra->snippetFileName=yytext;
1294 yyextra->snippetFileName=yyextra->snippetFileName.stripWhiteSpace();
1295 if (yyextra->snippetFileName ==
"this") yyextra->snippetFileName=yyextra->fileName;
1296 yyextra->snippetName =
"";
1297 BEGIN(SnippetDocTag);
1299<SnippetDocTag>[^\\@\n]+ {
1300 yyextra->snippetName += yytext;
1302<SnippetDocTag>{CMD} {
1303 yyextra->snippetName += yytext;
1305<SnippetDocTag>(\n|{CMD}"ilinebr") {
1306 for (
int i=(
int)yyleng-1;i>=0;i--) unput(yytext[i]);
1307 yyextra->snippetName = yyextra->snippetName.stripWhiteSpace();
1308 QCString blockId =
"["+yyextra->snippetName+
"]";
1315 BEGIN(yyextra->includeCtx);
1319<IncludeDoc,SnippetDoc>\n {
1324 BEGIN(yyextra->includeCtx);
1326<IncludeDoc,SnippetDoc>. {
1328 BEGIN(yyextra->includeCtx);
1330<CComment,ReadLine,IncludeFile>{CMD}"cond"/[^a-z_A-Z0-9] {
1331 yyextra->condCtx = YY_START;
1334<CComment,ReadLine,IncludeFile>{CMD}"endcond"/[^a-z_A-Z0-9] {
1335 bool oldSkip=yyextra->skip;
1337 if (YY_START==CComment && oldSkip && !yyextra->skip)
1340 if (yyextra->lang!=SrcLangExt::Python &&
1341 yyextra->lang!=SrcLangExt::VHDL &&
1342 yyextra->lang!=SrcLangExt::Markdown &&
1343 yyextra->lang!=SrcLangExt::Fortran)
1345 yyextra->outBuf+=
'/';
1346 yyextra->outBuf+=
'*';
1348 if (yyextra->specialComment)
1350 yyextra->outBuf+=
'*';
1356<CondLine>[!()&| \ta-z_A-Z0-9.\-]+ {
1359<CComment,ReadLine,IncludeFile>{CMD}"cond"{WSopt}/\n {
1360 yyextra->condCtx=YY_START;
1368<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]* {
1369 bool inCppComment = YY_START==ReadLine && yyextra->readLineCtx==SComment;
1370 bool inCComment = YY_START==CComment && yyextra->blockHeadCol>0;
1373<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{B}?{CMD}"ilinebr"{B}{CMD}"ialias{" {
1374 yyextra->lastBlockContext=YY_START;
1375 yyextra->blockCount=1;
1376 int extraSpace = (yytext[0]==
' '? 1:0);
1377 yyextra->aliasString=yytext+9+extraSpace;
1378 yyextra->aliasCmd=yytext+9+extraSpace;
1379 yyextra->lastEscaped=0;
1380 BEGIN( ReadAliasArgs );
1382<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]*"{" {
1383 yyextra->lastBlockContext=YY_START;
1384 yyextra->blockCount=1;
1385 yyextra->aliasString=yytext;
1386 yyextra->aliasCmd=yytext;
1387 yyextra->lastEscaped=0;
1388 BEGIN( ReadAliasArgs );
1390<ReadAliasArgs>^[ \t]*"*" {
1392 if (indent>yyextra->blockHeadCol)
1394 yyextra->aliasString+=yytext;
1401<ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]* {
1403<ReadAliasArgs>[^{}\n\\\*]+ {
1404 yyextra->aliasString+=yytext;
1405 yyextra->lastEscaped=
FALSE;
1407<ReadAliasArgs>"\\" {
1408 if (yyextra->lastEscaped) yyextra->lastEscaped=
FALSE;
1409 else yyextra->lastEscaped=
TRUE;
1410 yyextra->aliasString+=yytext;
1412<ReadAliasArgs>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") {
1413 yyextra->aliasString+=yytext;
1414 if (yyextra->inVerbatim && &yytext[1]==yyextra->blockName)
1423 yyextra->inVerbatim=
false;
1424 BEGIN(yyextra->lastCommentContext);
1428 yyextra->aliasString+=yytext;
1429 yyextra->lastEscaped=
FALSE;
1430 if (yyextra->inVerbatim)
1434 BEGIN( yyextra->lastBlockContext );
1438 yyextra->aliasString+=yytext;
1439 if (!yyextra->lastEscaped) yyextra->blockCount++;
1440 yyextra->lastEscaped=
FALSE;
1443 yyextra->aliasString+=yytext;
1444 if (!yyextra->lastEscaped) yyextra->blockCount--;
1445 if (yyextra->blockCount==0)
1447 bool inCppComment = yyextra->lastBlockContext==ReadLine && yyextra->readLineCtx==SComment;
1448 bool inCComment = yyextra->lastBlockContext==CComment && yyextra->blockHeadCol>0;
1449 replaceAliases(yyscanner,yyextra->aliasString.view(),inCppComment,inCComment);
1450 BEGIN( yyextra->lastBlockContext );
1452 yyextra->lastEscaped=
FALSE;
1455 yyextra->aliasString+=yytext;
1456 yyextra->lastEscaped=
FALSE;
1463 yyextra->insertCppCommentMarker=
false;
1464 BEGIN(yyextra->readLineCtx);
1466<ReadLine>{CMD}{CMD} |
1481 if (YY_START == ReadAliasArgs)
1483 warn(yyextra->fileName,yyextra->lineNr,
1484 "Reached end of file while still searching closing '}}' of an alias argument (probable start: '{}')",
1487 else if (YY_START==Verbatim || YY_START==VerbatimCode)
1489 warn(yyextra->fileName,yyextra->lineNr,
1490 "Reached end of file while still searching closing '{}' of a verbatim block starting at line {}",
1491 yyextra->blockName,yyextra->verbatimLine);
1493 if (yyextra->includeStack.empty())
1495 yyextra->insertCppCommentMarker=
false;
1500 std::unique_ptr<commentcnv_FileState> &fs = yyextra->includeStack.back();
1501 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
1502 yy_switch_to_buffer(fs->bufState, yyscanner);
1503 yy_delete_buffer(oldBuf, yyscanner);
1504 BEGIN(fs->oldState);
1505 yyextra->fileName = fs->oldFileName;
1506 yyextra->lineNr = fs->oldLineNr;
1507 yyextra->inBuf = fs->oldFileBuf;
1508 yyextra->inBufPos = fs->oldFileBufPos;
1509 yyextra->includeCtx = fs->oldIncludeCtx;
1511 if (fs->oldRaiseLvl!=yyextra->raiseLevel)
1513 lineStr+=
"\\iraise " + std::to_string(fs->oldRaiseLvl)+
" ";
1515 if (fs->oldRaiseLbl!=yyextra->raiseLabel)
1517 lineStr+=
"\\iprefix \"" + fs->oldRaiseLbl +
"\" ";
1519 lineStr+=
"\\ilinebr ";
1520 yyextra->raiseLevel = fs->oldRaiseLvl;
1521 yyextra->raiseLabel = fs->oldRaiseLbl;
1523 yyextra->includeStack.pop_back();
QCString & setNum(short n)
std::string_view view() const
1535 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1538 size_t optIdxStart = s.find(
'{');
1539 size_t optIdxEnd = optIdxStart!=std::string::npos ? s.find(
"}",optIdxStart+1) : std::string::npos;
1540 std::string cmdName;
1542 if (optIdxStart == std::string::npos)
1549 optList =
split(std::string{s.substr(optIdxStart+1,optIdxEnd-optIdxStart-1)},
",");
1551 bool isDoc = cmdName==
"includedoc" || cmdName==
"snippetdoc";
1552 for (
const auto &opt : optList)
1563 for (
const auto &opt : optList)
1566 size_t posEqual = locOpt.find(
'=');
1567 std::string_view option = posEqual!=std::string::npos ?
stripWhiteSpace(locOpt.substr(0,posEqual)) : locOpt;
1568 std::string_view value = posEqual!=std::string::npos ?
stripWhiteSpace(locOpt.substr(posEqual+1)) : std::string_view();
1570 if (option==std::string_view{
"doc"} && value.empty())
1573 else if (option==std::string_view{
"raise"} && !value.empty())
1575 yyextra->raiseIncrement = atoi(value.data());
1578 warn(yyextra->fileName,yyextra->lineNr,
"Raising section level from {} to {}, exceeds allowed range [0-{}], adjusting",
1583 else if (option==std::string_view{
"prefix"} && !value.empty())
1585 yyextra->raisePrefix = value;
1589 warn(yyextra->fileName,yyextra->lineNr,
"Unsupported option '{}' for {} command",option, cmdName);
1600 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1601 if (s.empty())
return;
1603 size_t len = s.length();
1606 while (p<len && (c=s[p]) && (c==
' ' || c==
'\t' || c==
'\n'))
1609 if (c==
'\n') { yyextra->lineNr++; yyextra->col=0; }
else { yyextra->col++; }
1614 while (p<len && (c=s[p]) && (c==
'/' || c==
'!' || c==
'#'))
1618 if (p<len && s[p]==
'<')
1632 yyextra->outBuf+=
' ';
1636 if (blanks>1) { yyextra->outBuf+=
'*'; yyextra->col++; }
1637 yyextra->outBuf+=
' ';
1641 yyextra->outBuf+=s.substr(p);
1642 yyextra->col+=
static_cast<int>(s.substr(p).length());
1654 else if (c==
'\t') col+=tabSize-(col%tabSize);
1663 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1664 size_t len = s.length();
1667 for (
size_t i=0;i<len;i++)
1672 yyextra->outBuf+=
'\n';
1677 yyextra->col+=tabSize-(yyextra->col%tabSize);
1688 for (
size_t i=0;i<len;i++)
1692 case '\n': yyextra->col=0;
1694 yyextra->lineNr++;
break;
1695 case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize);
break;
1696 default: yyextra->col++;
break;
1704 copyToOutput(yyscanner,std::string_view{s,(size_t)len});
1709 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1710 while (!yyextra->commentStack.empty()) yyextra->commentStack.pop();
1715 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1718 bool expResult = prs.
parse(yyextra->fileName,yyextra->lineNr,sectId);
1719 yyextra->condStack.emplace(yyextra->lineNr,sectId,yyextra->skip);
1728 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1729 if (yyextra->condStack.empty())
1731 warn(yyextra->fileName,yyextra->lineNr,
"Found \\endcond command without matching \\cond");
1732 yyextra->skip=
FALSE;
1738 yyextra->condStack.pop();
1745 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1746 bool oldSkip=yyextra->skip;
1748 if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
1749 !oldSkip && yyextra->skip)
1751 if (yyextra->lang!=SrcLangExt::Python &&
1752 yyextra->lang!=SrcLangExt::VHDL &&
1753 yyextra->lang!=SrcLangExt::Markdown &&
1754 yyextra->lang!=SrcLangExt::Fortran)
1756 yyextra->outBuf+=
'*';
1757 yyextra->outBuf+=
'/';
1761 if (yyextra->readLineCtx==SComment)
1767 BEGIN(yyextra->condCtx);
1782 int m1 = text.
find(marker);
1783 if (m1==-1)
return result;
1784 int m2 = text.
find(marker,m1+
static_cast<int>(marker.
length()));
1785 if (m2==-1)
return result;
1789 while (!found && (i=text.
find(
'\n',p))!=-1)
1791 found = (p<=m1 && m1<i);
1799 while ((i=text.
find(
'\n',p))!=-1)
1819 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1820 int startCol=yyextra->blockHeadCol;
1821 int contentCol=yyextra->insertCommentCol;
1822 int markerSpace=contentCol-startCol;
1826 if (yyextra->lang==SrcLangExt::Python)
1828 if (yyextra->pythonDocString)
1837 else if (yyextra->lang==SrcLangExt::Fortran)
1841 else if (yyextra->lang==SrcLangExt::Markdown)
1845 else if (yyextra->insertCppCommentMarker)
1860 for (;i<startCol;i++)
1864 if (
static_cast<int>(marker.length())<=markerSpace && !yyextra->firstIncludeLine)
1867 i+=
static_cast<int>(marker.length());
1869 for (;i<contentCol;i++)
1873 yyextra->firstIncludeLine =
false;
1879 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1887 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"included file name '{}' is ambiguous"
1890 bool alreadyProcessed = std::any_of(
1891 yyextra->includeStack.begin(),
1892 yyextra->includeStack.end(),
1893 [&absFileName,&blockId](
const auto &lfs)
1894 { return lfs->fileName==absFileName && lfs->blockId==blockId; }
1897 if (alreadyProcessed)
1901 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"recursive usage of '\\snippet{{doc}}' block with name '{}' and file name '{}', skipping",
1902 blockId,absFileName);
1906 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"recursive usage of '\\include{{doc}}' with file name '{}', skipping", absFileName);
1911 auto fs = std::make_unique<commentcnv_FileState>();
1914 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"\\{}{{doc}} file '{}' could not be read",blockId.
isEmpty()?
"include":
"snippet",absFileName);
1925 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"block marked with {} for \\snippet{{doc}} should appear twice in file {}, found it {:d} times, skipping",
1926 blockId,absFileName,count);
1932 fs->fileBuf.clear();
1935 fs->fileBuf.append(incText.
str());
1938 int oldRaiseLevel = yyextra->raiseLevel;
1939 QCString oldRaiseLabel = yyextra->raiseLabel;
1940 yyextra->raiseLevel+=yyextra->raiseIncrement;
1941 yyextra->raiseLabel+=yyextra->raisePrefix;
1942 QCString lineStr=
" \\ifile \""+absFileName+
"\" \\iline " + std::to_string(lineNr)+
" ";
1943 if (yyextra->raiseLevel>0)
1945 lineStr+=
"\\iraise " + std::to_string(yyextra->raiseLevel)+
" ";
1947 if (!yyextra->raiseLabel.isEmpty())
1949 lineStr+=
"\\iprefix \"" + yyextra->raiseLabel +
"\" ";
1951 lineStr+=
"\\ilinebr ";
1954 fs->fileName = absFileName;
1955 fs->bufState = YY_CURRENT_BUFFER;
1956 fs->oldLineNr = yyextra->lineNr;
1957 fs->oldFileName = yyextra->fileName;
1958 fs->oldState = yyextra->includeCtx;
1959 fs->oldFileBuf = yyextra->inBuf;
1960 fs->oldFileBufPos = yyextra->inBufPos;
1961 fs->oldIncludeCtx = yyextra->includeCtx;
1962 fs->oldRaiseLvl = oldRaiseLevel;
1963 fs->oldRaiseLbl = oldRaiseLabel;
1964 fs->blockId = blockId;
1965 yy_switch_to_buffer(yy_create_buffer(
nullptr,
YY_BUF_SIZE, yyscanner),yyscanner);
1966 yyextra->fileName = absFileName;
1967 yyextra->lineNr = lineNr;
1968 yyextra->inBuf = &fs->fileBuf;
1969 yyextra->inBufPos = 0;
1970 yyextra->includeStack.push_back(std::move(fs));
1976 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"\\{}{{doc}} file '{}' not found",blockId.
isEmpty()?
"include":
"snippet",inc);
1987 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1988 if (s.empty())
return;
1989 size_t pos = s.find(
'{');
1990 std::string cmd { s.substr(1, pos!=std::string::npos ? pos-1 : s.length()-1) };
1991 auto &expAlias = yyextra->expandedAliases;
1992 if (std::find(expAlias.begin(),expAlias.end(),cmd)!=std::end(expAlias))
1997 else if (cmd==
"ialias")
1999 if (s.length()>cmd.length()+3)
2001 std::string value { s.substr(cmd.length()+2,s.length()-cmd.length()-3) };
2003 expAlias.erase(std::remove(expAlias.begin(),expAlias.end(),value),expAlias.end());
2008 if (yyextra->inVerbatim)
2011 std::string blk = yyextra->blockName.str();
2012 assert(!blk.empty());
2013 bool isNamedCommand=
isId(blk[0]);
2016 while ((i=result.find(blk,p))!=std::string::npos && !found)
2018 found = !isNamedCommand ||
2019 (i>0 && (result[i-1]==
'\\' || result[i-1]==
'@') && !
isId(result[i+blk.length()]));
2020 p = i+yyextra->blockName.length();
2032 size_t numSpaces = yyextra->blockHeadCol>1 ? yyextra->blockHeadCol-1 : 0;
2033 std::string spaces(numSpaces,
' ');
2034 if (replaceCppComment)
2038 std::string replacement =
"\n"+spaces+
"///";
2041 else if (replaceCComment)
2043 std::string replacement =
"\n"+spaces+
" * ";
2046 expAlias.push_back(cmd);
2048 result +=
" \\ilinebr \\ialias{";
2051 for (
int i=(
int)result.length()-1; i>=0; i--)
2065 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2066 int bytesInBuf =
static_cast<int>(yyextra->inBuf->size())-yyextra->inBufPos;
2067 int bytesToCopy = std::min(max_size,bytesInBuf);
2068 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
2069 yyextra->inBufPos+=bytesToCopy;
2075 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2076 if (yyextra->mlBrief || yyextra->skip)
2084 if (i==yyextra->blockHeadCol || i+1==yyextra->blockHeadCol)
2091 for (i=(
int)yyleng-1;i>=0;i--) unput(yytext[i]);
2092 yyextra->inSpecialComment=
FALSE;
2109 commentcnvYYlex_init_extra(&extra,&yyscanner);
2113 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2115 yyextra->inBufPos = 0;
2118 yyextra->skip =
FALSE;
2119 yyextra->fileName = fileName;
2121 yyextra->pythonDocString =
FALSE;
2122 yyextra->lineNr = 1;
2123 yyextra->raiseLevel = 0;
2124 yyextra->raiseLabel =
"";
2125 yyextra->raiseIncrement = 0;
2126 yyextra->raisePrefix =
"";
2127 yyextra->insertCppCommentMarker=
false;
2128 yyextra->expandedAliases.clear();
2129 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2131 yyextra->vhdl =
FALSE;
2134 yyextra->isFixedForm =
FALSE;
2135 if (yyextra->lang==SrcLangExt::Fortran)
2141 if (yyextra->lang==SrcLangExt::Markdown)
2143 yyextra->nestingCount=0;
2145 yyextra->commentStack.push(yyextra->lineNr);
2152 while (!yyextra->condStack.empty())
2157 warn(yyextra->fileName,ctx.
lineNr,
"Conditional section{}does not have "
2158 "a corresponding \\endcond command within this file.",sectionInfo.
data());
2159 yyextra->condStack.pop();
2161 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2165 while (!yyextra->commentStack.empty())
2167 int lineNr = yyextra->commentStack.top();
2168 if (!first) lines +=
", ";
2171 yyextra->commentStack.pop();
2173 warn(yyextra->fileName,yyextra->lineNr,
"Reached end of file while still inside a (nested) comment. "
2174 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2176 yyextra->nestingCount = 0;
2180 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2183 commentcnvYYlex_destroy(yyscanner);
2189#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)