Doxygen
Loading...
Searching...
No Matches
docparser.h File Reference
#include <stdio.h>
#include <memory>
#include "qcstring.h"
#include "growvector.h"
#include "construct.h"
#include "types.h"
+ Include dependency graph for docparser.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  IDocParser
 opaque parser interface More...
 
class  IDocNodeAST
 opaque representation of the abstract syntax tree (AST) More...
 

Typedefs

using IDocParserPtr = std::unique_ptr<IDocParser>
 pointer to parser interface
 
using IDocNodeASTPtr = std::unique_ptr<IDocNodeAST>
 

Functions

IDocParserPtr createDocParser ()
 factory function to create a parser
 
IDocNodeASTPtr validatingParseDoc (IDocParser &parserIntf, const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &input, bool indexWords, bool isExample, const QCString &exampleName, bool singleLine, bool linkFromIndex, bool markdownSupport)
 
IDocNodeASTPtr validatingParseText (IDocParser &parser, const QCString &input)
 
IDocNodeASTPtr createRef (IDocParser &parser, const QCString &target, const QCString &context, const QCString &srcFile="", int srcLine=-1)
 
void docFindSections (const QCString &input, const Definition *d, const QCString &fileName)
 

Typedef Documentation

◆ IDocNodeASTPtr

using IDocNodeASTPtr = std::unique_ptr<IDocNodeAST>

Definition at line 56 of file docparser.h.

◆ IDocParserPtr

using IDocParserPtr = std::unique_ptr<IDocParser>

pointer to parser interface

Definition at line 40 of file docparser.h.

Function Documentation

◆ createDocParser()

◆ createRef()

IDocNodeASTPtr createRef ( IDocParser & parser,
const QCString & target,
const QCString & context,
const QCString & srcFile = "",
int srcLine = -1 )

Definition at line 2179 of file docparser.cpp.

2180{
2181 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2182 assert(parser!=nullptr);
2183 if (parser==nullptr) return nullptr;
2184 if (!srcFile.isEmpty())
2185 {
2186 parser->context.fileName = srcFile;
2187 parser->tokenizer.setLineNr(srcLine);
2188 }
2189 return std::make_unique<DocNodeAST>(DocRef(parser,nullptr,target,context));
2190}
DocTokenizer tokenizer
DocParserContext context
Node representing a reference to some item.
Definition docnode.h:758
void setLineNr(int lineno)
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
QCString fileName
Definition docparser_p.h:70

References DocParser::context, DocParserContext::fileName, QCString::isEmpty(), DocTokenizer::setLineNr(), and DocParser::tokenizer.

Referenced by convertMapFile(), replaceRef(), and LayoutNavEntry::url().

◆ docFindSections()

void docFindSections ( const QCString & input,
const Definition * d,
const QCString & fileName )

◆ validatingParseDoc()

IDocNodeASTPtr validatingParseDoc ( IDocParser & parserIntf,
const QCString & fileName,
int startLine,
const Definition * ctx,
const MemberDef * md,
const QCString & input,
bool indexWords,
bool isExample,
const QCString & exampleName,
bool singleLine,
bool linkFromIndex,
bool markdownSupport )

Main entry point for the comment block parser.

Parameters
parserIntfThe parser object created via createDocParser()
fileNameFile in which the documentation block is found (or the name of the example file in case isExample is TRUE).
startLineLine at which the documentation block is found.
ctxClass or namespace to which this block belongs.
mdMember definition to which the documentation belongs. Can be 0.
inputString representation of the documentation block.
indexWordsIndicates whether or not words should be put in the search index.
isExampleTRUE if the documentation belongs to an example.
exampleNameBase name of the example file (0 if isExample is FALSE).
singleLineOutput should be presented on a single line, so without starting a new paragraph at the end.
linkFromIndexTRUE if the documentation is generated from an index page. In this case context is not used to determine the relative path when making a link.
markdownSupportTRUE if the input needs to take markdown markup into account.
Returns
An object representing the abstract syntax tree. Ownership of the pointer is handed over to the caller.

Definition at line 1993 of file docparser.cpp.

2000{
2001 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2002 assert(parser!=nullptr);
2003 if (parser==nullptr) return nullptr;
2004 //printf("validatingParseDoc(%s,%s)=[%s]\n",ctx?qPrint(ctx->name()):"<none>",
2005 // md?qPrint(md->name()):"<none>",
2006 // input);
2007 //printf("========== validating %s at line %d\n",qPrint(fileName),startLine);
2008 //printf("---------------- input --------------------\n%s\n----------- end input -------------------\n",qPrint(input));
2009
2010 // set initial token
2011 parser->context.token = parser->tokenizer.resetToken();
2012
2013 if (ctx && ctx!=Doxygen::globalScope &&
2016 )
2017 )
2018 {
2020 }
2021 else if (ctx && ctx->definitionType()==Definition::TypePage)
2022 {
2023 const Definition *scope = (toPageDef(ctx))->getPageScope();
2024 if (scope && scope!=Doxygen::globalScope)
2025 {
2026 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2027 }
2028 }
2029 else if (ctx && ctx->definitionType()==Definition::TypeGroup)
2030 {
2031 const Definition *scope = (toGroupDef(ctx))->getGroupScope();
2032 if (scope && scope!=Doxygen::globalScope)
2033 {
2034 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2035 }
2036 }
2037 else
2038 {
2039 parser->context.context = "";
2040 }
2041 parser->context.scope = ctx;
2042 parser->context.lang = getLanguageFromFileName(fileName);
2043
2044 if (indexWords && Doxygen::searchIndex.enabled())
2045 {
2046 if (md)
2047 {
2048 parser->context.searchUrl=md->getOutputFileBase();
2049 Doxygen::searchIndex.setCurrentDoc(md,md->anchor(),false);
2050 }
2051 else if (ctx)
2052 {
2053 parser->context.searchUrl=ctx->getOutputFileBase();
2054 Doxygen::searchIndex.setCurrentDoc(ctx,ctx->anchor(),false);
2055 }
2056 }
2057 else
2058 {
2059 parser->context.searchUrl="";
2060 }
2061
2062 parser->context.fileName = fileName;
2063 parser->context.relPath = (!linkFromIndex && ctx) ?
2065 QCString("");
2066 //printf("ctx->name=%s relPath=%s\n",qPrint(ctx->name()),qPrint(parser->context.relPath));
2067 parser->context.memberDef = md;
2068 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2069 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2070 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2071 parser->context.inSeeBlock = FALSE;
2072 parser->context.xmlComment = FALSE;
2073 parser->context.insideHtmlLink = FALSE;
2074 parser->context.includeFileText = "";
2075 parser->context.includeFileOffset = 0;
2076 parser->context.includeFileLength = 0;
2077 parser->context.isExample = isExample;
2078 parser->context.exampleName = exampleName;
2079 parser->context.hasParamCommand = FALSE;
2080 parser->context.hasReturnCommand = FALSE;
2081 parser->context.retvalsFound.clear();
2082 parser->context.paramsFound.clear();
2083 parser->context.markdownSupport = markdownSupport;
2084
2085 //printf("Starting comment block at %s:%d\n",qPrint(parser->context.fileName),startLine);
2086 parser->tokenizer.setLineNr(startLine);
2087 size_t ioLen = input.length();
2088 QCString inpStr = parser->processCopyDoc(input.data(),ioLen);
2089 if (inpStr.isEmpty() || inpStr.at(inpStr.length()-1)!='\n')
2090 {
2091 inpStr+='\n';
2092 }
2093 //printf("processCopyDoc(in='%s' out='%s')\n",input,qPrint(inpStr));
2094 parser->tokenizer.init(inpStr.data(),parser->context.fileName,
2096
2097 // build abstract syntax tree
2098 auto ast = std::make_unique<DocNodeAST>(DocRoot(parser,md!=nullptr,singleLine));
2099 std::get<DocRoot>(ast->root).parse();
2100
2102 {
2103 // pretty print the result
2104 std::visit(PrintDocVisitor{},ast->root);
2105 }
2106
2107 if (md && md->isFunction())
2108 {
2110 }
2112
2113 // reset token
2114 parser->tokenizer.resetToken();
2115
2116 //printf(">>>>>> end validatingParseDoc(%s,%s)\n",ctx?qPrint(ctx->name()):"<none>",
2117 // md?qPrint(md->name()):"<none>");
2118
2119 return ast;
2120}
@ PrintTree
Definition debug.h:33
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:135
The common base class of all entity definitions found in the sources.
Definition definition.h:76
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual DefType definitionType() const =0
virtual QCString anchor() const =0
virtual QCString qualifiedName() const =0
virtual QCString getOutputFileBase() const =0
virtual const QCString & name() const =0
QCString processCopyDoc(const char *data, size_t &len)
void checkUnOrMultipleDocumentedParams()
Root node of documentation tree.
Definition docnode.h:1293
void init(const char *input, const QCString &fileName, bool markdownSupport, bool insideHtmlLink)
TokenInfo * resetToken()
static NamespaceDefMutable * globalScope
Definition doxygen.h:121
static SearchIndexIntf searchIndex
Definition doxygen.h:124
virtual bool isFunction() const =0
virtual void detectUndocumentedParams(bool hasParamCommand, bool hasReturnCommand) const =0
This is an alternative implementation of QCString.
Definition qcstring.h:101
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:567
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
GroupDef * toGroupDef(Definition *d)
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:467
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
#define FALSE
Definition qcstring.h:34
StringMultiSet retvalsFound
Definition docparser_p.h:75
DocStyleChangeStack styleStack
Definition docparser_p.h:67
size_t includeFileLength
Definition docparser_p.h:87
DocNodeStack nodeStack
Definition docparser_p.h:66
StringMultiSet paramsFound
Definition docparser_p.h:76
QCString exampleName
Definition docparser_p.h:79
const Definition * scope
Definition docparser_p.h:61
QCString includeFileText
Definition docparser_p.h:85
TokenInfo * token
Definition docparser_p.h:92
DocStyleChangeStack initialStyleStack
Definition docparser_p.h:68
SrcLangExt lang
Definition docparser_p.h:82
QCString searchUrl
Definition docparser_p.h:80
size_t includeFileOffset
Definition docparser_p.h:86
const MemberDef * memberDef
Definition docparser_p.h:77
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5549
QCString relativePathToRoot(const QCString &name)
Definition util.cpp:3933
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang.
Definition util.cpp:6229

References Definition::anchor(), QCString::at(), DocParser::checkUnOrMultipleDocumentedParams(), DocParser::context, DocParserContext::context, QCString::data(), Definition::definitionType(), MemberDef::detectUndocumentedParams(), DocParserContext::exampleName, FALSE, DocParserContext::fileName, Definition::getLanguage(), getLanguageFromFileName(), getLanguageSpecificSeparator(), Definition::getOutputFileBase(), Doxygen::globalScope, DocParserContext::hasParamCommand, DocParserContext::hasReturnCommand, DocParserContext::includeFileLength, DocParserContext::includeFileOffset, DocParserContext::includeFileText, DocTokenizer::init(), DocParserContext::initialStyleStack, DocParserContext::inSeeBlock, DocParserContext::insideHtmlLink, QCString::isEmpty(), DocParserContext::isExample, Debug::isFlagSet(), MemberDef::isFunction(), DocParserContext::lang, QCString::length(), DocParserContext::markdownSupport, DocParserContext::memberDef, Definition::name(), DocParserContext::nodeStack, DocParserContext::paramsFound, Debug::PrintTree, DocParser::processCopyDoc(), Definition::qualifiedName(), relativePathToRoot(), DocParserContext::relPath, DocTokenizer::resetToken(), DocParserContext::retvalsFound, DocParserContext::scope, Doxygen::searchIndex, DocParserContext::searchUrl, DocTokenizer::setLineNr(), DocParserContext::styleStack, substitute(), toGroupDef(), DocParserContext::token, DocParser::tokenizer, toPageDef(), Definition::TypeClass, Definition::TypeGroup, Definition::TypeNamespace, Definition::TypePage, and DocParserContext::xmlComment.

