/****************************************************************************** * * 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="lexcodeYY" %option noyywrap %option reentrant %option extra-type="struct lexcodeYY_state *" %top{ #include } %{ #include #include "config.h" #include "doxygen.h" #include "outputgen.h" #include "code.h" #include "lexcode.h" #include "filedef.h" #include "message.h" #define YY_NEVER_INTERACTIVE 1 #define YY_NO_INPUT 1 #define YY_NO_UNISTD_H 1 #define USE_STATE2STRING 0 struct lexcodeYY_state { CodeOutputInterface * code; CCodeParser ccodeParser; const char *inputString; //!< the code fragment as text yy_size_t inputPosition; //!< read offset during parsing int inputLines; //!< number of line in the code fragment int yyLineNr; //!< current line number bool needsTermination; bool lineNumbers = FALSE; const Definition *searchCtx; bool collectXRefs = FALSE; int lastContext = 0; int lastCContext = 0; int lastStringContext = 0; int docBlockContext = 0; int lastPreLineCtrlContext = 0; int lastRawStringContext = 0; int curlyCount = 0; QCString rulesPatternBuffer; QCString CCodeBuffer; int startCCodeLine = -1; int roundCount = 0; bool insideCode = FALSE; QCString delimiter; QCString docBlockName; uint fencedSize = 0; bool nestedComment = false; bool exampleBlock; QCString exampleName; QCString classScope; FileDef *sourceFileDef; const Definition *currentDefinition; const MemberDef *currentMemberDef; bool includeCodeFragment; const char *currentFontClass; }; #if USE_STATE2STRING static const char *stateToString(int state); #endif static void setCurrentDoc(yyscan_t yyscanner,const QCString &anchor); static void startCodeLine(yyscan_t yyscanner); static void endFontClass(yyscan_t yyscanner); static void endCodeLine(yyscan_t yyscanner); static void nextCodeLine(yyscan_t yyscanner); static void codifyLines(yyscan_t yyscanner,const QCString &text); static void startFontClass(yyscan_t yyscanner,const char *s); static int countLines(yyscan_t yyscanner); static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size); static void lineCount(yyscan_t yyscanner); static void handleCCode(yyscan_t yyscanner); #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} RulesStart "%%"{nl} RulesEnd "%%"{nl} RulesSharp "<"[^>\n]*">" RulesCurly "{"[^{}\n]*"}" StartSquare "[" StartDouble "\"" StartRound "(" StartRoundQuest "(?" 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}"'")) CHARCE "[:"[^:]*":]" /* 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 DefSectionLine %x RulesSectionInit %x RulesPattern %x RulesDouble %x RulesRoundDouble %x RulesSquare %x RulesRoundSquare %x RulesRound %x RulesRoundQuest %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 ^{TopStart} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); yyextra->lastContext = YY_START; yyextra->startCCodeLine=yyextra->yyLineNr; BEGIN (TopSection); } ^{LiteralStart} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); yyextra->lastContext = YY_START; yyextra->startCCodeLine=yyextra->yyLineNr; BEGIN (LiteralSection); } ^{TopEnd} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); BEGIN( yyextra->lastContext ) ; } .*{nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } ^{LiteralEnd} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); BEGIN( yyextra->lastContext ) ; } .*{nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } {CPPC}.*{nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } ^{ws}*{CCS} { yyextra->CCodeBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(COMMENT); } {CCE}{ws}*{nl} { yyextra->CCodeBuffer+=yytext; yyextra->yyLineNr++; handleCCode(yyscanner); BEGIN(yyextra->lastContext); } {CCE} { yyextra->CCodeBuffer+=yytext; handleCCode(yyscanner); BEGIN(yyextra->lastContext); } [^*\n]+ { yyextra->CCodeBuffer += yytext; } {CPPC}|{CCS} { yyextra->CCodeBuffer += yytext; } {nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } . { yyextra->CCodeBuffer += yytext; } ^{nl} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); yyextra->startCCodeLine=yyextra->yyLineNr; } ^{ws}.*{nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } ^{RulesStart} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); yyextra->startCCodeLine=yyextra->yyLineNr; BEGIN (RulesSectionInit); } ^{nws} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); BEGIN(DefSectionLine); } .*{nl} { codifyLines(yyscanner,yytext); yyextra->startCCodeLine=yyextra->yyLineNr; BEGIN(DefSection); } ^{RulesEnd} { handleCCode(yyscanner); codifyLines(yyscanner,yytext); yyextra->startCCodeLine=yyextra->yyLineNr; BEGIN (UserSection); } ^{nws} { handleCCode(yyscanner); unput(*yytext); BEGIN(RulesPattern); } {nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } ^{ws}.*{nl} { yyextra->CCodeBuffer += yytext; yyextra->yyLineNr++; } "<>" { yyextra->rulesPatternBuffer += yytext; } {EscapeRulesChar} { yyextra->rulesPatternBuffer += yytext; } {RulesSharp} { yyextra->rulesPatternBuffer += yytext; } {RulesCurly} { yyextra->rulesPatternBuffer += yytext; } {StartDouble} { yyextra->rulesPatternBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(RulesDouble); } "\\\\" { yyextra->rulesPatternBuffer += yytext; } "\\\"" { yyextra->rulesPatternBuffer += yytext; } "\"" { yyextra->rulesPatternBuffer += yytext; BEGIN( yyextra->lastContext ) ; } "\"" { yyextra->rulesPatternBuffer += yytext; BEGIN(RulesRound) ; } . { yyextra->rulesPatternBuffer += yytext; } {StartSquare} { yyextra->rulesPatternBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(RulesSquare); } {CHARCE} { yyextra->rulesPatternBuffer += yytext; } "\\[" | "\\]" { yyextra->rulesPatternBuffer += yytext; } "]" { yyextra->rulesPatternBuffer += yytext; BEGIN(RulesPattern) ; } "]" { yyextra->rulesPatternBuffer += yytext; BEGIN(RulesRound) ; } "\\\\" { yyextra->rulesPatternBuffer += yytext; } . { yyextra->rulesPatternBuffer += yytext; } {StartRoundQuest} { yyextra->rulesPatternBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(RulesRoundQuest); } {nl} { yyextra->rulesPatternBuffer += yytext; if (!yyextra->rulesPatternBuffer.isEmpty()) { startFontClass(yyscanner,"stringliteral"); codifyLines(yyscanner,yyextra->rulesPatternBuffer.data()); yyextra->rulesPatternBuffer.resize(0); endFontClass(yyscanner); } } [^)] { yyextra->rulesPatternBuffer += yytext; } ")" { yyextra->rulesPatternBuffer += yytext; BEGIN(yyextra->lastContext); } {StartRound} { yyextra->roundCount++; yyextra->rulesPatternBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(RulesRound); } {RulesCurly} { yyextra->rulesPatternBuffer += yytext; } {StartSquare} { yyextra->rulesPatternBuffer += yytext; BEGIN(RulesRoundSquare); } {StartDouble} { yyextra->rulesPatternBuffer += yytext; BEGIN(RulesRoundDouble); } {EscapeRulesChar} { yyextra->rulesPatternBuffer += yytext; } "(" { yyextra->roundCount++; yyextra->rulesPatternBuffer += yytext; } ")" { yyextra->roundCount--; yyextra->rulesPatternBuffer += yytext; if (!yyextra->roundCount) BEGIN( yyextra->lastContext ) ; } {nl} { yyextra->rulesPatternBuffer += yytext; yyextra->yyLineNr++; } {ws} { yyextra->rulesPatternBuffer += yytext; } . { yyextra->rulesPatternBuffer += yytext; } {ws}+"|" { if (!yyextra->rulesPatternBuffer.isEmpty()) { startFontClass(yyscanner,"stringliteral"); codifyLines(yyscanner,yyextra->rulesPatternBuffer); yyextra->rulesPatternBuffer.resize(0); endFontClass(yyscanner); } codifyLines(yyscanner,yytext); yyextra->startCCodeLine=yyextra->yyLineNr; yyextra->curlyCount = 0; BEGIN(SkipCurly); } ^{ws}*{nl} { codifyLines(yyscanner,"\n"); } ^{ws}+ { codifyLines(yyscanner,yytext); } ({ws}|{nl}) { unput(*yytext); if (!yyextra->rulesPatternBuffer.isEmpty()) { startFontClass(yyscanner,"stringliteral"); codifyLines(yyscanner,yyextra->rulesPatternBuffer); yyextra->rulesPatternBuffer.resize(0); endFontClass(yyscanner); } yyextra->startCCodeLine=yyextra->yyLineNr; yyextra->curlyCount = 0; BEGIN(SkipCurly); } "\\\\" { yyextra->rulesPatternBuffer += yytext; } {CCS} { if (!yyextra->rulesPatternBuffer.isEmpty()) { startFontClass(yyscanner,"stringliteral"); codifyLines(yyscanner,yyextra->rulesPatternBuffer); yyextra->rulesPatternBuffer.resize(0); endFontClass(yyscanner); } yyextra->CCodeBuffer += yytext; yyextra->lastContext = YY_START; BEGIN(COMMENT); } . { yyextra->rulesPatternBuffer += yytext; } {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; yyextra->yyLineNr++; BEGIN( yyextra->lastPreLineCtrlContext ); } "{" { yyextra->CCodeBuffer += yytext; ++yyextra->curlyCount ; } "}"/{BN}*{DCOMM}"