summaryrefslogtreecommitdiffstats
path: root/src/commentcnv.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/commentcnv.l')
-rw-r--r--src/commentcnv.l154
1 files changed, 95 insertions, 59 deletions
diff --git a/src/commentcnv.l b/src/commentcnv.l
index f3367a4..b5f8e41 100644
--- a/src/commentcnv.l
+++ b/src/commentcnv.l
@@ -18,6 +18,9 @@
%option prefix="commentcnvYY"
%option reentrant
%option extra-type="struct commentcnvYY_state *"
+%top{
+#include <stdint.h>
+}
%{
@@ -45,6 +48,8 @@
#define ADDCHAR(c) yyextra->outBuf->addChar(c)
#define ADDARRAY(a,s) yyextra->outBuf->addArray(a,s)
+
+#define USE_STATE2STRING 0
struct CondCtx
{
@@ -66,7 +71,7 @@ struct commentcnvYY_state
{
BufStr * inBuf = 0;
BufStr * outBuf = 0;
- int inBufPos = 0;
+ yy_size_t inBufPos = 0;
int col = 0;
int blockHeadCol = 0;
bool mlBrief = FALSE;
@@ -99,7 +104,9 @@ struct commentcnvYY_state
bool isFixedForm = FALSE; // For Fortran
};
+#if USE_STATE2STRING
static const char *stateToString(int state);
+#endif
static inline int computeIndent(const char *s);
static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len);
@@ -108,7 +115,7 @@ static void startCondSection(yyscan_t yyscanner,const char *sectId);
static void endCondSection(yyscan_t yyscanner);
static void handleCondSectionId(yyscan_t yyscanner,const char *expression);
static void replaceAliases(yyscan_t yyscanner,const char *s);
-static int yyread(yyscan_t yyscanner,char *buf,int max_size);
+static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
static void replaceComment(yyscan_t yyscanner,int offset);
@@ -135,12 +142,44 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
%x CondLine
%x ReadAliasArgs
+ //- start: NUMBER -------------------------------------------------------------------------
+ // Note same defines in code.l: keep in sync
+DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
+HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
+OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
+BINARY_INTEGER "0"[bB][01][01']*[01]?
+INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
+
+FP_SUF [fFlL]
+
+DIGIT_SEQ [0-9][0-9']*[0-9]?
+FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
+FP_EXP [eE][+-]?{DIGIT_SEQ}
+DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
+DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
+
+HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
+HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
+BIN_EXP [pP][+-]?{DIGIT_SEQ}
+HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
+HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
+
+FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
+FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
+FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
+NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
+ //- end: NUMBER ---------------------------------------------------------------------------
+
%%
-<Scan>[^"'!\/\n\\#,\-]* { /* eat anything that is not " / , or \n */
+<Scan>{NUMBER} { //Note similar code in code.l
+ if (yyextra->lang!=SrcLangExt_Cpp) REJECT;
+ copyToOutput(yyscanner,yytext,(int)yyleng);
+ }
+<Scan>[^"'!\/\n\\#,\-=; \t]* { /* eat anything that is not " / , or \n */
copyToOutput(yyscanner,yytext,(int)yyleng);
}
-<Scan>[,] { /* eat , so we have a nice separator in long initialization lines */
+<Scan>[,= ;\t] { /* eat , so we have a nice separator in long initialization lines */
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<Scan>"\"\"\""! { /* start of python long comment */
@@ -284,7 +323,7 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<Scan>"/*"[*!]? { /* start of a C comment */
- if ((yyextra->lang==SrcLangExt_Python) || (yyextra->lang==SrcLangExt_Tcl))
+ if (yyextra->lang==SrcLangExt_Python)
{
REJECT;
}
@@ -309,6 +348,16 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
}
}
+<Scan>"--"[^!][^\n]* {
+ if (yyextra->lang!=SrcLangExt_VHDL)
+ {
+ REJECT;
+ }
+ else
+ {
+ copyToOutput(yyscanner,yytext,(int)yyleng);
+ }
+ }
<Scan>"--!" {
if (yyextra->lang!=SrcLangExt_VHDL)
{
@@ -349,6 +398,17 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
yyextra->blockName=&yytext[1];
BEGIN(VerbatimCode);
}
+<CComment,ReadLine>^[ \t]*("```"[`]*|"~~~"[~]*) { /* start of markdown code block */
+ if (!Config_getBool(MARKDOWN_SUPPORT))
+ {
+ REJECT;
+ }
+ copyToOutput(yyscanner,yytext,(int)yyleng);
+ yyextra->lastCommentContext = YY_START;
+ yyextra->javaBlock=0;
+ yyextra->blockName=QCString(yytext).stripWhiteSpace().left(3);
+ BEGIN(VerbatimCode);
+ }
<CComment,ReadLine>[\\@]("dot"|"code"|"msc"|"startuml")/[^a-z_A-Z0-9] { /* start of a verbatim block */
copyToOutput(yyscanner,yytext,(int)yyleng);
yyextra->lastCommentContext = YY_START;
@@ -427,6 +487,13 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
}
}
}
+<VerbatimCode>("```"[`]*|"~~~"[~]*) { /* end of markdown code block */
+ copyToOutput(yyscanner,yytext,(int)yyleng);
+ if (yytext[0]==yyextra->blockName[0])
+ {
+ BEGIN(yyextra->lastCommentContext);
+ }
+ }
<VerbatimCode>[\\@]("enddot"|"endcode"|"endmsc"|"enduml") { /* end of verbatim block */
copyToOutput(yyscanner,yytext,(int)yyleng);
if (&yytext[4]==yyextra->blockName)
@@ -457,13 +524,13 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
}
}
}
-<Verbatim,VerbatimCode>[^@\/\\\n{}]* { /* any character not a backslash or new line or } */
+<Verbatim,VerbatimCode>[^`~@\/\\\n{}]* { /* any character not a backslash or new line or } */
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<Verbatim,VerbatimCode>\n { /* new line in verbatim block */
copyToOutput(yyscanner,yytext,(int)yyleng);
}
-<Verbatim>^[ \t]*"///" {
+<Verbatim>^[ \t]*"//"[/!] {
if (yyextra->blockName=="dot" || yyextra->blockName=="msc" || yyextra->blockName=="uml" || yyextra->blockName.at(0)=='f')
{
// see bug 487871, strip /// from dot images and formulas.
@@ -484,7 +551,7 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<SkipString>\\. { /* escaped character in string */
- if (yyextra->lang==SrcLangExt_Fortran)
+ if (yyextra->lang==SrcLangExt_Fortran || yyextra->lang==SrcLangExt_VHDL)
{
unput(yytext[1]);
copyToOutput(yyscanner,yytext,1);
@@ -505,7 +572,7 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<SkipChar>\\. { /* escaped character */
- if (yyextra->lang==SrcLangExt_Fortran)
+ if (yyextra->lang==SrcLangExt_Fortran || yyextra->lang==SrcLangExt_VHDL)
{
unput(yytext[1]);
copyToOutput(yyscanner,yytext,1);
@@ -526,7 +593,7 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
copyToOutput(yyscanner,yytext,(int)yyleng);
}
-<CComment>[^ <\\!@*\n{\"\/]* { /* anything that is not a '*' or command */
+<CComment>[^ `~<\\!@*\n{\"\/]* { /* anything that is not a '*' or command */
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<CComment>"*"+[^*/\\@\n{\"]* { /* stars without slashes */
@@ -546,7 +613,7 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
}
}
<CComment>\n { /* new line in comment */
- copyToOutput(yyscanner,yytext,(int)yyleng);
+ copyToOutput(yyscanner,yytext,(int)yyleng);
/* in case of Fortran always end of comment */
if (yyextra->lang==SrcLangExt_Fortran)
{
@@ -554,16 +621,18 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
}
}
<CComment>"/"+"*" { /* nested C comment */
- if ((yyextra->lang==SrcLangExt_Python) || (yyextra->lang==SrcLangExt_Tcl))
+ if (yyextra->lang==SrcLangExt_Python ||
+ yyextra->lang==SrcLangExt_Markdown)
{
REJECT;
}
yyextra->nestingCount++;
yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
- copyToOutput(yyscanner,yytext,(int)yyleng);
+ copyToOutput(yyscanner,yytext,(int)yyleng);
}
<CComment>"*"+"/" { /* end of C comment */
- if ((yyextra->lang==SrcLangExt_Python) || (yyextra->lang==SrcLangExt_Tcl))
+ if (yyextra->lang==SrcLangExt_Python ||
+ yyextra->lang==SrcLangExt_Markdown)
{
REJECT;
}
@@ -843,6 +912,9 @@ MAILADR ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
copyToOutput(yyscanner,yytext,(int)yyleng);
}
+<*>. {
+ copyToOutput(yyscanner,yytext,(int)yyleng);
+ }
%%
static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
@@ -1011,11 +1083,11 @@ static void replaceAliases(yyscan_t yyscanner,const char *s)
}
-static int yyread(yyscan_t yyscanner,char *buf,int max_size)
+static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
- int bytesInBuf = yyextra->inBuf->curPos()-yyextra->inBufPos;
- int bytesToCopy = QMIN(max_size,bytesInBuf);
+ yy_size_t bytesInBuf = yyextra->inBuf->curPos()-yyextra->inBufPos;
+ yy_size_t bytesToCopy = QMIN(max_size,bytesInBuf);
memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
yyextra->inBufPos+=bytesToCopy;
return bytesToCopy;
@@ -1039,52 +1111,13 @@ static void replaceComment(yyscan_t yyscanner,int offset)
else
{
copyToOutput(yyscanner," */",3);
- int i;for (i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
+ for (i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
yyextra->inSpecialComment=FALSE;
BEGIN(Scan);
}
}
}
-// simplified way to know if this is fixed form
-// duplicate in fortrancode.l
-static bool recognizeFixedForm(const char* contents)
-{
- int column=0;
- bool skipLine=FALSE;
-
- for(int i=0;;i++) {
- column++;
-
- switch(contents[i]) {
- case '\n':
- column=0;
- skipLine=FALSE;
- break;
- case ' ':
- break;
- case '\000':
- return FALSE;
- case 'C':
- case 'c':
- case '*':
- if(column==1) return TRUE;
- if(skipLine) break;
- return FALSE;
- case '!':
- if(column>1 && column<7) return FALSE;
- skipLine=TRUE;
- break;
- default:
- if(skipLine) break;
- if(column==7) return TRUE;
- return FALSE;
- }
- }
- return FALSE;
-}
-
-
/*! This function does three things:
* -# It converts multi-line C++ style comment blocks (that are aligned)
* to C style comment blocks (if MULTILINE_CPP_IS_BRIEF is set to NO).
@@ -1121,7 +1154,8 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
yyextra->isFixedForm = FALSE;
if (yyextra->lang==SrcLangExt_Fortran)
{
- yyextra->isFixedForm = recognizeFixedForm(inBuf->data());
+ FortranFormat fmt = convertFileNameFortranParserCode(fileName);
+ yyextra->isFixedForm = recognizeFixedForm(inBuf->data(),fmt);
}
if (yyextra->lang==SrcLangExt_Markdown)
@@ -1143,7 +1177,7 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
warn(yyextra->fileName,ctx->lineNr,"Conditional section%sdoes not have "
"a corresponding \\endcond command within this file.",sectionInfo.data());
}
- if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt_Markdown)
+ if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt_Markdown && yyextra->lang!=SrcLangExt_Fortran)
{
QCString tmp= "(probable line reference: ";
bool first = TRUE;
@@ -1175,4 +1209,6 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
//----------------------------------------------------------------------------
+#if USE_STATE2STRING
#include "commentcnv.l.h"
+#endif