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 1500 of file pycode.l.

1500 : p(std::make_unique<Private>())
1501{
1502 pycodeYYlex_init_extra(&p->state,&p->yyscanner);
1503#ifdef FLEX_DEBUG
1504 pycodeYYset_debug(Debug::isFlagSet(Debug::Lex_pycode)?1:0,p->yyscanner);
1505#endif
1507}
@ 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:1514
std::unique_ptr< Private > p
Definition pycode.h:50

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

◆ ~PythonCodeParser()

PythonCodeParser::~PythonCodeParser ( )
override

Definition at line 1509 of file pycode.l.

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

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 1526 of file pycode.l.

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

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

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: