Doxygen
Loading...
Searching...
No Matches
LexCodeParser Class Reference

LEX code scanner. More...

#include <src/lexcode.h>

Inheritance diagram for LexCodeParser:
Collaboration diagram for LexCodeParser:

Classes

struct  Private

Public Member Functions

 LexCodeParser ()
 ~LexCodeParser () override
void parseCode (OutputCodeList &codeOutIntf, const QCString &scopeName, const QCString &input, SrcLangExt, bool stripCodeComments, bool isExampleBlock, const QCString &exampleName=QCString(), const FileDef *fileDef=nullptr, int startLine=-1, int endLine=-1, bool inlineFragment=FALSE, const MemberDef *memberDef=nullptr, bool showLineNumbers=TRUE, const Definition *searchCtx=nullptr, bool collectXRefs=TRUE) override
 Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
void resetCodeParserState () override
 Resets the state of the code parser.

Private Attributes

std::unique_ptr< Privatep

Detailed Description

LEX code scanner.

Definition at line 29 of file lexcode.h.

Constructor & Destructor Documentation

◆ LexCodeParser()

LexCodeParser::LexCodeParser ( )

Definition at line 1175 of file lexcode.l.

1175 : p(std::make_unique<Private>())
1176{
1177 lexcodeYYlex_init_extra(&p->state, &p->yyscanner);
1178#ifdef FLEX_DEBUG
1179 lexcodeYYset_debug(Debug::isFlagSet(Debug::Lex_lexcode)?1:0,p->yyscanner);
1180#endif
1182}
@ Lex_lexcode
Definition debug.h:62
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
std::unique_ptr< Private > p
Definition lexcode.h:55
void resetCodeParserState() override
Resets the state of the code parser.
Definition lexcode.l:1189

References Debug::isFlagSet(), Debug::Lex_lexcode, p, and resetCodeParserState().

◆ ~LexCodeParser()

LexCodeParser::~LexCodeParser ( )
override

Definition at line 1184 of file lexcode.l.

1185{
1186 lexcodeYYlex_destroy(p->yyscanner);
1187}

References p.

Member Function Documentation

◆ parseCode()

void LexCodeParser::parseCode ( OutputCodeList & codeOutList,
const QCString & scopeName,
const QCString & input,
SrcLangExt lang,
bool stripCodeComments,
bool isExampleBlock,
const QCString & exampleName = QCString(),
const FileDef * fileDef = nullptr,
int startLine = -1,
int endLine = -1,
bool inlineFragment = FALSE,
const MemberDef * memberDef = nullptr,
bool showLineNumbers = TRUE,
const Definition * searchCtx = nullptr,
bool collectXRefs = TRUE )
overridevirtual

Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.

Parameters
[in]codeOutListinterface for writing the result.
[in]scopeNameName of scope to which the code belongs.
[in]inputActual code in the form of a string
[in]langThe programming language of the code fragment.
[in]stripCodeCommentssignals whether or not for the code block the doxygen comments should be stripped.
[in]isExampleBlockTRUE iff the code is part of an example.
[in]exampleNameName of the example.
[in]fileDefFile definition to which the code is associated.
[in]startLineStarting line in case of a code fragment.
[in]endLineEnding line of the code fragment.
[in]inlineFragmentCode fragment that is to be shown inline as part of the documentation.
[in]memberDefMember definition to which the code is associated (non null in case of an inline fragment for a member).
[in]showLineNumbersif set to TRUE and also fileDef is not 0, line numbers will be added to the source fragment
[in]searchCtxcontext under which search data has to be stored.
[in]collectXRefscollect cross-reference relations.

Implements CodeParserInterface.

Definition at line 1196 of file lexcode.l.

