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 2208 of file docparser.cpp.

2209{
2210 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2211 assert(parser!=nullptr);
2212 if (parser==nullptr) return nullptr;
2213 if (!srcFile.isEmpty())
2214 {
2215 parser->context.fileName = srcFile;
2216 parser->tokenizer.setLineNr(srcLine);
2217 }
2218 return std::make_unique<DocNodeAST>(DocRef(parser,nullptr,target,context));
2219}
DocTokenizer tokenizer
DocParserContext context
Node representing a reference to some item.
Definition docnode.h:772
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 2022 of file docparser.cpp.

2029{
2030 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2031 assert(parser!=nullptr);
2032 if (parser==nullptr) return nullptr;
2033 //printf("validatingParseDoc(%s,%s)=[%s]\n",ctx?qPrint(ctx->name()):"<none>",
2034 // md?qPrint(md->name()):"<none>",
2035 // input);
2036 //printf("========== validating %s at line %d\n",qPrint(fileName),startLine);
2037 //printf("---------------- input --------------------\n%s\n----------- end input -------------------\n",qPrint(input));
2038
2039 // set initial token
2040 parser->context.token = parser->tokenizer.resetToken();
2041
2042 if (ctx && ctx!=Doxygen::globalScope &&
2045 )
2046 )
2047 {
2049 }
2050 else if (ctx && ctx->definitionType()==Definition::TypePage)
2051 {
2052 const Definition *scope = (toPageDef(ctx))->getPageScope();
2053 if (scope && scope!=Doxygen::globalScope)
2054 {
2055 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2056 }
2057 }
2058 else if (ctx && ctx->definitionType()==Definition::TypeGroup)
2059 {
2060 const Definition *scope = (toGroupDef(ctx))->getGroupScope();
2061 if (scope && scope!=Doxygen::globalScope)
2062 {
2063 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2064 }
2065 }
2066 else
2067 {
2068 parser->context.context = "";
2069 }
2070 parser->context.scope = ctx;
2071 parser->context.lang = getLanguageFromFileName(fileName);
2072
2073 if (indexWords && Doxygen::searchIndex.enabled())
2074 {
2075 if (md)
2076 {
2077 parser->context.searchUrl=md->getOutputFileBase();
2078 Doxygen::searchIndex.setCurrentDoc(md,md->anchor(),false);
2079 }
2080 else if (ctx)
2081 {
2082 parser->context.searchUrl=ctx->getOutputFileBase();
2083 Doxygen::searchIndex.setCurrentDoc(ctx,ctx->anchor(),false);
2084 }
2085 }
2086 else
2087 {
2088 parser->context.searchUrl="";
2089 }
2090
2091 parser->context.fileName = fileName;
2092 parser->context.relPath = (!linkFromIndex && ctx) ?
2094 QCString("");
2095 //printf("ctx->name=%s relPath=%s\n",qPrint(ctx->name()),qPrint(parser->context.relPath));
2096 parser->context.memberDef = md;
2097 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2098 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2099 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2100 parser->context.inSeeBlock = FALSE;
2101 parser->context.xmlComment = FALSE;
2102 parser->context.insideHtmlLink = FALSE;
2103 parser->context.includeFileText = "";
2104 parser->context.includeFileOffset = 0;
2105 parser->context.includeFileLength = 0;
2106 parser->context.isExample = isExample;
2107 parser->context.exampleName = exampleName;
2108 parser->context.hasParamCommand = FALSE;
2109 parser->context.hasReturnCommand = FALSE;
2110 parser->context.retvalsFound.clear();
2111 parser->context.paramsFound.clear();
2112 parser->context.markdownSupport = markdownSupport;
2113
2114 //printf("Starting comment block at %s:%d\n",qPrint(parser->context.fileName),startLine);
2115 parser->tokenizer.setLineNr(startLine);
2116 size_t ioLen = input.length();
2117 QCString inpStr = parser->processCopyDoc(input.data(),ioLen);
2118 if (inpStr.isEmpty() || inpStr.at(inpStr.length()-1)!='\n')
2119 {
2120 inpStr+='\n';
2121 }
2122 //printf("processCopyDoc(in='%s' out='%s')\n",input,qPrint(inpStr));
2123 parser->tokenizer.init(inpStr.data(),parser->context.fileName,
2125
2126 // build abstract syntax tree
2127 auto ast = std::make_unique<DocNodeAST>(DocRoot(parser,md!=nullptr,singleLine));
2128 std::get<DocRoot>(ast->root).parse();
2129
2131 {
2132 // pretty print the result
2133 std::visit(PrintDocVisitor{},ast->root);
2134 }
2135
2136 if (md && md->isFunction())
2137 {
2139 }
2141
2142 // reset token
2143 parser->tokenizer.resetToken();
2144
2145 //printf(">>>>>> end validatingParseDoc(%s,%s)\n",ctx?qPrint(ctx->name()):"<none>",
2146 // md?qPrint(md->name()):"<none>");
2147
2148 return ast;
2149}
@ 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:1307
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:578
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:6230

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(), generateHtmlOutput(), 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 2151 of file docparser.cpp.

2152{
2153 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2154 assert(parser!=nullptr);
2155 if (parser==nullptr) return nullptr;
2156
2157 // set initial token
2158 parser->context.token = parser->tokenizer.resetToken();
2159
2160 //printf("------------ input ---------\n%s\n"
2161 // "------------ end input -----\n",input);
2162 //parser->context.token = new TokenInfo;
2163 parser->context.context = "";
2164 parser->context.fileName = "<parseText>";
2165 parser->context.relPath = "";
2166 parser->context.memberDef = nullptr;
2167 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2168 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2169 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2170 parser->context.inSeeBlock = FALSE;
2171 parser->context.xmlComment = FALSE;
2172 parser->context.insideHtmlLink = FALSE;
2173 parser->context.includeFileText = "";
2174 parser->context.includeFileOffset = 0;
2175 parser->context.includeFileLength = 0;
2176 parser->context.isExample = FALSE;
2177 parser->context.exampleName = "";
2178 parser->context.hasParamCommand = FALSE;
2179 parser->context.hasReturnCommand = FALSE;
2180 parser->context.retvalsFound.clear();
2181 parser->context.paramsFound.clear();
2182 parser->context.searchUrl="";
2184 parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2185
2186
2187 auto ast = std::make_unique<DocNodeAST>(DocText(parser));
2188
2189 if (!input.isEmpty())
2190 {
2191 parser->tokenizer.setLineNr(1);
2192 parser->tokenizer.init(input.data(),parser->context.fileName,
2194
2195 // build abstract syntax tree
2196 std::get<DocText>(ast->root).parse();
2197
2199 {
2200 // pretty print the result
2201 std::visit(PrintDocVisitor{},ast->root);
2202 }
2203 }
2204
2205 return ast;
2206}
Root node of a text fragment.
Definition docnode.h:1298
#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().