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

#include <src/pycode.h>

Inheritance diagram for PythonCodeParser:
Collaboration diagram for PythonCodeParser:

Classes

struct  Private

Public Member Functions

 PythonCodeParser ()
 ~PythonCodeParser () override
void parseCode (OutputCodeList &codeOutIntf, const QCString &scopeName, const QCString &input, SrcLangExt lang, 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

Definition at line 33 of file pycode.h.

Constructor & Destructor Documentation

◆ PythonCodeParser()

PythonCodeParser::PythonCodeParser ( )

Definition at line 1499 of file pycode.l.

1499 : p(std::make_unique<Private>())
1500{
1501 pycodeYYlex_init_extra(&p->state,&p->yyscanner);
1502#ifdef FLEX_DEBUG
1503 pycodeYYset_debug(Debug::isFlagSet(Debug::Lex_pycode)?1:0,p->yyscanner);
1504#endif
1506}
@ Lex_pycode
Definition debug.h:65
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
void resetCodeParserState() override
Resets the state of the code parser.
Definition pycode.l:1513
std::unique_ptr< Private > p
Definition pycode.h:50

References Debug::isFlagSet(), Debug::Lex_pycode, and p.

◆ ~PythonCodeParser()

PythonCodeParser::~PythonCodeParser ( )
override

Definition at line 1508 of file pycode.l.

1509{
1510 pycodeYYlex_destroy(p->yyscanner);
1511}

References p.

Member Function Documentation

◆ parseCode()

void PythonCodeParser::parseCode ( OutputCodeList & codeOutList,
const QCString & scopeName,
const QCString & 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 1525 of file pycode.l.

1532{
1533 yyscan_t yyscanner = p->yyscanner;
1534 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1535
1536 //printf("***parseCode(%s)\n",qPrint(input));
1537
1538 codeOutIntf.stripCodeComments(stripCodeComments);
1539 if (input.isEmpty()) return;
1540 DebugLex debugLex(Debug::Lex_pycode, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()): nullptr);
1541 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
1542 yyextra->code = &codeOutIntf;
1543 yyextra->inputString = input.data();
1544 yyextra->inputPosition = 0;
1545 yyextra->currentFontClass = nullptr;
1546 yyextra->insideCodeLine = FALSE;
1547 yyextra->searchCtx = options.searchCtx();
1548 yyextra->collectXRefs = options.collectXRefs();
1549 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
1550 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
1551 yyextra->exampleBlock = options.isExample();
1552 yyextra->exampleName = options.exampleName();
1553 yyextra->sourceFileDef = options.fileDef();
1554 yyextra->symbolResolver.setFileScope(options.fileDef());
1555 yyextra->foldStack.clear();
1556 yyextra->insideSpecialComment = false;
1557
1558 if (yyextra->exampleBlock && options.fileDef()==nullptr)
1559 {
1560 // create a dummy filedef for the example
1561 yyextra->exampleFileDef = createFileDef("",(!options.exampleName().isEmpty()?qPrint(options.exampleName()):"generated"));
1562 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1563 }
1564 if (yyextra->sourceFileDef)
1565 {
1566 setCurrentDoc(yyscanner,"l00001");
1567 }
1568
1569 yyextra->includeCodeFragment = options.inlineFragment();
1570 // Starts line 1 on the output
1571 startCodeLine(yyscanner);
1572
1573 pycodeYYrestart(nullptr,yyscanner);
1574
1575 pycodeYYlex(yyscanner);
1576
1577 if (!yyextra->indents.empty())
1578 {
1579 // printf("Exited pysourceparser in inconsistent state!\n");
1580 }
1581
1582 if (yyextra->insideCodeLine)
1583 {
1584 endCodeLine(yyscanner);
1585 }
1586 if (Config_getBool(HTML_CODE_FOLDING))
1587 {
1588 while (!yyextra->foldStack.empty())
1589 {
1590 yyextra->code->endFold();
1591 yyextra->foldStack.pop_back();
1592 }
1593 }
1594 if (yyextra->exampleFileDef)
1595 {
1596 // delete the temporary file definition used for this example
1597 yyextra->exampleFileDef.reset();
1598 yyextra->sourceFileDef=nullptr;
1599 }
1600 // write the tooltips
1601 yyextra->tooltipManager.writeTooltips(codeOutIntf);
1602}
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:3462
yyguts_t * yyscan_t
Definition code.l:24
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition code.l:2277
#define Config_getBool(name)
Definition config.h:33
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
#define FALSE
Definition qcstring.h:34
bool isExample() const
Definition parserintf.h:81
const Definition * searchCtx() const
Definition parserintf.h:89
const FileDef * fileDef() const
Definition parserintf.h:83
int endLine() const
Definition parserintf.h:85
bool inlineFragment() const
Definition parserintf.h:86
QCString exampleName() const
Definition parserintf.h:82
int startLine() const
Definition parserintf.h:84
bool collectXRefs() const
Definition parserintf.h:90

References CodeParserOptions::collectXRefs(), Config_getBool, countLines(), createFileDef(), QCString::data(), endCodeLine(), CodeParserOptions::endLine(), CodeParserOptions::exampleName(), FALSE, CodeParserOptions::fileDef(), FileDef::fileName(), CodeParserOptions::inlineFragment(), QCString::isEmpty(), CodeParserOptions::isExample(), Debug::Lex_pycode, p, qPrint(), CodeParserOptions::searchCtx(), setCurrentDoc(), startCodeLine(), CodeParserOptions::startLine(), and OutputCodeList::stripCodeComments().

◆ resetCodeParserState()

void PythonCodeParser::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 1513 of file pycode.l.

1514{
1515 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
1516 yyextra->codeClassMap.clear();
1517 yyextra->currentDefinition = nullptr;
1518 yyextra->currentMemberDef = nullptr;
1519 yyextra->doubleStringIsDoc = FALSE;
1520 yyextra->paramParens = 0;
1521 while (!yyextra->indents.empty()) yyextra->indents.pop();
1522 BEGIN( Body );
1523}

References FALSE, and p.

Member Data Documentation

◆ p

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

Definition at line 50 of file pycode.h.

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


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