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:
185 DocTokenizer();
188
189 TokenInfo *token();
190 [[maybe_unused]] TokenInfo *resetToken();
191
192 void setFileName(const QCString &fileName);
193 QCString getFileName() const;
194 void setLineNr(int lineno);
195 int getLineNr() const;
196 void pushState();
197 void popState();
198
199 // operations on the scanner
200 void findSections(const QCString &input,const Definition *d,
201 const QCString &fileName);
202 void init(const char *input,const QCString &fileName,
203 bool markdownSupport, bool insideHtmlLink);
204 void cleanup();
205 void pushContext();
206 bool popContext();
207 Token lex();
208 void unputString(const QCString &tag);
209 void setStatePara();
210 void setStateTitle();
212 void setStateCode();
213 void setStateICode();
214 void setStateXmlCode();
215 void setStateHtmlOnly();
216 void setStateManOnly();
217 void setStateLatexOnly();
218 void setStateXmlOnly();
219 void setStateDbOnly();
220 void setStateRtfOnly();
221 void setStateVerbatim();
222 void setStateIVerbatim();
223 void setStateILiteral();
224 void setStateILiteralOpt();
225 void setStateDot();
226 void setStateMsc();
227 void setStateParam();
228 void setStateXRefItem();
229 void setStateFile();
230 void setStateIFile();
231 void setStatePattern();
232 void setStateLink();
233 void setStateCite();
234 void setStateDoxyConfig();
235 void setStateRef();
236 void setStateInternalRef();
237 void setStateText();
238 void setStateSkipTitle();
239 void setStateAnchor();
240 void setInsidePre(bool b);
241 void pushBackHtmlTag(const QCString &tag);
242 void setStateSnippet();
243 void startAutoList();
244 void endAutoList();
245 void setStatePlantUML();
246 void setStateSetScope();
247 void setStatePlantUMLOpt();
248 void setStateOptions();
249 void setStateBlock();
250 void setStateEmoji();
251 void setStateILine();
253 void setStateShowDate();
254 void setStatePrefix();
255
256 private:
257 struct Private;
258 std::unique_ptr<Private> p;
259};
260
261#endif
The common base class of all entity definitions found in the sources.
Definition definition.h:77
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()
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 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