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.
 
- Public Member Functions inherited from CodeParserInterface

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

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

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

◆ ~LexCodeParser()

LexCodeParser::~LexCodeParser ( )
override

Definition at line 1185 of file lexcode.l.

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

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

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

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

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

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: