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< Private > p

Detailed Description

LEX code scanner.

Definition at line 24 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: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: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 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 1196 of file lexcode.l.

1203{
1204 yyscan_t yyscanner = p->yyscanner;
1205 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1206
1207 if (input.empty()) return;
1208
1209 DebugLex debugLex(Debug::Lex_lexcode, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()) : nullptr);
1210
1211 yyextra->code = &codeOutIntf;
1212 yyextra->inputString = input.data();
1213 yyextra->inputPosition = 0;
1214 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
1215 yyextra->currentFontClass = nullptr;
1216 yyextra->insideCodeLine = false;
1217 yyextra->classScope = scopeName;
1218 yyextra->currentMemberDef = options.memberDef();
1219 yyextra->searchCtx = options.searchCtx();
1220 yyextra->collectXRefs = options.collectXRefs();
1221 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
1222 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
1223 yyextra->startCCodeLine = yyextra->yyLineNr;
1224 yyextra->stripCodeComments = stripCodeComments;
1225 yyextra->exampleBlock = options.isExample();
1226 yyextra->exampleName = options.exampleName();
1227 yyextra->sourceFileDef = options.fileDef();
1228 yyextra->lineNumbers = options.fileDef()!=nullptr && options.showLineNumbers();
1229
1230 if (options.isExample() && options.fileDef()==nullptr)
1231 {
1232 // create a dummy filedef for the example
1233 yyextra->exampleFileDef = createFileDef(DString(),!options.exampleName().empty() ? options.exampleName() : DString("generated"));
1234 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1235 }
1236
1237 if (yyextra->sourceFileDef)
1238 {
1239 setCurrentDoc(yyscanner,"l00001");
1240 }
1241
1242 yyextra->includeCodeFragment = options.inlineFragment();
1243 // Starts line 1 on the output
1244 startCodeLine(yyscanner);
1245
1246 lexcodeYYrestart( nullptr, yyscanner );
1247 BEGIN( DefSection );
1248 lexcodeYYlex(yyscanner);
1249
1250 if (yyextra->insideCodeLine)
1251 {
1252 endCodeLine(yyscanner);
1253 }
1254 if (yyextra->exampleFileDef)
1255 {
1256 // delete the temporary file definition used for this example
1257 yyextra->exampleFileDef.reset();
1258 yyextra->sourceFileDef=0;
1259 }
1260}
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:25
#define yyguts_t
Definition code.l:23
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:270
static void endCodeLine(yyscan_t yyscanner)
Definition lexcode.l:1032
static void startCodeLine(yyscan_t yyscanner)
Definition lexcode.l:974
static void setCurrentDoc(yyscan_t yyscanner, const DString &anchor)
Definition lexcode.l:954
static int countLines(yyscan_t yyscanner)
Definition lexcode.l:1095
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(), CodeParserOptions::startLine(), and yyguts_t.

◆ 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, and yyguts_t.

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: