17 #define YY_BUF_SIZE 10*1024*1024
20%option never-interactive
21%option prefix="commentcnvYY"
23%option extra-type="struct commentcnvYY_state *"
27#define YY_TYPEDEF_YY_SCANNER_T
57#define YY_NO_UNISTD_H 1
95 const std::string *
inBuf;
154static void replaceAliases(
yyscan_t yyscanner,std::string_view s,
bool replaceCppComment=
false,
bool replaceCComment=
false);
163#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
166static inline const char *
getLexerFILE() {
return __FILE__;}
This is an alternative implementation of QCString.
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
static const char * stateToString(int state)
static const char * getLexerFILE()
Token literal values and constants.
Some helper functions for std::string.
A bunch of utility functions.
171MAILADDR ("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\-]+
198DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
199HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
200OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
201BINARY_INTEGER "0"[bB][01][01']*[01]?
202INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
206DIGIT_SEQ [0-9][0-9']*[0-9]?
207FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
208FP_EXP [eE][+-]?{DIGIT_SEQ}
209DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
210DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
212HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
213HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
214BIN_EXP [pP][+-]?{DIGIT_SEQ}
215HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
216HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
218FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
219FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
220FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
221NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
223RAWBEGIN (u|U|L|u8)?R\"[^ \t\(\)\\]{0,16}"("
224RAWEND ")"[^ \t\(\)\\]{0,16}\"
226FILEICHAR [a-z_A-Z0-9\x80-\xFF\\:\\\/\-\+=&#@]
227FILEECHAR [a-z_A-Z0-9\x80-\xFF\-\+=&#@]
228FILECHARS {FILEICHAR}*{FILEECHAR}+
229HFILEMASK {FILEICHAR}*("."{FILEICHAR}+)+{FILECHARS}*
230VFILEMASK {FILECHARS}("."{FILECHARS})*
231FILEMASK {VFILEMASK}|{HFILEMASK}
259 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
263 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
267<Scan>[^"'!\/\n\\#,\-=; \t@$]* {
275 if (yyextra->lang!=SrcLangExt::Python)
281 yyextra->pythonDocString =
TRUE;
282 yyextra->pythonDocStringChar = yytext[0];
283 yyextra->nestingCount=1;
287 yyextra->commentStack.push(yyextra->lineNr);
292 if (yyextra->lang!=SrcLangExt::Python)
302 yyextra->pythonDocString =
TRUE;
303 yyextra->pythonDocStringChar = yytext[0];
304 yyextra->nestingCount=1;
308 yyextra->commentStack.push(yyextra->lineNr);
#define Config_getBool(name)
311<Scan>{B}*![><!]/.*\n {
312 if (yyextra->lang!=SrcLangExt::Fortran)
318 yyextra->nestingCount=0;
320 yyextra->specialComment=
true;
322 yyextra->blockHeadCol=yyextra->col-2;
324 yyextra->commentStack.push(yyextra->lineNr);
327<Scan>[Cc\*][><!]/.*\n {
328 if (yyextra->lang!=SrcLangExt::Fortran)
335 if (yyextra->isFixedForm && (yyextra->col == 0))
337 yyextra->nestingCount=0;
339 yyextra->specialComment=
true;
341 yyextra->blockHeadCol=yyextra->col-1;
343 yyextra->commentStack.push(yyextra->lineNr);
352 if (yyextra->lang!=SrcLangExt::Fortran)
362 if (yyextra->lang!=SrcLangExt::Fortran)
368 if (yyextra->col == 0)
379 if (yyextra->lang!=SrcLangExt::CSharp) REJECT
381 yyextra->stringContext = YY_START;
382 BEGIN(SkipVerbString);
386 yyextra->stringContext = YY_START;
391 yyextra->charContext = YY_START;
392 if (yyextra->lang!=SrcLangExt::VHDL)
400<Scan>{CPPC}[!/]/.*\n[ \t]*{CPPC}[!/][ \t]*{CMD}"}" {
402 yyextra->inSpecialComment=
true;
403 yyextra->blockHeadCol=yyextra->col+1;
404 yyextra->insertCppCommentMarker=
true;
406 yyextra->readLineCtx=YY_START;
409<Scan>{CPPC}"!"/.*\n[ \t]*{CPPC}[\/!][^\/] |
410<Scan>({CPPC}"/"[/]*)/[^/].*\n[ \t]*{CPPC}[\/!][^\/] {
411 if (yyextra->mlBrief)
420 while (i<(
int)yyleng && yytext[i]==
'/') i++;
422 yyextra->blockHeadCol=yyextra->col+1;
423 if (yytext[2] ==
'!')
432 yyextra->inSpecialComment=
TRUE;
434 yyextra->readLineCtx=SComment;
438<Scan>{CPPC}"##Documentation"{ANYopt}/\n {
439 if (yyextra->mlBrief) REJECT;
441 yyextra->blockHeadCol=yyextra->col+1;
444 yyextra->inRoseComment=
TRUE;
447<Scan>{CPPC}[!\/]/.*\n[ \t]*{CPPC}[|\/][ \t]*{CMD}"}" {
448 yyextra->inSpecialComment=yytext[2]==
'/' || yytext[2]==
'!';
449 if (yyextra->inSpecialComment)
451 yyextra->blockHeadCol=yyextra->col+1;
454 yyextra->readLineCtx=YY_START;
457<Scan>{CPPC}[!/]/.*\n {
458 yyextra->inSpecialComment=
true;
459 yyextra->blockHeadCol=yyextra->col+1;
460 yyextra->insertCppCommentMarker=
true;
462 yyextra->readLineCtx=YY_START;
466 yyextra->inSpecialComment=
false;
468 yyextra->readLineCtx=YY_START;
475 if (yyextra->lang==SrcLangExt::Python)
479 yyextra->specialComment=(int)yyleng==3;
480 yyextra->nestingCount=1;
483 if (yyextra->specialComment)
485 yyextra->blockHeadCol=0;
492 yyextra->commentStack.push(yyextra->lineNr);
495 if (yyextra->lang!=SrcLangExt::PHP)
502 if (yyextra->lang!=SrcLangExt::Python)
508 yyextra->nestingCount=0;
510 yyextra->specialComment=(int)yyleng==2;
511 if (yyextra->specialComment)
513 yyextra->blockHeadCol=yyextra->col;
515 yyextra->commentStack.push(yyextra->lineNr);
520<Scan>"--"[^!][^\n]* {
521 if (yyextra->lang!=SrcLangExt::VHDL)
531 if (yyextra->lang!=SrcLangExt::VHDL)
537 yyextra->specialComment=
true;
538 yyextra->blockHeadCol=yyextra->col;
539 yyextra->vhdl =
TRUE;
540 yyextra->nestingCount=0;
542 yyextra->commentStack.push(yyextra->lineNr);
548 if (yyextra->lang!=SrcLangExt::Fortran)
554 yyextra->nestingCount=0;
556 yyextra->specialComment=
true;
557 yyextra->blockHeadCol=yyextra->col;
558 yyextra->commentStack.push(yyextra->lineNr);
QCString extractEndRawStringDelimiter(const char *rawEnd)
570<RawString>[^)\n]+ {
copyToOutput(yyscanner,yytext,yyleng); }
574<CComment,CNComment,ReadLine,IncludeFile>{MAILADDR} |
575<CComment,CNComment,ReadLine,IncludeFile>"<"{MAILADDR}">" {
578<CComment,IncludeFile>"{"[ \t]*"@code"/[ \t\n] {
580 yyextra->lastCommentContext = YY_START;
581 yyextra->javaBlock=1;
582 yyextra->blockName=
QCString(
"end")+&yytext[1];
583 yyextra->inVerbatim=
true;
584 yyextra->verbatimLine=yyextra->lineNr;
587<CComment,IncludeFile>"{"[ \t]*"@literal"/[ \t\n] {
589 yyextra->lastCommentContext = YY_START;
590 yyextra->javaBlock=1;
591 yyextra->blockName=
QCString(
"end")+&yytext[1];
592 yyextra->inVerbatim=
true;
593 yyextra->verbatimLine=yyextra->lineNr;
596<CComment,ReadLine,IncludeFile>{CMD}"ilinebr"[ \t]+("```"[`]*|"~~~"[~]*) {
602 yyextra->lastCommentContext = YY_START;
603 yyextra->javaBlock=0;
605 yyextra->inVerbatim=
true;
606 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
609<CComment,ReadLine,IncludeFile>^[ \t]*("```"[`]*|"~~~"[~]*) {
615 yyextra->lastCommentContext = YY_START;
616 yyextra->javaBlock=0;
618 yyextra->inVerbatim=
true;
619 yyextra->verbatimLine=yyextra->lineNr;
QCString left(size_t len) const
622<CComment,ReadLine,IncludeFile>{CMD}("dot"|"code"|"msc"|"startuml")/[^a-z_A-Z0-9] {
624 yyextra->lastCommentContext = YY_START;
625 yyextra->javaBlock=0;
626 if (
qstrcmp(&yytext[1],
"startuml")==0)
628 yyextra->blockName=
"enduml";
632 yyextra->blockName=
QCString(
"end")+&yytext[1];
634 yyextra->inVerbatim=
true;
635 yyextra->verbatimLine=yyextra->lineNr;
int qstrcmp(const char *str1, const char *str2)
638<CComment,ReadLine,IncludeFile>"\\`" {
641<CComment,ReadLine,IncludeFile>"```" {
644<CComment,ReadLine,IncludeFile>"`"{1,2} {
650 yyextra->lastCommentContext = YY_START;
651 yyextra->javaBlock=0;
652 yyextra->blockName=yytext;
653 yyextra->inVerbatim=
true;
654 yyextra->verbatimLine=yyextra->lineNr;
657<CComment,ReadLine,IncludeFile>{CMD}("f$"|"f["|"f{"|"f(") {
659 yyextra->blockName=&yytext[1];
660 if (yyextra->blockName.at(1)==
'[')
662 yyextra->blockName.at(1)=
']';
664 else if (yyextra->blockName.at(1)==
'{')
666 yyextra->blockName.at(1)=
'}';
668 else if (yyextra->blockName.at(1)==
'(')
670 yyextra->blockName.at(1)=
')';
672 yyextra->lastCommentContext = YY_START;
673 yyextra->inVerbatim=
true;
674 yyextra->verbatimLine=yyextra->lineNr;
677<CComment,ReadLine,IncludeFile>"<!--!" {
678 if (yyextra->inVerbatim) REJECT;
680 yyextra->inHtmlDoxygenCommand=
true;
682<CComment,ReadLine,IncludeFile>"-->" {
683 if (yyextra->inHtmlDoxygenCommand)
685 yyextra->inHtmlDoxygenCommand=
false;
692<CComment,ReadLine,IncludeFile>"<!--" {
694 yyextra->blockName=
"-->";
695 yyextra->lastCommentContext = YY_START;
696 yyextra->inVerbatim=
true;
697 yyextra->verbatimLine=yyextra->lineNr;
700<CComment,ReadLine,IncludeFile>{CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] {
702 yyextra->blockName=
QCString(
"end")+&yytext[1];
703 yyextra->lastCommentContext = YY_START;
704 yyextra->inVerbatim=
true;
705 yyextra->verbatimLine=yyextra->lineNr;
717<Verbatim>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") {
719 if (&yytext[1]==yyextra->blockName)
721 yyextra->inVerbatim=
false;
722 BEGIN(yyextra->lastCommentContext);
727 if (yytext==yyextra->blockName)
729 yyextra->inVerbatim=
false;
730 BEGIN(yyextra->lastCommentContext);
734 if (yyextra->javaBlock==0)
740 yyextra->javaBlock++;
745 if (yyextra->javaBlock==0)
751 yyextra->javaBlock--;
752 if (yyextra->javaBlock==0)
755 yyextra->inVerbatim=
false;
756 BEGIN(yyextra->lastCommentContext);
764<VerbatimCode>("```"[`]*|"~~~"[~]*) {
765 if (yytext[0]==
'`' && (yyextra->blockName==
"`" || yyextra->blockName==
"``"))
773 if (yytext[0]==yyextra->blockName[0])
775 yyextra->inVerbatim=
false;
776 BEGIN(yyextra->lastCommentContext);
784 yyextra->inVerbatim=
false;
785 BEGIN(yyextra->lastCommentContext);
792 yyextra->inVerbatim=
false;
793 BEGIN(yyextra->lastCommentContext);
796<VerbatimCode>"`"{1,2} {
798 if (yytext==yyextra->blockName)
800 yyextra->inVerbatim=
false;
801 BEGIN(yyextra->lastCommentContext);
804<VerbatimCode>{CMD}("enddot"|"endcode"|"endmsc"|"enduml")/("{")? {
806 if (&yytext[1]==yyextra->blockName)
808 yyextra->inVerbatim=
false;
809 BEGIN(yyextra->lastCommentContext);
812<VerbatimCode>^[ \t]*{CPPC}[\!\/]? {
813 if (!yyextra->inSpecialComment || yyextra->mlBrief)
820 while (yytext[l]==
' ' || yytext[l]==
'\t')
835<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]* {
838<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n{B}*"//" {
839 if (yyextra->lastCommentContext!=ReadLine)
848<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n {
849 if (yyextra->lastCommentContext==ReadLine)
851 yyextra->inVerbatim=
false;
852 BEGIN(yyextra->lastCommentContext);
856<Verbatim,VerbatimCode>\n {
858 if (yyextra->lastCommentContext == IncludeFile)
863<Verbatim>^[ \t]*{CPPC}[/!] {
864 if (yyextra->blockName==
"enddot" || yyextra->blockName==
"endmsc" || yyextra->blockName==
"enduml" || yyextra->blockName.at(0)==
'f')
868 while (yytext[l]==
' ' || yytext[l]==
'\t')
880<Verbatim,VerbatimCode>. {
884 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
896 BEGIN(yyextra->stringContext);
904<SkipVerbString>[^"\n]+ {
907<SkipVerbString>\"\" {
910<SkipVerbString>"\"" {
912 BEGIN(yyextra->stringContext);
921 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
933 BEGIN(yyextra->charContext);
942<CComment,CNComment>[^ `~<\\!@*\n{\"'\/-`]* {
945<CComment,CNComment>^{B}*"*"+[^*\/<\\@\n{\"`]* {
946 if (yyextra->lang==SrcLangExt::Markdown) REJECT;
948 if (yyextra->col>yyextra->blockHeadCol)
951 yyextra->blockHeadCol=yyextra->col;
957 if (yyextra->lang!=SrcLangExt::Python)
961 else if (yyextra->pythonDocStringChar != yytext[0])
967 yyextra->nestingCount--;
968 yyextra->pythonDocString =
FALSE;
969 yyextra->pythonDocStringChar =
'\0';
974<CComment,CNComment>\n {
977 if (yyextra->lang==SrcLangExt::Fortran)
982<CComment,CNComment>"/""/"+/"*/" {
986<CComment,CNComment>"/"+"*" {
987 if (yyextra->lang==SrcLangExt::Python ||
988 yyextra->lang==SrcLangExt::Markdown)
992 yyextra->nestingCount++;
993 yyextra->commentStack.push(yyextra->lineNr);
996<CComment,CNComment>^{B}*"*"+"/" |
997<CComment,CNComment>"*"+"/" {
998 if (yyextra->lang==SrcLangExt::Python ||
999 yyextra->lang==SrcLangExt::Markdown)
1006 yyextra->nestingCount--;
1007 if (yyextra->nestingCount<=0)
1014 yyextra->commentStack.pop();
1019<CComment,CNComment>"\n"/[ \t]*"#" {
1020 if (yyextra->lang!=SrcLangExt::VHDL)
1028 yyextra->vhdl =
FALSE;
1038<CComment,CNComment>"\n"/[ \t]*"-" {
1039 if (yyextra->lang!=SrcLangExt::Python || yyextra->pythonDocString)
1049<CComment,CNComment>"\n"/[ \t]*[^ \t#\-] {
1050 if (yyextra->lang==SrcLangExt::Python)
1052 if (yyextra->pythonDocString)
1062 else if (yyextra->lang==SrcLangExt::VHDL)
1066 yyextra->vhdl =
FALSE;
1092<CComment,CNComment>{CMD}"~"[a-z_A-Z-]* {
1093 if (yyextra->lang!=SrcLangExt::Markdown) REJECT;
1100 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...
1106<CComment,CNComment>{CMD}{CMD} |
1107<CComment,CNComment>. {
1110<SkipLang>{CMD}"~"[a-zA-Z-]* {
1114 warn(yyextra->fileName,yyextra->lineNr,
1123<SkipLang>[^*@\\\n]* {
1130<SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n {
1133<SComment>\n[ \t]*{CPPC}"/"{SLASHopt}/\n {
1136<SComment>^[ \t]*{CPPC}"/"[^\/\n]/.*\n {
1138 yyextra->readLineCtx=YY_START;
1139 YY_CURRENT_BUFFER->yy_at_bol=1;
1142<SComment>\n[ \t]*{CPPC}[\/!]("<")?[ \t]*{CMD}"}".*\n {
1146 yyextra->inSpecialComment=
false;
1147 yyextra->inRoseComment=
false;
1150<SComment>\n[ \t]*{CPPC}"/"[^\\@\/\n]/.*\n {
1152 yyextra->readLineCtx=YY_START;
1153 YY_CURRENT_BUFFER->yy_at_bol=1;
1156<SComment>^[ \t]*{CPPC}"!" |
1157<SComment>^[ \t]*{CPPC}"!<"/.*\n |
1158<SComment>^[ \t]*{CPPC}"!"[^<]/.*\n {
1160 yyextra->readLineCtx=YY_START;
1161 YY_CURRENT_BUFFER->yy_at_bol=1;
1164<SComment>\n[ \t]*{CPPC}"!" |
1165<SComment>\n[ \t]*{CPPC}"!<"/.*\n |
1166<SComment>\n[ \t]*{CPPC}"!"[^<\n]/.*\n {
1168 yyextra->readLineCtx=YY_START;
1169 YY_CURRENT_BUFFER->yy_at_bol=1;
1172<SComment>^[ \t]*{CPPC}"##"/.*\n {
1173 if (!yyextra->inRoseComment)
1180 yyextra->readLineCtx=YY_START;
1181 YY_CURRENT_BUFFER->yy_at_bol=1;
1185<SComment>\n[ \t]*{CPPC}"##"/.*\n {
1186 if (!yyextra->inRoseComment)
1193 yyextra->readLineCtx=YY_START;
1194 YY_CURRENT_BUFFER->yy_at_bol=1;
1201 yyextra->inSpecialComment=
FALSE;
1202 yyextra->inRoseComment=
FALSE;
1203 yyextra->insertCppCommentMarker=
false;
1204 yyextra->readLineCtx = Scan;
1214<ReadLine,CopyLine>"*" {
1217<ReadLine,CopyLine>{RL} {
1220<ReadLine,CopyLine>{RL}/{B}{CMD}"ilinebr"{B} {
1223<ReadLine,CopyLine>{RLopt}/\n {
1225 yyextra->insertCppCommentMarker=
false;
1226 BEGIN(yyextra->readLineCtx);
1228<CComment,CNComment,ReadLine>"\<" {
1231<CComment,CNComment,ReadLine>{CMD}{CMD}[~a-z_A-Z][a-z_A-Z0-9]*[ \t]* {
1235<CComment,ReadLine,IncludeFile>{CMD}("include"{OPTS}|"includedoc"{OPTS}*) {
1236 if (!
parseIncludeOptions(yyscanner,std::string_view{yytext,
static_cast<size_t>(yyleng)})) REJECT;
1237 yyextra->includeCtx = YY_START;
1238 yyextra->firstIncludeLine =
true;
1239 yyextra->insertCommentCol = yyextra->col;
1240 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1242 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1247<CComment,ReadLine,IncludeFile>{CMD}("snippet"{OPTS}|"snippetdoc"{OPTS}*) {
1248 if (!
parseIncludeOptions(yyscanner,std::string_view{yytext,
static_cast<size_t>(yyleng)})) REJECT;
1249 yyextra->includeCtx = YY_START;
1250 yyextra->firstIncludeLine =
true;
1251 yyextra->insertCommentCol = yyextra->col;
1252 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1254 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1259<IncludeDoc,SnippetDoc>{B}*
1260<IncludeDoc>{FILEMASK}|"\""[^\n\"]+"\"" {
1264 fileName=fileName.
mid(1,fileName.
length()-2);
1272 BEGIN(yyextra->includeCtx);
size_t length() const
Returns the length of the string, not counting the 0-terminator.
1275<SnippetDoc>({FILEMASK}|"\""[^\n\"]+"\""){B}+ {
1276 yyextra->snippetFileName=yytext;
1277 yyextra->snippetFileName=yyextra->snippetFileName.stripWhiteSpace();
1278 if (yyextra->snippetFileName ==
"this") yyextra->snippetFileName=yyextra->fileName;
1279 yyextra->snippetName =
"";
1280 BEGIN(SnippetDocTag);
1282<SnippetDocTag>[^\\@\n]+ {
1283 yyextra->snippetName += yytext;
1285<SnippetDocTag>{CMD} {
1286 yyextra->snippetName += yytext;
1288<SnippetDocTag>(\n|{CMD}"ilinebr") {
1289 for (
int i=(
int)yyleng-1;i>=0;i--) unput(yytext[i]);
1290 yyextra->snippetName = yyextra->snippetName.stripWhiteSpace();
1291 QCString blockId =
"["+yyextra->snippetName+
"]";
1298 BEGIN(yyextra->includeCtx);
1302<IncludeDoc,SnippetDoc>\n {
1307 BEGIN(yyextra->includeCtx);
1309<IncludeDoc,SnippetDoc>. {
1311 BEGIN(yyextra->includeCtx);
1313<CComment,ReadLine,IncludeFile>{CMD}"cond"/[^a-z_A-Z0-9] {
1314 yyextra->condCtx = YY_START;
1317<CComment,ReadLine,IncludeFile>{CMD}"endcond"/[^a-z_A-Z0-9] {
1318 bool oldSkip=yyextra->skip;
1320 if (YY_START==CComment && oldSkip && !yyextra->skip)
1323 if (yyextra->lang!=SrcLangExt::Python &&
1324 yyextra->lang!=SrcLangExt::VHDL &&
1325 yyextra->lang!=SrcLangExt::Markdown &&
1326 yyextra->lang!=SrcLangExt::Fortran)
1328 yyextra->outBuf+=
'/';
1329 yyextra->outBuf+=
'*';
1331 if (yyextra->specialComment)
1333 yyextra->outBuf+=
'*';
1339<CondLine>[!()&| \ta-z_A-Z0-9.\-]+ {
1342<CComment,ReadLine,IncludeFile>{CMD}"cond"{WSopt}/\n {
1343 yyextra->condCtx=YY_START;
1351<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]* {
1352 bool inCppComment = YY_START==ReadLine && yyextra->readLineCtx==SComment;
1353 bool inCComment = YY_START==CComment && yyextra->blockHeadCol>0;
1356<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{B}?{CMD}"ilinebr"{B}{CMD}"ialias{" {
1357 yyextra->lastBlockContext=YY_START;
1358 yyextra->blockCount=1;
1359 int extraSpace = (yytext[0]==
' '? 1:0);
1360 yyextra->aliasString=yytext+9+extraSpace;
1361 yyextra->aliasCmd=yytext+9+extraSpace;
1362 yyextra->lastEscaped=0;
1363 BEGIN( ReadAliasArgs );
1365<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]*"{" {
1366 yyextra->lastBlockContext=YY_START;
1367 yyextra->blockCount=1;
1368 yyextra->aliasString=yytext;
1369 yyextra->aliasCmd=yytext;
1370 yyextra->lastEscaped=0;
1371 BEGIN( ReadAliasArgs );
1373<ReadAliasArgs>^[ \t]*"*" {
1375 if (indent>yyextra->blockHeadCol)
1377 yyextra->aliasString+=yytext;
1384<ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]* {
1386<ReadAliasArgs>[^{}\n\\\*]+ {
1387 yyextra->aliasString+=yytext;
1388 yyextra->lastEscaped=
FALSE;
1390<ReadAliasArgs>"\\" {
1391 if (yyextra->lastEscaped) yyextra->lastEscaped=
FALSE;
1392 else yyextra->lastEscaped=
TRUE;
1393 yyextra->aliasString+=yytext;
1395<ReadAliasArgs>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") {
1396 yyextra->aliasString+=yytext;
1397 if (yyextra->inVerbatim && &yytext[1]==yyextra->blockName)
1406 yyextra->inVerbatim=
false;
1407 BEGIN(yyextra->lastCommentContext);
1411 yyextra->aliasString+=yytext;
1412 yyextra->lastEscaped=
FALSE;
1413 if (yyextra->inVerbatim)
1417 BEGIN( yyextra->lastBlockContext );
1421 yyextra->aliasString+=yytext;
1422 if (!yyextra->lastEscaped) yyextra->blockCount++;
1423 yyextra->lastEscaped=
FALSE;
1426 yyextra->aliasString+=yytext;
1427 if (!yyextra->lastEscaped) yyextra->blockCount--;
1428 if (yyextra->blockCount==0)
1430 bool inCppComment = yyextra->lastBlockContext==ReadLine && yyextra->readLineCtx==SComment;
1431 bool inCComment = yyextra->lastBlockContext==CComment && yyextra->blockHeadCol>0;
1432 replaceAliases(yyscanner,yyextra->aliasString.view(),inCppComment,inCComment);
1433 BEGIN( yyextra->lastBlockContext );
1435 yyextra->lastEscaped=
FALSE;
1438 yyextra->aliasString+=yytext;
1439 yyextra->lastEscaped=
FALSE;
1446 yyextra->insertCppCommentMarker=
false;
1447 BEGIN(yyextra->readLineCtx);
1449<ReadLine>{CMD}{CMD} |
1464 if (YY_START == ReadAliasArgs)
1466 warn(yyextra->fileName,yyextra->lineNr,
1467 "Reached end of file while still searching closing '}}' of an alias argument (probable start: '{}')",
1470 else if (YY_START==Verbatim || YY_START==VerbatimCode)
1472 warn(yyextra->fileName,yyextra->lineNr,
1473 "Reached end of file while still searching closing '{}' of a verbatim block starting at line {}",
1474 yyextra->blockName,yyextra->verbatimLine);
1476 if (yyextra->includeStack.empty())
1478 yyextra->insertCppCommentMarker=
false;
1483 std::unique_ptr<commentcnv_FileState> &fs = yyextra->includeStack.back();
1484 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
1485 yy_switch_to_buffer(fs->bufState, yyscanner);
1486 yy_delete_buffer(oldBuf, yyscanner);
1487 BEGIN(fs->oldState);
1488 yyextra->fileName = fs->oldFileName;
1489 yyextra->lineNr = fs->oldLineNr;
1490 yyextra->inBuf = fs->oldFileBuf;
1491 yyextra->inBufPos = fs->oldFileBufPos;
1492 yyextra->includeCtx = fs->oldIncludeCtx;
1494 if (fs->oldRaiseLvl!=yyextra->raiseLevel)
1496 lineStr+=
"\\iraise " + std::to_string(fs->oldRaiseLvl)+
" ";
1498 if (fs->oldRaiseLbl!=yyextra->raiseLabel)
1500 lineStr+=
"\\iprefix \"" + fs->oldRaiseLbl +
"\" ";
1502 lineStr+=
"\\ilinebr ";
1503 yyextra->raiseLevel = fs->oldRaiseLvl;
1504 yyextra->raiseLabel = fs->oldRaiseLbl;
1506 yyextra->includeStack.pop_back();
QCString & setNum(short n)
std::string_view view() const
1518 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1521 size_t optIdxStart = s.find(
'{');
1522 size_t optIdxEnd = optIdxStart!=std::string::npos ? s.find(
"}",optIdxStart+1) : std::string::npos;
1523 std::string cmdName;
1525 if (optIdxStart == std::string::npos)
1532 optList =
split(std::string{s.substr(optIdxStart+1,optIdxEnd-optIdxStart-1)},
",");
1534 bool isDoc = cmdName==
"includedoc" || cmdName==
"snippetdoc";
1535 for (
const auto &opt : optList)
1546 for (
const auto &opt : optList)
1549 size_t posEqual = locOpt.find(
'=');
1550 std::string_view option = posEqual!=std::string::npos ?
stripWhiteSpace(locOpt.substr(0,posEqual)) : locOpt;
1551 std::string_view value = posEqual!=std::string::npos ?
stripWhiteSpace(locOpt.substr(posEqual+1)) : std::string_view();
1553 if (option==std::string_view{
"doc"} && value.empty())
1556 else if (option==std::string_view{
"raise"} && !value.empty())
1558 yyextra->raiseIncrement = atoi(value.data());
1561 warn(yyextra->fileName,yyextra->lineNr,
"Raising section level from {} to {}, exceeds allowed range [0-{}], adjusting",
1566 else if (option==std::string_view{
"prefix"} && !value.empty())
1568 yyextra->raisePrefix = value;
1572 warn(yyextra->fileName,yyextra->lineNr,
"Unsupported option '{}' for {} command",option, cmdName);
1583 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1584 if (s.empty())
return;
1586 size_t len = s.length();
1589 while (p<len && (c=s[p]) && (c==
' ' || c==
'\t' || c==
'\n'))
1592 if (c==
'\n') { yyextra->lineNr++; yyextra->col=0; }
else { yyextra->col++; }
1597 while (p<len && (c=s[p]) && (c==
'/' || c==
'!' || c==
'#'))
1601 if (p<len && s[p]==
'<')
1615 yyextra->outBuf+=
' ';
1619 if (blanks>1) { yyextra->outBuf+=
'*'; yyextra->col++; }
1620 yyextra->outBuf+=
' ';
1624 yyextra->outBuf+=s.substr(p);
1625 yyextra->col+=
static_cast<int>(s.substr(p).length());
1637 else if (c==
'\t') col+=tabSize-(col%tabSize);
1646 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1647 size_t len = s.length();
1650 for (
size_t i=0;i<len;i++)
1655 yyextra->outBuf+=
'\n';
1660 yyextra->col+=tabSize-(yyextra->col%tabSize);
1671 for (
size_t i=0;i<len;i++)
1675 case '\n': yyextra->col=0;
1677 yyextra->lineNr++;
break;
1678 case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize);
break;
1679 default: yyextra->col++;
break;
1692 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1693 while (!yyextra->commentStack.empty()) yyextra->commentStack.pop();
1698 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1701 bool expResult = prs.
parse(yyextra->fileName,yyextra->lineNr,sectId);
1702 yyextra->condStack.emplace(yyextra->lineNr,sectId,yyextra->skip);
1711 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1712 if (yyextra->condStack.empty())
1714 warn(yyextra->fileName,yyextra->lineNr,
"Found \\endcond command without matching \\cond");
1715 yyextra->skip=
FALSE;
1721 yyextra->condStack.pop();
1728 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1729 bool oldSkip=yyextra->skip;
1731 if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
1732 !oldSkip && yyextra->skip)
1734 if (yyextra->lang!=SrcLangExt::Python &&
1735 yyextra->lang!=SrcLangExt::VHDL &&
1736 yyextra->lang!=SrcLangExt::Markdown &&
1737 yyextra->lang!=SrcLangExt::Fortran)
1739 yyextra->outBuf+=
'*';
1740 yyextra->outBuf+=
'/';
1744 if (yyextra->readLineCtx==SComment)
1750 BEGIN(yyextra->condCtx);
1765 int m1 = text.
find(marker);
1766 if (m1==-1)
return result;
1767 int m2 = text.
find(marker,m1+
static_cast<int>(marker.
length()));
1768 if (m2==-1)
return result;
1772 while (!found && (i=text.
find(
'\n',p))!=-1)
1774 found = (p<=m1 && m1<i);
1782 while ((i=text.
find(
'\n',p))!=-1)
1802 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1803 int startCol=yyextra->blockHeadCol;
1804 int contentCol=yyextra->insertCommentCol;
1805 int markerSpace=contentCol-startCol;
1809 if (yyextra->lang==SrcLangExt::Python)
1811 if (yyextra->pythonDocString)
1820 else if (yyextra->lang==SrcLangExt::Fortran)
1824 else if (yyextra->lang==SrcLangExt::Markdown)
1828 else if (yyextra->insertCppCommentMarker)
1843 for (;i<startCol;i++)
1847 if (
static_cast<int>(marker.length())<=markerSpace && !yyextra->firstIncludeLine)
1850 i+=
static_cast<int>(marker.length());
1852 for (;i<contentCol;i++)
1856 yyextra->firstIncludeLine =
false;
1862 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1866 if (!absFileName.
isEmpty() && fi.exists() && fi.isFile())
1870 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"included file name '{}' is ambiguous"
1873 bool alreadyProcessed = std::any_of(
1874 yyextra->includeStack.begin(),
1875 yyextra->includeStack.end(),
1876 [&absFileName,&blockId](
const auto &lfs)
1877 { return lfs->fileName==absFileName && lfs->blockId==blockId; }
1880 if (alreadyProcessed)
1884 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"recursive usage of '\\snippet{{doc}}' block with name '{}' and file name '{}', skipping",
1885 blockId,absFileName);
1889 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"recursive usage of '\\include{{doc}}' with file name '{}', skipping", absFileName);
1894 auto fs = std::make_unique<commentcnv_FileState>();
1897 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"\\{}{{doc}} file '{}' could not be read",blockId.
isEmpty()?
"include":
"snippet",absFileName);
1908 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"block marked with {} for \\snippet{{doc}} should appear twice in file {}, found it {:d} times, skipping",
1909 blockId,absFileName,count);
1915 fs->fileBuf.clear();
1918 fs->fileBuf.append(incText.
str());
1921 int oldRaiseLevel = yyextra->raiseLevel;
1922 QCString oldRaiseLabel = yyextra->raiseLabel;
1923 yyextra->raiseLevel+=yyextra->raiseIncrement;
1924 yyextra->raiseLabel+=yyextra->raisePrefix;
1925 QCString lineStr=
" \\ifile \""+absFileName+
"\" \\iline " + std::to_string(lineNr)+
" ";
1926 if (yyextra->raiseLevel>0)
1928 lineStr+=
"\\iraise " + std::to_string(yyextra->raiseLevel)+
" ";
1930 if (!yyextra->raiseLabel.isEmpty())
1932 lineStr+=
"\\iprefix \"" + yyextra->raiseLabel +
"\" ";
1934 lineStr+=
"\\ilinebr ";
1937 fs->fileName = absFileName;
1938 fs->bufState = YY_CURRENT_BUFFER;
1939 fs->oldLineNr = yyextra->lineNr;
1940 fs->oldFileName = yyextra->fileName;
1941 fs->oldState = yyextra->includeCtx;
1942 fs->oldFileBuf = yyextra->inBuf;
1943 fs->oldFileBufPos = yyextra->inBufPos;
1944 fs->oldIncludeCtx = yyextra->includeCtx;
1945 fs->oldRaiseLvl = oldRaiseLevel;
1946 fs->oldRaiseLbl = oldRaiseLabel;
1947 fs->blockId = blockId;
1948 yy_switch_to_buffer(yy_create_buffer(
nullptr,
YY_BUF_SIZE, yyscanner),yyscanner);
1949 yyextra->fileName = absFileName;
1950 yyextra->lineNr = lineNr;
1951 yyextra->inBuf = &fs->fileBuf;
1952 yyextra->inBufPos = 0;
1953 yyextra->includeStack.push_back(std::move(fs));
1959 warn_doc_error(yyextra->fileName,yyextra->lineNr,
"\\{}{{doc}} file '{}' not found",blockId.
isEmpty()?
"include":
"snippet",inc);
1968static void replaceAliases(
yyscan_t yyscanner,std::string_view s,
bool replaceCppComment,
bool replaceCComment)
1970 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
1971 if (s.empty())
return;
1972 size_t pos = s.find(
'{');
1973 std::string cmd { s.substr(1, pos!=std::string::npos ? pos-1 : s.length()-1) };
1974 auto &expAlias = yyextra->expandedAliases;
1975 if (std::find(expAlias.begin(),expAlias.end(),cmd)!=std::end(expAlias))
1980 else if (cmd==
"ialias")
1982 if (s.length()>cmd.length()+3)
1984 std::string value { s.substr(cmd.length()+2,s.length()-cmd.length()-3) };
1986 expAlias.erase(std::remove(expAlias.begin(),expAlias.end(),value),expAlias.end());
1991 if (yyextra->inVerbatim)
1994 std::string blk = yyextra->blockName.str();
1995 assert(!blk.empty());
1996 bool isNamedCommand=
isId(blk[0]);
1999 while ((i=result.find(blk,p))!=std::string::npos && !found)
2001 found = !isNamedCommand ||
2002 (i>0 && (result[i-1]==
'\\' || result[i-1]==
'@') && !
isId(result[i+blk.length()]));
2003 p = i+yyextra->blockName.length();
2015 size_t numSpaces = yyextra->blockHeadCol>1 ? yyextra->blockHeadCol-1 : 0;
2016 std::string spaces(numSpaces,
' ');
2017 if (replaceCppComment)
2021 std::string replacement =
"\n"+spaces+
"///";
2024 else if (replaceCComment)
2026 std::string replacement =
"\n"+spaces+
" * ";
2029 expAlias.push_back(cmd);
2031 result +=
" \\ilinebr \\ialias{";
2034 for (
int i=(
int)result.length()-1; i>=0; i--)
2048 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2049 int bytesInBuf =
static_cast<int>(yyextra->inBuf->size())-yyextra->inBufPos;
2050 int bytesToCopy = std::min(max_size,bytesInBuf);
2051 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
2052 yyextra->inBufPos+=bytesToCopy;
2058 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2059 if (yyextra->mlBrief || yyextra->skip)
2067 if (i==yyextra->blockHeadCol || i+1==yyextra->blockHeadCol)
2074 for (i=(
int)yyleng-1;i>=0;i--) unput(yytext[i]);
2075 yyextra->inSpecialComment=
FALSE;
2087void convertCppComments(
const std::string &inBuf,std::string &outBuf,
const std::string &fn)
2092 commentcnvYYlex_init_extra(&extra,&yyscanner);
2096 struct yyguts_t *yyg = (
struct yyguts_t*)yyscanner;
2098 yyextra->inBufPos = 0;
2101 yyextra->skip =
FALSE;
2102 yyextra->fileName = fileName;
2104 yyextra->pythonDocString =
FALSE;
2105 yyextra->lineNr = 1;
2106 yyextra->raiseLevel = 0;
2107 yyextra->raiseLabel =
"";
2108 yyextra->raiseIncrement = 0;
2109 yyextra->raisePrefix =
"";
2110 yyextra->insertCppCommentMarker=
false;
2111 yyextra->expandedAliases.clear();
2112 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2114 yyextra->vhdl =
FALSE;
2117 yyextra->isFixedForm =
FALSE;
2118 if (yyextra->lang==SrcLangExt::Fortran)
2124 if (yyextra->lang==SrcLangExt::Markdown)
2126 yyextra->nestingCount=0;
2128 yyextra->commentStack.push(yyextra->lineNr);
2135 while (!yyextra->condStack.empty())
2140 warn(yyextra->fileName,ctx.
lineNr,
"Conditional section{}does not have "
2141 "a corresponding \\endcond command within this file.",sectionInfo.data());
2142 yyextra->condStack.pop();
2144 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2148 while (!yyextra->commentStack.empty())
2150 int lineNr = yyextra->commentStack.top();
2151 if (!first) lines +=
", ";
2154 yyextra->commentStack.pop();
2156 warn(yyextra->fileName,yyextra->lineNr,
"Reached end of file while still inside a (nested) comment. "
2157 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2159 yyextra->nestingCount = 0;
2163 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2166 commentcnvYYlex_destroy(yyscanner);
2172#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
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
#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)