/***************************************************************************** * * * * 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] Bopt {B}* 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}"'")) /* no comment start / end signs inside square brackets */ NCOMM [^/\*] // C start comment CCS "/\*" // C end comment CCE "*\/" // Cpp comment CPPC "/\/" // doxygen start comment DCOMM ("/\*!"|"/\**"|"/\/!"|"/\/\/") // Optional any character ANYopt .* // Optional all but newline NONLopt [^\n]* %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); } {CPPC}.*{nl} { yyextra->cCodeBuffer += yytext; } ^{ws}*{CCS} { yyextra->cCodeBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(COMMENT); } {CCE}{ws}*{nl} { yyextra->cCodeBuffer+=yytext; BEGIN(yyextra->lastContext); } {CCE} { yyextra->cCodeBuffer+=yytext; BEGIN(yyextra->lastContext); } [^*\n]+ { yyextra->cCodeBuffer += yytext; } {CPPC}|{CCS} { 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); } {CCS} { 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}*{DCOMM}"