/***************************************************************************** * * * * Copyright (C) 1997-2002 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * * Documents produced by Doxygen are derivative works derived from the * input used in their production; they are not affected by this license. * */ %{ #define YY_NEVER_INTERACTIVE 1 #include #include #include "bufstr.h" #include "debug.h" #include "message.h" static BufStr *g_inBuf; static BufStr *g_outBuf; static int g_inBufPos; static void replaceCommentMarker(const char *s,int len) { const char *p=s; char c; // copy blanks while ((c=*p) && (c==' ' || c=='\t' || c=='\n')) { g_outBuf->addChar(c); p++; } // replace start of comment marker by spaces while ((c=*p) && (c=='/' || c=='!')) { g_outBuf->addChar(' '); p++; if (*p=='<') // comment-after-item marker { g_outBuf->addChar(' '); p++; } if (c=='!') // end after first ! { break; } } // copy comment line to output g_outBuf->addArray(p,len-(p-s)); } static inline void copyToOutput(const char *s,int len) { g_outBuf->addArray(s,len); } #undef YY_INPUT #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size); static int yyread(char *buf,int max_size) { int bytesInBuf = g_inBuf->curPos()-g_inBufPos; int bytesToCopy = QMIN(max_size,bytesInBuf); memcpy(buf,g_inBuf->data()+g_inBufPos,bytesToCopy); g_inBufPos+=bytesToCopy; return bytesToCopy; } %} %option noyywrap %option nounput %x Scan %x SkipString %x SComment %x CComment %x Verbatim %% [^\"\/\n\\]* { /* eat anything that is not " / or \n */ copyToOutput(yytext,yyleng); } "\"" { /* start of a string */ copyToOutput(yytext,yyleng); BEGIN(SkipString); } \n { /* new line */ copyToOutput(yytext,yyleng); } ("//!"|"///").*\n/[ \t]*"//"[\/!][^\/] { /* start C++ style special comment block */ int i=3; if (yytext[2]=='/') { while (i"//"[\/!].*\n { /* one line C++ comment */ copyToOutput(yytext,yyleng); } "/*" { /* start of a C comment */ copyToOutput(yytext,yyleng); BEGIN(CComment); } "\\verbatim" { /* start of a verbatim block */ copyToOutput(yytext,yyleng); BEGIN(Verbatim); } . { /* any other character */ copyToOutput(yytext,yyleng); } "\\endverbatim" { /* end of verbatim block */ copyToOutput(yytext,yyleng); BEGIN(Scan); } [^\\\n]* { /* any character not a backslash or new line */ copyToOutput(yytext,yyleng); } \n { /* new line in verbatim block */ copyToOutput(yytext,yyleng); } . { /* any other character */ copyToOutput(yytext,yyleng); } \\. { /* escaped character in string */ copyToOutput(yytext,yyleng); } "\"" { /* end of string */ copyToOutput(yytext,yyleng); BEGIN(Scan); } . { /* any other string character */ copyToOutput(yytext,yyleng); } \n { /* new line inside string (illegal for some compilers) */ copyToOutput(yytext,yyleng); } [^*\n]* { /* anything that is not a '*' */ copyToOutput(yytext,yyleng); } "*"+[^*/\n]* { /* stars without slashes */ copyToOutput(yytext,yyleng); } \n { /* new line in comment */ copyToOutput(yytext,yyleng); } "*"+"/" { /* end of C comment */ copyToOutput(yytext,yyleng); BEGIN(Scan); } ^[ \t]*"///"[\/]*/\n { replaceCommentMarker(yytext,yyleng); } \n[ \t]*"///"[\/]*/\n { replaceCommentMarker(yytext,yyleng); } ^[ \t]*"///"[^\/\n].*/\n { replaceCommentMarker(yytext,yyleng); } \n[ \t]*"///"[^\/\n].*/\n { replaceCommentMarker(yytext,yyleng); } ^[ \t]*"//!".*/\n { replaceCommentMarker(yytext,yyleng); } \n[ \t]*"//!".*/\n { replaceCommentMarker(yytext,yyleng); } \n { /* end of special comment */ copyToOutput(" */",3); copyToOutput(yytext,yyleng); BEGIN(Scan); } %% void convertCppComments(BufStr *inBuf,BufStr *outBuf) { g_inBuf = inBuf; g_outBuf = outBuf; g_inBufPos = 0; BEGIN(Scan); yylex(); if (Debug::isFlagSet(Debug::CommentCnv)) { msg("-------------\n%s\n-------------\n",g_outBuf->data()); } } //---------------------------------------------------------------------------- extern "C" { // some bogus code to keep the compiler happy void commentcnvYYdummy() { yy_flex_realloc(0,0); } }