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