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_Internal, 0x10011) \
64 TKSPEC(RetVal_SwitchLang, 0x10012) \
65 TKSPEC(RetVal_CloseXml, 0x10013) \
66 TKSPEC(RetVal_EndBlockQuote, 0x10014) \
67 TKSPEC(RetVal_CopyDoc, 0x10015) \
68 TKSPEC(RetVal_EndInternal, 0x10016) \
69 TKSPEC(RetVal_EndParBlock, 0x10017) \
70 TKSPEC(RetVal_EndHtmlDetails, 0x10018) \
71 TKSPEC(RetVal_SubSubParagraph, 0x10019)
72
73enum class TokenRetval
74{
75#define TKSPEC(x,y) x = y,
78#undef TKSPEC
79};
80
81class Token
82{
83 public:
84 explicit Token(TokenRetval tv) : m_value(tv) {}
85 TokenRetval value() const { return m_value; }
86#define TKSPEC(x,y) static Token make_##x() { return Token(TokenRetval::x); }
89#undef TKSPEC
90
91 const char *to_string() const
92 {
93 const char *result = "ERROR";
94 switch (m_value)
95 {
96#define TKSPEC(x,y) case TokenRetval::x: result = #x; break;
99#undef TKSPEC
100 }
101 return result;
102 }
103
104 char command_to_char() const
105 {
106 return m_value==TokenRetval::TK_COMMAND_AT ? '@' : '\\';
107 }
108
109 static Token char_to_command(char c)
110 {
111 return c=='@' ? make_TK_COMMAND_AT() : make_TK_COMMAND_BS();
112 }
113
114 template<typename... ARGS>
115 bool is_any_of(ARGS... args) const
116 {
117 return ((m_value == args) || ...);
118 }
119
120 bool is(TokenRetval rv) const
121 {
122 return m_value==rv;
123 }
124
125 friend inline bool operator==(const Token &t1,const Token &t2) { return t1.m_value==t2.m_value; }
126 friend inline bool operator!=(const Token &t1,const Token &t2) { return !(operator==(t1,t2)); }
127
128 private:
130};
131
132/** @brief Data associated with a token used by the comment block parser. */
134{
135 // command token
136 QCString name;
137
138 // command text (RCS tag)
139 QCString text;
140
141 // comment blocks
142
143 // list token info
144 bool isEnumList = false;
145 bool isCheckedList = false;
146 int indent = 0;
147
148 // sections
149 QCString sectionId;
150
151 // simple section
154
155 // verbatim fragment
156 QCString verb;
157
158 // xrefitem
159 int id = -1;
160
161 // html tag
162 HtmlAttribList attribs;
163 bool endTag = false;
164 bool emptyTag = false;
165 QCString attribsStr;
166
167 // whitespace
168 QCString chars;
169
170 // url
171 bool isEMailAddr = false;
172
173 // param attributes
174 enum ParamDir { In=1, Out=2, InOut=3, Unspecified=0 };
176};
177
178class Definition;
179
181{
182 public:
183 DocTokenizer();
186
187 TokenInfo *token();
188 [[maybe_unused]] TokenInfo *resetToken();
189
190 void setLineNr(int lineno);
191 int getLineNr(void);
192 void pushState();
193 void popState();
194
195 // operations on the scanner
196 void findSections(const QCString &input,const Definition *d,
197 const QCString &fileName);
198 void init(const char *input,const QCString &fileName,
199 bool markdownSupport, bool insideHtmlLink);
200 void cleanup();
201 void pushContext();
202 bool popContext();
203 Token lex();
204 void unputString(const QCString &tag);
205 void setStatePara();
206 void setStateTitle();
208 void setStateCode();
209 void setStateICode();
210 void setStateXmlCode();
211 void setStateHtmlOnly();
212 void setStateManOnly();
213 void setStateLatexOnly();
214 void setStateXmlOnly();
215 void setStateDbOnly();
216 void setStateRtfOnly();
217 void setStateVerbatim();
218 void setStateIVerbatim();
219 void setStateILiteral();
220 void setStateILiteralOpt();
221 void setStateDot();
222 void setStateMsc();
223 void setStateParam();
224 void setStateXRefItem();
225 void setStateFile();
226 void setStateIFile();
227 void setStatePattern();
228 void setStateLink();
229 void setStateCite();
230 void setStateDoxyConfig();
231 void setStateRef();
232 void setStateInternalRef();
233 void setStateText();
234 void setStateSkipTitle();
235 void setStateAnchor();
236 void setInsidePre(bool b);
237 void pushBackHtmlTag(const QCString &tag);
238 void setStateSnippet();
239 void startAutoList();
240 void endAutoList();
241 void setStatePlantUML();
242 void setStateSetScope();
243 void setStatePlantUMLOpt();
244 void setStateOptions();
245 void setStateBlock();
246 void setStateEmoji();
247 void setStateILine();
249 void setStateShowDate();
250 void setStatePrefix();
251
252 private:
253 struct Private;
254 std::unique_ptr<Private> p;
255};
256
257#endif
The common base class of all entity definitions found in the sources.
Definition definition.h:76
TokenInfo * token()
void setStateTitleAttrValue()
void setStateILiteralOpt()
void setStateILiteral()
void setStateCite()
void setStateSnippet()
void setStatePrefix()
void setStateEmoji()
void init(const char *input, const QCString &fileName, bool markdownSupport, bool insideHtmlLink)
void setLineNr(int lineno)
void setStateCode()
void setStatePattern()
void startAutoList()
void setStateIFile()
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()
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()
int getLineNr(void)
void setStatePlantUML()
TokenInfo * resetToken()
void setStateIVerbatim()
void setStateXmlOnly()
std::unique_ptr< Private > p
void setStateSetScope()
void pushBackHtmlTag(const QCString &tag)
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
@ RETVAL_SPECIFICATIONS
#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