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.
 
- Public Member Functions inherited from CodeParserInterface

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:64
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:135
void resetCodeParserState() override
Resets the state of the code parser.
Definition pycode.l:1514
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 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,
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 1526 of file pycode.l.

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

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: