Skip to main content

The PythonCodeParser Class Reference

Declaration

class PythonCodeParser { ... }

Included Headers

#include <src/pycode.h>

Base class

classCodeParserInterface

Abstract interface for code parsers. More...

Public Constructors Index

PythonCodeParser ()

Public Destructor Index

~PythonCodeParser () override

Public Member Functions Index

voidparseCode (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. More...

voidresetCodeParserState () override

Resets the state of the code parser. More...

Private Member Attributes Index

std::unique_ptr< Private >p

Definition at line 33 of file pycode.h.

Public Constructors

PythonCodeParser()

PythonCodeParser::PythonCodeParser ()

Declaration at line 36 of file pycode.h, definition at line 1500 of file pycode.l.

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}

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

Public Destructor

~PythonCodeParser()

PythonCodeParser::~PythonCodeParser ()

Declaration at line 37 of file pycode.h, definition at line 1509 of file pycode.l.

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

Reference p.

Public Member Functions

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)
virtual

Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.

Parameters
[in] codeOutList

interface for writing the result.

[in] scopeName

Name of scope to which the code belongs.

[in] input

Actual code in the form of a string

[in] lang

The programming language of the code fragment.

[in] stripCodeComments

signals whether or not for the code block the doxygen comments should be stripped.

[in] isExampleBlock

TRUE iff the code is part of an example.

[in] exampleName

Name of the example.

[in] fileDef

File definition to which the code is associated.

[in] startLine

Starting line in case of a code fragment.

[in] endLine

Ending line of the code fragment.

[in] inlineFragment

Code fragment that is to be shown inline as part of the documentation.

[in] memberDef

Member definition to which the code is associated (non null in case of an inline fragment for a member).

[in] showLineNumbers

if set to TRUE and also fileDef is not 0, line numbers will be added to the source fragment

[in] searchCtx

context under which search data has to be stored.

[in] collectXRefs

collect cross-reference relations.

Declaration at line 40 of file pycode.h, definition at line 1526 of file pycode.l.

1527 const QCString &/* scopeName */,
1528 const QCString &input,
1529 SrcLangExt /*lang*/,
1530 bool stripCodeComments,
1531 bool isExampleBlock,
1532 const QCString &exampleName,
1533 const FileDef *fileDef,
1534 int startLine,
1535 int endLine,
1536 bool inlineFragment,
1537 const MemberDef * /* memberDef */,
1538 bool /* showLineNumbers */,
1539 const Definition *searchCtx,
1540 bool collectXRefs
1541 )
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}

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 ()
virtual

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()

Declaration at line 56 of file pycode.h, 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.

Private Member Attributes

p

std::unique_ptr<Private> PythonCodeParser::p

Definition at line 59 of file pycode.h.

59 std::unique_ptr<Private> p;

Referenced by parseCode, PythonCodeParser, resetCodeParserState and ~PythonCodeParser.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.