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, 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.

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:59

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

◆ ~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,
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 1525 of file pycode.l.

1541{
1542 yyscan_t yyscanner = p->yyscanner;
1543 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1544
1545 //printf("***parseCode(%s)\n",qPrint(input));
1546
1547 codeOutIntf.stripCodeComments(stripCodeComments);
1548 if (input.isEmpty()) return;
1549 DebugLex debugLex(Debug::Lex_pycode, __FILE__, fileDef ? qPrint(fileDef->fileName()): nullptr);
1550 yyextra->fileName = fileDef ? fileDef->fileName():"";
1551 yyextra->code = &codeOutIntf;
1552 yyextra->inputString = input.data();
1553 yyextra->inputPosition = 0;
1554 yyextra->currentFontClass = nullptr;
1555 yyextra->insideCodeLine = FALSE;
1556 yyextra->searchCtx=searchCtx;
1557 yyextra->collectXRefs=collectXRefs;
1558 if (startLine!=-1)
1559 yyextra->yyLineNr = startLine;
1560 else
1561 yyextra->yyLineNr = 1;
1562 if (endLine!=-1)
1563 yyextra->inputLines = endLine+1;
1564 else
1565 yyextra->inputLines = yyextra->yyLineNr + countLines(yyscanner) - 1;
1566
1567
1568 yyextra->exampleBlock = isExampleBlock;
1569 yyextra->exampleName = exampleName;
1570 yyextra->sourceFileDef = fileDef;
1571 yyextra->symbolResolver.setFileScope(fileDef);
1572 yyextra->foldStack.clear();
1573 yyextra->insideSpecialComment = false;
1574
1575 if (yyextra->exampleBlock && fileDef==nullptr)
1576 {
1577 // create a dummy filedef for the example
1578 yyextra->exampleFileDef = createFileDef("",(!exampleName.isEmpty()?qPrint(exampleName):"generated"));
1579 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1580 }
1581 if (yyextra->sourceFileDef)
1582 {
1583 setCurrentDoc(yyscanner,"l00001");
1584 }
1585
1586 yyextra->includeCodeFragment = inlineFragment;
1587 // Starts line 1 on the output
1588 startCodeLine(yyscanner);
1589
1590 pycodeYYrestart(nullptr,yyscanner);
1591
1592 pycodeYYlex(yyscanner);
1593
1594 if (!yyextra->indents.empty())
1595 {
1596 // printf("Exited pysourceparser in inconsistent state!\n");
1597 }
1598
1599 if (yyextra->insideCodeLine)
1600 {
1601 endCodeLine(yyscanner);
1602 }
1603 if (Config_getBool(HTML_CODE_FOLDING))
1604 {
1605 while (!yyextra->foldStack.empty())
1606 {
1607 yyextra->code->endFold();
1608 yyextra->foldStack.pop_back();
1609 }
1610 }
1611 if (yyextra->exampleFileDef)
1612 {
1613 // delete the temporary file definition used for this example
1614 yyextra->exampleFileDef.reset();
1615 yyextra->sourceFileDef=nullptr;
1616 }
1617 // write the tooltips
1618 yyextra->tooltipManager.writeTooltips(codeOutIntf);
1619}
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:3454
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

References Config_getBool, countLines(), createFileDef(), QCString::data(), endCodeLine(), FALSE, FileDef::fileName(), QCString::isEmpty(), Debug::Lex_pycode, p, qPrint(), setCurrentDoc(), startCodeLine(), 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.

Referenced by PythonCodeParser().

Member Data Documentation

◆ p

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

Definition at line 59 of file pycode.h.

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


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