Referenced by addPerlModDocBlock(), generateBriefDoc(), OutputList::generateDoc(), getSQLDocBlock(), parseCommentAsText(), ConceptDefImpl::writeBriefDescription(), DirDefImpl::writeBriefDescription(), FileDefImpl::writeBriefDescription(), GroupDefImpl::writeBriefDescription(), ModuleDefImpl::writeBriefDescription(), NamespaceDefImpl::writeBriefDescription(), MemberDefImpl::writeDeclaration(), ClassDefImpl::writeDeclarationLink(), ConceptDefImpl::writeDeclarationLink(), ModuleDefImpl::writeDeclarationLink(), MemberList::writePlainDeclarations(), and writeXMLDocBlock().

◆ validatingParseText()

IDocNodeASTPtr validatingParseText ( IDocParser & parser,
const QCString & input )

Main entry point for parsing simple text fragments. These fragments are limited to words, whitespace and symbols.

Definition at line 2122 of file docparser.cpp.

2123{
2124 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2125 assert(parser!=nullptr);
2126 if (parser==nullptr) return nullptr;
2127
2128 // set initial token
2129 parser->context.token = parser->tokenizer.resetToken();
2130
2131 //printf("------------ input ---------\n%s\n"
2132 // "------------ end input -----\n",input);
2133 //parser->context.token = new TokenInfo;
2134 parser->context.context = "";
2135 parser->context.fileName = "<parseText>";
2136 parser->context.relPath = "";
2137 parser->context.memberDef = nullptr;
2138 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2139 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2140 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2141 parser->context.inSeeBlock = FALSE;
2142 parser->context.xmlComment = FALSE;
2143 parser->context.insideHtmlLink = FALSE;
2144 parser->context.includeFileText = "";
2145 parser->context.includeFileOffset = 0;
2146 parser->context.includeFileLength = 0;
2147 parser->context.isExample = FALSE;
2148 parser->context.exampleName = "";
2149 parser->context.hasParamCommand = FALSE;
2150 parser->context.hasReturnCommand = FALSE;
2151 parser->context.retvalsFound.clear();
2152 parser->context.paramsFound.clear();
2153 parser->context.searchUrl="";
2155 parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2156
2157
2158 auto ast = std::make_unique<DocNodeAST>(DocText(parser));
2159
2160 if (!input.isEmpty())
2161 {
2162 parser->tokenizer.setLineNr(1);
2163 parser->tokenizer.init(input.data(),parser->context.fileName,
2165
2166 // build abstract syntax tree
2167 std::get<DocText>(ast->root).parse();
2168
2170 {
2171 // pretty print the result
2172 std::visit(PrintDocVisitor{},ast->root);
2173 }
2174 }
2175
2176 return ast;
2177}
Root node of a text fragment.
Definition docnode.h:1284
#define Config_getBool(name)
Definition config.h:33
@ Unknown
Definition types.h:43

References Config_getBool, DocParser::context, DocParserContext::context, QCString::data(), DocParserContext::exampleName, FALSE, DocParserContext::fileName, DocParserContext::hasParamCommand, DocParserContext::hasReturnCommand, DocParserContext::includeFileLength, DocParserContext::includeFileOffset, DocParserContext::includeFileText, DocTokenizer::init(), DocParserContext::initialStyleStack, DocParserContext::inSeeBlock, DocParserContext::insideHtmlLink, QCString::isEmpty(), DocParserContext::isExample, Debug::isFlagSet(), DocParserContext::lang, DocParserContext::markdownSupport, DocParserContext::memberDef, DocParserContext::nodeStack, DocParserContext::paramsFound, Debug::PrintTree, DocParserContext::relPath, DocTokenizer::resetToken(), DocParserContext::retvalsFound, DocParserContext::searchUrl, DocTokenizer::setLineNr(), DocParserContext::styleStack, DocParserContext::token, DocParser::tokenizer, Unknown, and DocParserContext::xmlComment.

Referenced by RTFGenerator::endIndexSection(), and OutputList::parseText().