1212{
1213 yyscan_t yyscanner = p->yyscanner;
1214 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1215
1216 if (input.isEmpty()) return;
1217
1218 DebugLex debugLex(Debug::Lex_lexcode, __FILE__, fileDef ? qPrint(fileDef->fileName()) : nullptr);
1219
1220 yyextra->code = &codeOutIntf;
1221 yyextra->inputString = input.data();
1222 yyextra->inputPosition = 0;
1223 yyextra->fileName = fileDef ? fileDef->fileName():"";
1224 yyextra->currentFontClass = nullptr;
1225 yyextra->insideCodeLine = false;
1226
1227 yyextra->classScope=scopeName;
1228 yyextra->currentMemberDef=memberDef;
1229 yyextra->searchCtx=searchCtx;
1230 yyextra->collectXRefs=collectXRefs;
1231
1232 if (startLine!=-1)
1233 yyextra->yyLineNr = startLine;
1234 else
1235 yyextra->yyLineNr = 1;
1236
1237 if (endLine!=-1)
1238 yyextra->inputLines = endLine+1;
1239 else
1240 yyextra->inputLines = yyextra->yyLineNr + countLines(yyscanner) - 1;
1241
1242 yyextra->startCCodeLine = yyextra->yyLineNr;
1243 yyextra->stripCodeComments = stripCodeComments;
1244 yyextra->exampleBlock = isExampleBlock;
1245 yyextra->exampleName = exampleName;
1246 yyextra->sourceFileDef = fileDef;
1247 yyextra->lineNumbers = fileDef!=0 && showLineNumbers;
1248
1249 if (isExampleBlock && fileDef==0)
1250 {
1251 // create a dummy filedef for the example
1252 yyextra->exampleFileDef = createFileDef(QCString(),!exampleName.isEmpty() ? exampleName : QCString("generated"));
1253 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1254 }
1255
1256 if (yyextra->sourceFileDef)
1257 {
1258 setCurrentDoc(yyscanner,"l00001");
1259 }
1260
1261 yyextra->includeCodeFragment = inlineFragment;
1262 // Starts line 1 on the output
1263 startCodeLine(yyscanner);
1264
1265 lexcodeYYrestart( nullptr, yyscanner );
1266 BEGIN( DefSection );
1267 lexcodeYYlex(yyscanner);
1268
1269 if (yyextra->insideCodeLine)
1270 {
1271 endCodeLine(yyscanner);
1272 }
1273 if (yyextra->exampleFileDef)
1274 {
1275 // delete the temporary file definition used for this example
1276 yyextra->exampleFileDef.reset();
1277 yyextra->sourceFileDef=0;
1278 }
1279}
virtual QCString fileName() const =0
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
static void endCodeLine(yyscan_t yyscanner)
Definition code.l:2490
static void startCodeLine(yyscan_t yyscanner)
Definition code.l:2421
static int countLines(yyscan_t yyscanner)
Definition code.l:3483
yyguts_t * yyscan_t
Definition code.l:24
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition code.l:2283
std::unique_ptr< FileDef > createFileDef(const QCString &p, const QCString &n, const QCString &ref, const QCString &dn)
Definition filedef.cpp:268
const char * qPrint(const char *s)
Definition qcstring.h:672

References countLines(), createFileDef(), QCString::data(), endCodeLine(), FileDef::fileName(), QCString::isEmpty(), Debug::Lex_lexcode, p, qPrint(), setCurrentDoc(), and startCodeLine().

◆ resetCodeParserState()

void LexCodeParser::resetCodeParserState ( )
overridevirtual

Resets the state of the code parser.

Since multiple code fragments can together form a single example, an explicit function is used to reset the code parser state.

See also
parseCode()

Implements CodeParserInterface.

Definition at line 1189 of file lexcode.l.

1190{
1191 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
1192 yyextra->currentDefinition = nullptr;
1193 yyextra->currentMemberDef = nullptr;
1194}

References p.

Referenced by LexCodeParser().

Member Data Documentation

◆ p

std::unique_ptr<Private> LexCodeParser::p
private

Definition at line 55 of file lexcode.h.

Referenced by LexCodeParser(), parseCode(), resetCodeParserState(), and ~LexCodeParser().


The documentation for this class was generated from the following files: