/***************************************************************************** * * * * Copyright (C) 1997-2021 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. * */ %option never-interactive %option prefix="lexscannerYY" %option reentrant %option extra-type="struct lexscannerYY_state *" %option noyywrap %top{ #include } %{ /* * includes */ #include #include #include #include #include #include #include #include "config.h" #include "lexscanner.h" #include "entry.h" #include "message.h" #include "util.h" #include "scanner.h" #define YY_NO_INPUT 1 #define YY_NO_UNISTD_H 1 #define USE_STATE2STRING 0 #define repeatChar(chr, cnt) std::string(cnt, chr).c_str() struct lexscannerYY_state { COutlineParser cOutlineParser; const char * inputString = 0; int inputPosition = 0; int lastContext = 0; int lastCContext = 0; int lastStringContext = 0; int docBlockContext = 0; int lastPreLineCtrlContext = 0; int lastRawStringContext = 0; int curlyCount = 0; bool insideCode = FALSE; QCString delimiter; QCString docBlockName; uint fencedSize = 0; bool nestedComment = false; QCString prefix = "yy"; QCString CCodeBuffer; int roundCount = 0; int squareCount = 0; QCString yyFileName; ClangTUParser *clangParser = 0; std::shared_ptr current; std::shared_ptr current_root; SrcLangExt language; }; #if USE_STATE2STRING static const char *stateToString(int state); #endif //----------------------------------------------------------------------------- // forward declarations for statefull functions static void handleCCode(yyscan_t yyscanner); static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size); /* ----------------------------------------------------------------- */ #undef YY_INPUT #define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size); %} nl (\r\n|\r|\n) ws [ \t] nws [^ \t\n] TopStart "%top{"{nl} TopEnd "}"{nl} LiteralStart "%{"{nl} LiteralEnd "%}"{nl} OptPrefix "%option"{ws}+"prefix"{ws}*"="{ws}* RulesStart "%%"{nl} RulesEnd "%%"{nl} RulesSharp "<"[^>]*">" RulesCurly "{"[^{}\n]*"}" StartSquare "[" StartDouble "\"" StartRound "(" EscapeRulesCharOpen "\\["|"\\<"|"\\{"|"\\("|"\\\""|"\\{"|"\\ " EscapeRulesCharClose "\\]"|"\\>"|"\\}"|"\\)" EscapeRulesChar {EscapeRulesCharOpen}|{EscapeRulesCharClose} CMD ("\\"|"@") BN [ \t\n\r] BL [ \t\r]*"\n" B [ \t] ID "$"?[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]* PRE [pP][rR][eE] CODE [cC][oO][dD][eE] RAWBEGIN (u|U|L|u8)?R\"[^ \t\(\)\\]{0,16}"(" RAWEND ")"[^ \t\(\)\\]{0,16}\" CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) %x DefSection %x OptPrefix %x DefSectionLine %x RulesSectionInit %x RulesPattern %x RulesDouble %x RulesRoundDouble %x RulesSquare %x RulesRoundSquare %x RulesRound %x UserSection %x TopSection %x LiteralSection %x COMMENT %x SkipCurly %x SkipCurlyEndDoc %x PreLineCtrl %x DocLine %x DocBlock %x DocCopyBlock %x SkipString %x RawString %x SkipComment %x SkipCxxComment %x Comment %% <*>\x0d {OptPrefix} { BEGIN (OptPrefix); } "\""[^\"]*"\"" { yyextra->prefix = yytext; yyextra->prefix = yyextra->prefix.mid(1,yyleng-2); } {nl} { yyextra->CCodeBuffer += yytext; BEGIN (DefSection); } ^{RulesStart} { yyextra->CCodeBuffer += "int " + yyextra->prefix + "lex (yyscan_t yyscanner) {\n"; BEGIN (RulesSectionInit); } ^{TopStart} { yyextra->CCodeBuffer += "\n"; yyextra->lastContext = YY_START; BEGIN (TopSection); } ^{LiteralStart} { yyextra->CCodeBuffer += "\n"; yyextra->lastContext = YY_START; BEGIN (LiteralSection); } ^{TopEnd} { yyextra->CCodeBuffer += "\n"; BEGIN( yyextra->lastContext ) ; } .*{nl} { yyextra->CCodeBuffer += yytext; } ^{LiteralEnd} { yyextra->CCodeBuffer += "\n"; BEGIN( yyextra->lastContext ) ; } .*{nl} { yyextra->CCodeBuffer += yytext; } ^{nws} { BEGIN(DefSectionLine); } "//".*{nl} { yyextra->CCodeBuffer += yytext; } ^{ws}*"/*" { yyextra->CCodeBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(COMMENT); } "*/"{ws}*{nl} { yyextra->CCodeBuffer+=yytext; BEGIN(yyextra->lastContext); } "*/" { yyextra->CCodeBuffer+=yytext; BEGIN(yyextra->lastContext); } [^*\n]+ { yyextra->CCodeBuffer += yytext; } "//"|"/*" { yyextra->CCodeBuffer += yytext; } {nl} { yyextra->CCodeBuffer += yytext; } . { yyextra->CCodeBuffer += yytext; } ^{nl} { yyextra->CCodeBuffer += "\n"; } ^{ws}.*{nl} { yyextra->CCodeBuffer += yytext; } .*{nl} { yyextra->CCodeBuffer += "\n"; BEGIN(DefSection); } ^{RulesEnd} { yyextra->CCodeBuffer += "}\n"; BEGIN (UserSection); } ^{nws} { unput(*yytext); BEGIN(RulesPattern); } ^{ws}.*{nl} { yyextra->CCodeBuffer += yytext; } ^{nl} { yyextra->CCodeBuffer += yytext; } "<>" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {EscapeRulesChar} { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {RulesSharp} { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {RulesCurly} { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {StartDouble} { yyextra->CCodeBuffer += repeatChar(' ', yyleng); yyextra->lastContext = YY_START; BEGIN(RulesDouble); } "\\\\" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } "\\\"" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } "\"" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); BEGIN( yyextra->lastContext ) ; } "\"" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); BEGIN(RulesRound) ; } . { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {StartSquare} { yyextra->squareCount++; yyextra->CCodeBuffer += repeatChar(' ', yyleng); yyextra->lastContext = YY_START; BEGIN(RulesSquare); } "\\[" | "\\]" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } "[" { yyextra->squareCount++; yyextra->CCodeBuffer += repeatChar(' ', yyleng); } "]" { yyextra->squareCount--; yyextra->CCodeBuffer += repeatChar(' ', yyleng); if (!yyextra->squareCount) BEGIN(RulesPattern); } "]" { yyextra->squareCount--; yyextra->CCodeBuffer += repeatChar(' ', yyleng); if (!yyextra->squareCount) BEGIN(RulesRound) ; } "\\\\" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } . { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {StartRound} { yyextra->roundCount++; yyextra->CCodeBuffer += repeatChar(' ', yyleng); yyextra->lastContext = YY_START; BEGIN(RulesRound); } {RulesCurly} { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {StartSquare} { yyextra->squareCount++; yyextra->CCodeBuffer += repeatChar(' ', yyleng); BEGIN(RulesRoundSquare); } {StartDouble} { yyextra->CCodeBuffer += repeatChar(' ', yyleng); BEGIN(RulesRoundDouble); } "\\(" | "\\)" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } "(" { yyextra->roundCount++; yyextra->CCodeBuffer += repeatChar(' ', yyleng); } ")" { yyextra->roundCount--; yyextra->CCodeBuffer += repeatChar(' ', yyleng); if (!yyextra->roundCount) BEGIN( yyextra->lastContext ) ; } . { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {ws}+"|" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); yyextra->curlyCount = 0; BEGIN(SkipCurly); } ^{ws}*{nl} { yyextra->CCodeBuffer += "\n"; } ^{ws}+ { } ({ws}|{nl}) { unput(*yytext); yyextra->curlyCount = 0; BEGIN(SkipCurly); } "\\\\" { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } "/*" { yyextra->CCodeBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(COMMENT); } . { yyextra->CCodeBuffer += repeatChar(' ', yyleng); } {B}*"#"{B}+[0-9]+{B}+/"\"" { /* line control directive */ yyextra->CCodeBuffer += yytext; yyextra->lastPreLineCtrlContext = YY_START; BEGIN( PreLineCtrl ); } "\""[^\n\"]*"\"" { yyextra->CCodeBuffer += yytext; } . { yyextra->CCodeBuffer += yytext; } \n { yyextra->CCodeBuffer += yytext; BEGIN( yyextra->lastPreLineCtrlContext ); } "{" { yyextra->CCodeBuffer += yytext; ++yyextra->curlyCount ; } "}"/{BN}*("/*!"|"/**"|"//!"|"///")"