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

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 DString &scopeName, const DString &input, SrcLangExt, bool stripCodeComments, const CodeParserOptions &options) 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 24 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:64
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
std::unique_ptr< Private > p
Definition lexcode.h:41
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 DString & scopeName,
const DString & input,
SrcLangExt lang,
bool stripCodeComments,
const CodeParserOptions & options )
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]optionsAdditional options to configure the parser.

Implements CodeParserInterface.

Definition at line 1195 of file lexcode.l.

1202{
1203 yyscan_t yyscanner = p->yyscanner;
1204 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1205
1206 if (input.empty()) return;
1207
1208 DebugLex debugLex(Debug::Lex_lexcode, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()) : nullptr);
1209
1210 yyextra->code = &codeOutIntf;
1211 yyextra->inputString = input.data();
1212 yyextra->inputPosition = 0;
1213 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
1214 yyextra->currentFontClass = nullptr;
1215 yyextra->insideCodeLine = false;
1216 yyextra->classScope = scopeName;
1217 yyextra->currentMemberDef = options.memberDef();
1218 yyextra->searchCtx = options.searchCtx();
1219 yyextra->collectXRefs = options.collectXRefs();
1220 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
1221 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
1222 yyextra->startCCodeLine = yyextra->yyLineNr;
1223 yyextra->stripCodeComments = stripCodeComments;
1224 yyextra->exampleBlock = options.isExample();
1225 yyextra->exampleName = options.exampleName();
1226 yyextra->sourceFileDef = options.fileDef();
1227 yyextra->lineNumbers = options.fileDef()!=nullptr && options.showLineNumbers();
1228
1229 if (options.isExample() && options.fileDef()==nullptr)
1230 {
1231 // create a dummy filedef for the example
1232 yyextra->exampleFileDef = createFileDef(DString(),!options.exampleName().empty() ? options.exampleName() : DString("generated"));
1233 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1234 }
1235
1236 if (yyextra->sourceFileDef)
1237 {
1238 setCurrentDoc(yyscanner,"l00001");
1239 }
1240
1241 yyextra->includeCodeFragment = options.inlineFragment();
1242 // Starts line 1 on the output
1243 startCodeLine(yyscanner);
1244
1245 lexcodeYYrestart( nullptr, yyscanner );
1246 BEGIN( DefSection );
1247 lexcodeYYlex(yyscanner);
1248
1249 if (yyextra->insideCodeLine)
1250 {
1251 endCodeLine(yyscanner);
1252 }
1253 if (yyextra->exampleFileDef)
1254 {
1255 // delete the temporary file definition used for this example
1256 yyextra->exampleFileDef.reset();
1257 yyextra->sourceFileDef=0;
1258 }
1259}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
virtual DString fileName() const =0
yyguts_t * yyscan_t
Definition code.l:24
const char * qPrint(const char *s)
Definition dstring.h:783
std::unique_ptr< FileDef > createFileDef(const DString &p, const DString &n, const DString &ref, const DString &dn)
Definition filedef.cpp:269
static void endCodeLine(yyscan_t yyscanner)
Definition lexcode.l:1031
static void startCodeLine(yyscan_t yyscanner)
Definition lexcode.l:973
static void setCurrentDoc(yyscan_t yyscanner, const DString &anchor)
Definition lexcode.l:953
static int countLines(yyscan_t yyscanner)
Definition lexcode.l:1094
bool isExample() const
Definition parserintf.h:80
const Definition * searchCtx() const
Definition parserintf.h:88
DString exampleName() const
Definition parserintf.h:81
const FileDef * fileDef() const
Definition parserintf.h:82
int endLine() const
Definition parserintf.h:84
const MemberDef * memberDef() const
Definition parserintf.h:86
bool showLineNumbers() const
Definition parserintf.h:87
bool inlineFragment() const
Definition parserintf.h:85
int startLine() const
Definition parserintf.h:83
bool collectXRefs() const
Definition parserintf.h:89

References CodeParserOptions::collectXRefs(), countLines(), createFileDef(), DString::data(), DString::empty(), endCodeLine(), CodeParserOptions::endLine(), CodeParserOptions::exampleName(), CodeParserOptions::fileDef(), FileDef::fileName(), CodeParserOptions::inlineFragment(), CodeParserOptions::isExample(), Debug::Lex_lexcode, CodeParserOptions::memberDef(), p, qPrint(), CodeParserOptions::searchCtx(), setCurrentDoc(), CodeParserOptions::showLineNumbers(), startCodeLine(), and CodeParserOptions::startLine().

◆ 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 41 of file lexcode.h.

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


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