Doxygen
Loading...
Searching...
No Matches
docparser_p.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2022 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#ifndef DOCPARSER_P_H
17#define DOCPARSER_P_H
18
19/** @file
20 * @brief Private header shared between docparser.cpp and docnode.cpp
21 */
22
23#include <cassert>
24#include <stack>
25#include <iterator>
26#include <vector>
27#include <deque>
28#include <cstdint>
29
30#include "containers.h"
31#include "docparser.h"
32#include "docnode.h"
33#include "doctokenizer.h"
34#include "searchindex.h"
35#include "construct.h"
36#include "cmdmapper.h"
37
38using DefinitionStack = std::vector<const Definition *>;
39using DocNodeStack = std::stack<DocNodeVariant *>;
40
41template<typename T, typename Container = std::deque<T>>
42class IterableStack : public std::stack<T, Container>
43{
44 using std::stack<T, Container>::c;
45
46public:
47
48 // expose just the iterators of the underlying container
49 auto begin() { return std::begin(c); }
50 auto end() { return std::end(c); }
51
52 auto begin() const { return std::begin(c); }
53 auto end() const { return std::end(c); }
54};
56
57/** Parser's context to store all global variables.
58 */
60{
61 const Definition *scope = nullptr;
62 QCString context;
63 bool inSeeBlock = false;
64 bool xmlComment = false;
65 bool insideHtmlLink = false;
70 QCString fileName;
71 QCString relPath;
72
73 bool hasParamCommand = false;
74 bool hasReturnCommand = false;
77 const MemberDef * memberDef = nullptr;
78 bool isExample = false;
79 QCString exampleName;
80 QCString searchUrl;
81 QCString prefix;
83
90 bool stripCodeComments = true;
91
92 TokenInfo *token = nullptr;
93 int lineNo = 0;
94 bool markdownSupport = false;
95};
96
97class DocParser : public IDocParser
98{
99 public:
100 void pushContext();
101 void popContext();
102 void handleImg(DocNodeVariant *parent,DocNodeList &children,const HtmlAttribList &tagHtmlAttribs);
103 Token internalValidatingParseDoc(DocNodeVariant *parent,DocNodeList &children,
104 const QCString &doc);
105 QCString processCopyDoc(const char *data,size_t &len);
106 QCString findAndCopyImage(const QCString &fileName,DocImage::Type type, bool doWarn = true);
107 void checkArgumentName();
108 void checkRetvalName();
110 bool findDocsForMemberOrCompound(const QCString &commandName,
111 QCString *pDoc,
112 QCString *pBrief,
113 const Definition **pDef);
115 DocNodeList &children,bool
116 handleWord=TRUE);
118 DocNodeList &children,const QCString &txt);
120 DocNodeList &children, QCString &width,QCString &height);
121 Token handleStyleArgument(DocNodeVariant *parent,DocNodeList &children,
122 const QCString &cmdName);
123 void handleStyleEnter(DocNodeVariant *parent,DocNodeList &children, DocStyleChange::Style s,
124 const QCString &tagName,const HtmlAttribList *attribs);
125 void handleStyleLeave(DocNodeVariant *parent,DocNodeList &children, DocStyleChange::Style s,
126 const QCString &tagName);
127 void handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children);
128 void handleInitialStyleCommands(DocNodeVariant *parent,DocNodeList &children);
129 Token handleAHref(DocNodeVariant *parent,DocNodeList &children,const HtmlAttribList &tagHtmlAttribs);
131 void handleLinkedWord(DocNodeVariant *parent,DocNodeList &children,bool ignoreAutoLinkFlag=FALSE);
132 void handleParameterType(DocNodeVariant *parent,DocNodeList &children,const QCString &paramTypes);
133 void handleInternalRef(DocNodeVariant *parent,DocNodeList &children);
134 void handleAnchor(DocNodeVariant *parent,DocNodeList &children);
135 void handlePrefix(DocNodeVariant *parent,DocNodeList &children);
136 void handleImage(DocNodeVariant *parent, DocNodeList &children);
137 void readTextFileByName(const QCString &file,QCString &text);
138
139 std::stack< DocParserContext > contextStack;
140 DocParserContext context;
141 DocTokenizer tokenizer;
142};
143
144//---------------------------------------------------------------------------
145
147{
148 public:
149 AutoNodeStack(DocParser *parser,DocNodeVariant* node)
150 : m_parser(parser), m_node(node) { m_parser->context.nodeStack.push(node); }
152 {
153#if defined(NDEBUG)
154 (void)m_node;
155 if (!m_parser->context.nodeStack.empty())
156 {
157 m_parser->context.nodeStack.pop(); // robust version that does not assert
158 }
159#else
160 assert(m_parser->context.nodeStack.top()==m_node);
161 m_parser->context.nodeStack.pop(); // error checking version
162#endif
163 }
165
166 private:
167 DocParser *m_parser;
169};
170
171inline bool isPreformatted(const DocNodeVariant *n)
172{
173 return std::visit([](auto &&x)->decltype(auto) { return x.isPreformatted(); }, *n);
174}
175
176/*! Returns TRUE iff node n is a child of a preformatted node */
177inline bool insidePRE(const DocNodeVariant *n)
178{
179 while (n)
180 {
181 if (isPreformatted(n)) return TRUE;
182 n=parent(n);
183 }
184 return FALSE;
185}
186
187/*! Returns TRUE iff node n is a child of a html list item node */
188inline bool insideLI(const DocNodeVariant *n)
189{
190 while (n)
191 {
192 if (std::holds_alternative<DocHtmlListItem>(*n)) return TRUE;
193 n=parent(n);
194 }
195 return FALSE;
196}
197
198/*! Returns TRUE iff node n is a child of a html list item node */
199inline bool insideBlockQuote(const DocNodeVariant *n)
200{
201 while (n)
202 {
203 if (std::holds_alternative<DocHtmlBlockQuote>(*n)) return TRUE;
204 n=parent(n);
205 }
206 return FALSE;
207}
208
209
210//---------------------------------------------------------------------------
211
212/*! Returns TRUE iff node n is a child of a unordered html list node */
213inline bool insideUL(const DocNodeVariant *n)
214{
215 while (n)
216 {
217 if (std::holds_alternative<DocHtmlList>(*n) &&
218 std::get<DocHtmlList>(*n).type()==DocHtmlList::Unordered)
219 {
220 return TRUE;
221 }
222 n=parent(n);
223 }
224 return FALSE;
225}
226
227//---------------------------------------------------------------------------
228
229/*! Returns TRUE iff node n is a child of a ordered html list node */
230inline bool insideOL(const DocNodeVariant *n)
231{
232 while (n)
233 {
234 if (std::holds_alternative<DocHtmlList>(*n) &&
235 std::get<DocHtmlList>(*n).type()==DocHtmlList::Ordered)
236 {
237 return TRUE;
238 }
239 n=parent(n);
240 }
241 return FALSE;
242}
243
244//---------------------------------------------------------------------------
245
246inline bool insideTable(const DocNodeVariant *n)
247{
248 while (n)
249 {
250 if (std::holds_alternative<DocHtmlTable>(*n)) return TRUE;
251 n=parent(n);
252 }
253 return FALSE;
254}
255
256//---------------------------------------------------------------------------
257
258inline bool insideDetails(const DocNodeVariant *n)
259{
260 while (n)
261 {
262 if (std::holds_alternative<DocHtmlDetails>(*n)) return TRUE;
263 n=parent(n);
264 }
265 return FALSE;
266}
267
268//---------------------------------------------------------------------------
269
270inline bool insideDL(const DocNodeVariant *n)
271{
272 while (n)
273 {
274 if (std::holds_alternative<DocHtmlDescList>(*n)) return TRUE;
275 n=parent(n);
276 }
277 return FALSE;
278}
279
280#endif
DocParser * m_parser
const DocNodeVariant * m_node
AutoNodeStack(DocParser *parser, DocNodeVariant *node)
bool defaultHandleToken(DocNodeVariant *parent, Token tok, DocNodeList &children, bool handleWord=TRUE)
std::stack< DocParserContext > contextStack
void handleLinkedWord(DocNodeVariant *parent, DocNodeList &children, bool ignoreAutoLinkFlag=FALSE)
DocTokenizer tokenizer
void handleInternalRef(DocNodeVariant *parent, DocNodeList &children)
void handleParameterType(DocNodeVariant *parent, DocNodeList &children, const QCString &paramTypes)
QCString findAndCopyImage(const QCString &fileName, DocImage::Type type, bool doWarn=true)
Definition docparser.cpp:93
void checkRetvalName()
QCString processCopyDoc(const char *data, size_t &len)
void readTextFileByName(const QCString &file, QCString &text)
Token handleAHref(DocNodeVariant *parent, DocNodeList &children, const HtmlAttribList &tagHtmlAttribs)
Token internalValidatingParseDoc(DocNodeVariant *parent, DocNodeList &children, const QCString &doc)
void handleInitialStyleCommands(DocNodeVariant *parent, DocNodeList &children)
void handleStyleLeave(DocNodeVariant *parent, DocNodeList &children, DocStyleChange::Style s, const QCString &tagName)
void handlePendingStyleCommands(DocNodeVariant *parent, DocNodeList &children)
void checkUnOrMultipleDocumentedParams()
void popContext()
Definition docparser.cpp:73
bool findDocsForMemberOrCompound(const QCString &commandName, QCString *pDoc, QCString *pBrief, const Definition **pDef)
void handleImage(DocNodeVariant *parent, DocNodeList &children)
void handleStyleEnter(DocNodeVariant *parent, DocNodeList &children, DocStyleChange::Style s, const QCString &tagName, const HtmlAttribList *attribs)
void handlePrefix(DocNodeVariant *parent, DocNodeList &children)
Token handleStyleArgument(DocNodeVariant *parent, DocNodeList &children, const QCString &cmdName)
void checkArgumentName()
DocParserContext context
void handleAnchor(DocNodeVariant *parent, DocNodeList &children)
void handleImg(DocNodeVariant *parent, DocNodeList &children, const HtmlAttribList &tagHtmlAttribs)
void defaultHandleTitleAndSize(const CommandType cmd, DocNodeVariant *parent, DocNodeList &children, QCString &width, QCString &height)
void handleUnclosedStyleCommands()
void pushContext()
Definition docparser.cpp:59
void errorHandleDefaultToken(DocNodeVariant *parent, Token tok, DocNodeList &children, const QCString &txt)
opaque parser interface
Definition docparser.h:34
auto end() const
Definition docparser_p.h:53
auto begin() const
Definition docparser_p.h:52
CommandType
Definition cmdmapper.h:29
#define NON_COPYABLE(cls)
Macro to help implementing the rule of 5 for a non-copyable & movable class.
Definition construct.h:37
std::multiset< std::string > StringMultiSet
Definition containers.h:32
std::variant< DocWord, DocLinkedWord, DocURL, DocLineBreak, DocHorRuler, DocAnchor, DocCite, DocStyleChange, DocSymbol, DocEmoji, DocWhiteSpace, DocSeparator, DocVerbatim, DocInclude, DocIncOperator, DocFormula, DocIndexEntry, DocAutoList, DocAutoListItem, DocTitle, DocXRefItem, DocImage, DocDotFile, DocMscFile, DocDiaFile, DocVhdlFlow, DocLink, DocRef, DocInternalRef, DocHRef, DocHtmlHeader, DocHtmlDescTitle, DocHtmlDescList, DocSection, DocSecRefItem, DocSecRefList, DocInternal, DocParBlock, DocSimpleList, DocHtmlList, DocSimpleSect, DocSimpleSectSep, DocParamSect, DocPara, DocParamList, DocSimpleListItem, DocHtmlListItem, DocHtmlDescData, DocHtmlCell, DocHtmlCaption, DocHtmlRow, DocHtmlTable, DocHtmlBlockQuote, DocText, DocRoot, DocHtmlDetails, DocHtmlSummary, DocPlantUmlFile > DocNodeVariant
Definition docnode.h:66
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Definition docnode.h:1310
std::stack< DocNodeVariant * > DocNodeStack
Definition docparser_p.h:39
bool isPreformatted(const DocNodeVariant *n)
bool insideUL(const DocNodeVariant *n)
bool insideTable(const DocNodeVariant *n)
std::vector< const Definition * > DefinitionStack
Definition docparser_p.h:38
IterableStack< const DocNodeVariant * > DocStyleChangeStack
Definition docparser_p.h:55
bool insidePRE(const DocNodeVariant *n)
bool insideLI(const DocNodeVariant *n)
bool insideDL(const DocNodeVariant *n)
bool insideBlockQuote(const DocNodeVariant *n)
bool insideDetails(const DocNodeVariant *n)
bool insideOL(const DocNodeVariant *n)
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
Web server based search engine.
Parser's context to store all global variables.
Definition docparser_p.h:60
StringMultiSet retvalsFound
Definition docparser_p.h:75
bool includeFileShowLineNo
Definition docparser_p.h:89
DocStyleChangeStack styleStack
Definition docparser_p.h:67
size_t includeFileLength
Definition docparser_p.h:87
QCString fileName
Definition docparser_p.h:70
DocNodeStack nodeStack
Definition docparser_p.h:66
StringMultiSet paramsFound
Definition docparser_p.h:76
DefinitionStack copyStack
Definition docparser_p.h:69
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
QCString includeFileName
Definition docparser_p.h:84
size_t includeFileOffset
Definition docparser_p.h:86
const MemberDef * memberDef
Definition docparser_p.h:77
SrcLangExt
Language as given by extension.
Definition types.h:42