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 1174 of file lexcode.l.

1174 : p(std::make_unique<Private>())
1175{
1176 lexcodeYYlex_init_extra(&p->state, &p->yyscanner);
1177#ifdef FLEX_DEBUG
1178 lexcodeYYset_debug(Debug::isFlagSet(Debug::Lex_lexcode)?1:0,p->yyscanner);
1179#endif
1181}
@ 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:1188

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

◆ ~LexCodeParser()

LexCodeParser::~LexCodeParser ( )
override

Definition at line 1183 of file lexcode.l.

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

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 1195 of file lexcode.l.

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

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 1188 of file lexcode.l.

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

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: