Doxygen
Loading...
Searching...
No Matches
doctokenizer.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * $Id: $
4 *
5 *
6 * Copyright (C) 1997-2015 by Dimitri van Heesch.
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation under the terms of the GNU General Public License is hereby
10 * granted. No representations are made about the suitability of this software
11 * for any purpose. It is provided "as is" without express or implied warranty.
12 * See the GNU General Public License for more details.
13 *
14 * Documents produced by Doxygen are derivative works derived from the
15 * input used in their production; they are not affected by this license.
16 *
17 */
18
19#ifndef DOCTOKENIZER_H
20#define DOCTOKENIZER_H
21
22#include <stdio.h>
23#include <memory>
24
25#include "htmlattrib.h"
26#include "qcstring.h"
27#include "construct.h"
28
29#define TOKEN_SPECIFICATIONS \
30 TKSPEC(TK_EOF, -1) \
31 TKSPEC(TK_NONE, 0) \
32 TKSPEC(TK_WORD, 1) \
33 TKSPEC(TK_LNKWORD, 2) \
34 TKSPEC(TK_WHITESPACE, 3) \
35 TKSPEC(TK_LISTITEM, 4) \
36 TKSPEC(TK_ENDLIST, 5) \
37 TKSPEC(TK_COMMAND_AT, 6) /*! Command starting with `@` */ \
38 TKSPEC(TK_HTMLTAG, 7) \
39 TKSPEC(TK_SYMBOL, 8) \
40 TKSPEC(TK_NEWPARA, 9) \
41 TKSPEC(TK_RCSTAG, 10) \
42 TKSPEC(TK_URL, 11) \
43 TKSPEC(TK_COMMAND_BS, 12) /*! Command starting with `\` */
44
45#define RETVAL_SPECIFICATIONS \
46 TKSPEC(RetVal_OK, 0x10000) \
47 TKSPEC(RetVal_SimpleSec, 0x10001) \
48 TKSPEC(RetVal_ListItem, 0x10002) \
49 TKSPEC(RetVal_Section, 0x10003) \
50 TKSPEC(RetVal_Subsection, 0x10004) \
51 TKSPEC(RetVal_Subsubsection, 0x10005) \
52 TKSPEC(RetVal_Paragraph, 0x10006) \
53 TKSPEC(RetVal_SubParagraph, 0x10007) \
54 TKSPEC(RetVal_EndList, 0x10008) \
55 TKSPEC(RetVal_EndPre, 0x10009) \
56 TKSPEC(RetVal_DescData, 0x1000A) \
57 TKSPEC(RetVal_DescTitle, 0x1000B) \
58 TKSPEC(RetVal_EndDesc, 0x1000C) \
59 TKSPEC(RetVal_TableRow, 0x1000D) \
60 TKSPEC(RetVal_TableCell, 0x1000E) \
61 TKSPEC(RetVal_TableHCell, 0x1000F) \
62 TKSPEC(RetVal_EndTable, 0x10010) \
63 TKSPEC(RetVal_EndTableCell, 0x10011) \
64 TKSPEC(RetVal_EndTableRow, 0x10012) \
65 TKSPEC(RetVal_Internal, 0x10013) \
66 TKSPEC(RetVal_SwitchLang, 0x10014) \
67 TKSPEC(RetVal_CloseXml, 0x10015) \
68 TKSPEC(RetVal_EndBlockQuote, 0x10016) \
69 TKSPEC(RetVal_CopyDoc, 0x10017) \
70 TKSPEC(RetVal_EndInternal, 0x10018) \
71 TKSPEC(RetVal_EndParBlock, 0x10019) \
72 TKSPEC(RetVal_EndHtmlDetails, 0x1001A) \
73 TKSPEC(RetVal_SubSubParagraph, 0x1001B)
74
75enum class TokenRetval
76{
77#define TKSPEC(x,y) x = y,
80#undef TKSPEC
81};
82
83class Token
84{
85 public:
86 explicit Token(TokenRetval tv) : m_value(tv) {}
87 TokenRetval value() const { return m_value; }
88#define TKSPEC(x,y) static Token make_##x() { return Token(TokenRetval::x); }
91#undef TKSPEC
92
93 const char *to_string() const
94 {
95 const char *result = "ERROR";
96 switch (m_value)
97 {
98#define TKSPEC(x,y) case TokenRetval::x: result = #x; break;
101#undef TKSPEC
102 }
103 return result;
104 }
105
106 char command_to_char() const
107 {
108 return m_value==TokenRetval::TK_COMMAND_AT ? '@' : '\\';
109 }
110
111 static Token char_to_command(char c)
112 {
113 return c=='@' ? make_TK_COMMAND_AT() : make_TK_COMMAND_BS();
114 }
115
116 template<typename... ARGS>
117 bool is_any_of(ARGS... args) const
118 {
119 return ((m_value == args) || ...);
120 }
121
122 bool is(TokenRetval rv) const
123 {
124 return m_value==rv;
125 }
126
127 friend inline bool operator==(const Token &t1,const Token &t2) { return t1.m_value==t2.m_value; }
128 friend inline bool operator!=(const Token &t1,const Token &t2) { return !(operator==(t1,t2)); }
129
130 private:
132};
133
134/** @brief Data associated with a token used by the comment block parser. */
136{
137 // command token
139
140 // command text (RCS tag)
142
143 // comment blocks
144
145 // list token info
146 bool isEnumList = false;
147 bool isCheckedList = false;
148 int indent = 0;
149
150 // sections
152
153 // simple section
156
157 // verbatim fragment
159
160 // xrefitem
161 int id = -1;
162
163 // html tag
165 bool endTag = false;
166 bool emptyTag = false;
168
169 // whitespace
171
172 // url
173 bool isEMailAddr = false;
174
175 // param attributes
176 enum ParamDir { In=1, Out=2, InOut=3, Unspecified=0 };
178};
179
180class Definition;
181
183{
184 public:
186 {
187 public:
188 AutoSaveState(DocTokenizer &tok) : m_tok(tok) { m_tok.pushState(); }
189 ~AutoSaveState() { m_tok.popState(); }
190 private:
192 };
193
194 DocTokenizer();
197
198 TokenInfo *token();
199 [[maybe_unused]] TokenInfo *resetToken();
200
201 void setFileName(const QCString &fileName);
202 QCString getFileName() const;
203 void setLineNr(int lineno);
204 int getLineNr() const;
205
206 // operations on the scanner
207 void findSections(const QCString &input,const Definition *d,
208 const QCString &fileName);
209 void init(const char *input,const QCString &fileName,
210 bool markdownSupport, bool insideHtmlLink);
211 void cleanup();
212 Token lex();
213 void unputString(const QCString &tag);
214 void setStatePara();
215 void setStateTitle();
217 void setStateCode();
218 void setStateICode();
219 void setStateXmlCode();
220 void setStateHtmlOnly();
221 void setStateManOnly();
222 void setStateLatexOnly();
223 void setStateXmlOnly();
224 void setStateDbOnly();
225 void setStateRtfOnly();
226 void setStateVerbatim();
227 void setStateIVerbatim();
228 void setStateILiteral();
229 void setStateILiteralOpt();
230 void setStateDot();
231 void setStateMsc();
232 void setStateParam();
233 void setStateXRefItem();
234 void setStateFile();
235 void setStateIFile();
236 void setStatePattern();
237 void setStateLink();
238 void setStateCite();
239 void setStateDoxyConfig();
240 void setStateRef();
241 void setStateInternalRef();
242 void setStateText();
243 void setStateSkipTitle();
244 void setStateAnchor();
245 void setInsidePre(bool b);
246 void pushBackHtmlTag(const QCString &tag);
247 void setStateSnippet();
248 void startAutoList();
249 void endAutoList();
250 void setStatePlantUML();
251 void setStateMermaid();
252 void setStateSetScope();
253 void setStatePlantUMLOpt();
254 void setStateMermaidOpt();
255 void setStateOptions();
256 void setStateBlock();
257 void setStateEmoji();
258 void setStateILine();
260 void setStateShowDate();
261 void setStatePrefix();
262
263 private:
264 friend class AutoSaveState;
265 friend class DocParser;
266 void pushState();
267 void popState();
268 void pushContext();
269 bool popContext();
270 struct Private;
271 std::unique_ptr<Private> p;
272};
273
274#endif
The common base class of all entity definitions found in the sources.
Definition definition.h:77
AutoSaveState(DocTokenizer &tok)
TokenInfo * token()
void setStateTitleAttrValue()
void setStateILiteralOpt()
void setStateILiteral()
void setStateCite()
void setStateSnippet()
void setStatePrefix()
void setStateEmoji()
void setStateMermaidOpt()
void init(const char *input, const QCString &fileName, bool markdownSupport, bool insideHtmlLink)
void setLineNr(int lineno)
friend class DocParser
void setStateCode()
void setStatePattern()
void startAutoList()
void setStateIFile()
QCString getFileName() const
void setFileName(const QCString &fileName)
void setStateSkipTitle()
void setStateParam()
void setStateBlock()
void setStatePlantUMLOpt()
void setStateAnchor()
void findSections(const QCString &input, const Definition *d, const QCString &fileName)
void setStateRtfOnly()
void setStateVerbatim()
void setStateLink()
void setStateTitle()
void setStateFile()
void setStateLatexOnly()
void setStateManOnly()
void setStateShowDate()
void setInsidePre(bool b)
void setStateXRefItem()
int getLineNr() const
void setStateText()
void setStateXmlCode()
void unputString(const QCString &tag)
void setStateDbOnly()
void setStateHtmlOnly()
void setStateInternalRef()
void setStateILine()
void setStateICode()
void setStateOptions()
void setStateDoxyConfig()
void setStateQuotedString()
void setStatePara()
void setStatePlantUML()
TokenInfo * resetToken()
void setStateIVerbatim()
void setStateXmlOnly()
std::unique_ptr< Private > p
void setStateMermaid()
void setStateSetScope()
void pushBackHtmlTag(const QCString &tag)
Class representing a list of HTML attributes.
Definition htmlattrib.h:33
This is an alternative implementation of QCString.
Definition qcstring.h:101
friend bool operator==(const Token &t1, const Token &t2)
bool is(TokenRetval rv) const
TokenRetval m_value
static Token char_to_command(char c)
TOKEN_SPECIFICATIONS RETVAL_SPECIFICATIONS const char * to_string() const
TokenRetval value() const
bool is_any_of(ARGS... args) const
friend bool operator!=(const Token &t1, const Token &t2)
Token(TokenRetval tv)
char command_to_char() const
#define NON_COPYABLE(cls)
Macro to help implementing the rule of 5 for a non-copyable & movable class.
Definition construct.h:37
TokenRetval
#define TOKEN_SPECIFICATIONS
#define RETVAL_SPECIFICATIONS
Data associated with a token used by the comment block parser.
ParamDir paramDir
QCString verb
bool isEnumList
QCString text
QCString sectionId
QCString chars
HtmlAttribList attribs
bool isCheckedList
QCString simpleSectText
QCString name
QCString attribsStr
bool isEMailAddr
QCString simpleSectName