Doxygen
Loading...
Searching...
No Matches
doctokenizer.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2026 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 DOCTOKENIZER_H
17#define DOCTOKENIZER_H
18
19#include <cstdio>
20#include <memory>
21
22#include "construct.h"
23#include "dstring.h"
24#include "htmlattrib.h"
25
26#define TOKEN_SPECIFICATIONS \
27 TKSPEC(TK_EOF, -1) \
28 TKSPEC(TK_NONE, 0) \
29 TKSPEC(TK_WORD, 1) \
30 TKSPEC(TK_LNKWORD, 2) \
31 TKSPEC(TK_WHITESPACE, 3) \
32 TKSPEC(TK_LISTITEM, 4) \
33 TKSPEC(TK_ENDLIST, 5) \
34 TKSPEC(TK_COMMAND_AT, 6) /*! Command starting with `@` */ \
35 TKSPEC(TK_HTMLTAG, 7) \
36 TKSPEC(TK_SYMBOL, 8) \
37 TKSPEC(TK_NEWPARA, 9) \
38 TKSPEC(TK_RCSTAG, 10) \
39 TKSPEC(TK_URL, 11) \
40 TKSPEC(TK_COMMAND_BS, 12) /*! Command starting with `\` */
41
42#define RETVAL_SPECIFICATIONS \
43 TKSPEC(RetVal_OK, 0x10000) \
44 TKSPEC(RetVal_SimpleSec, 0x10001) \
45 TKSPEC(RetVal_ListItem, 0x10002) \
46 TKSPEC(RetVal_Section, 0x10003) \
47 TKSPEC(RetVal_Subsection, 0x10004) \
48 TKSPEC(RetVal_Subsubsection, 0x10005) \
49 TKSPEC(RetVal_Paragraph, 0x10006) \
50 TKSPEC(RetVal_SubParagraph, 0x10007) \
51 TKSPEC(RetVal_EndList, 0x10008) \
52 TKSPEC(RetVal_EndPre, 0x10009) \
53 TKSPEC(RetVal_DescData, 0x1000A) \
54 TKSPEC(RetVal_DescTitle, 0x1000B) \
55 TKSPEC(RetVal_EndDesc, 0x1000C) \
56 TKSPEC(RetVal_TableRow, 0x1000D) \
57 TKSPEC(RetVal_TableCell, 0x1000E) \
58 TKSPEC(RetVal_TableHCell, 0x1000F) \
59 TKSPEC(RetVal_EndTable, 0x10010) \
60 TKSPEC(RetVal_EndTableCell, 0x10011) \
61 TKSPEC(RetVal_EndTableRow, 0x10012) \
62 TKSPEC(RetVal_Internal, 0x10013) \
63 TKSPEC(RetVal_SwitchLang, 0x10014) \
64 TKSPEC(RetVal_CloseXml, 0x10015) \
65 TKSPEC(RetVal_EndBlockQuote, 0x10016) \
66 TKSPEC(RetVal_CopyDoc, 0x10017) \
67 TKSPEC(RetVal_EndInternal, 0x10018) \
68 TKSPEC(RetVal_EndParBlock, 0x10019) \
69 TKSPEC(RetVal_EndHtmlDetails, 0x1001A) \
70 TKSPEC(RetVal_SubSubParagraph, 0x1001B)
71
72enum class TokenRetval
73{
74#define TKSPEC(x,y) x = y,
77#undef TKSPEC
78};
79
80class Token
81{
82 public:
83 explicit Token(TokenRetval tv) : m_value(tv) {}
84 TokenRetval value() const { return m_value; }
85#define TKSPEC(x,y) static Token make_##x() { return Token(TokenRetval::x); }
88#undef TKSPEC
89
90 const char *to_string() const
91 {
92 const char *result = "ERROR";
93 switch (m_value)
94 {
95#define TKSPEC(x,y) case TokenRetval::x: result = #x; break;
98#undef TKSPEC
99 }
100 return result;
101 }
102
103 char command_to_char() const
104 {
105 return m_value==TokenRetval::TK_COMMAND_AT ? '@' : '\\';
106 }
107
108 static Token char_to_command(char c)
109 {
110 return c=='@' ? make_TK_COMMAND_AT() : make_TK_COMMAND_BS();
111 }
112
113 template<typename... ARGS>
114 bool is_any_of(ARGS... args) const
115 {
116 return ((m_value == args) || ...);
117 }
118
119 bool is(TokenRetval rv) const
120 {
121 return m_value==rv;
122 }
123
124 friend inline bool operator==(const Token &t1,const Token &t2) { return t1.m_value==t2.m_value; }
125 friend inline bool operator!=(const Token &t1,const Token &t2) { return !(operator==(t1,t2)); }
126
127 private:
129};
130
131/** @brief Data associated with a token used by the comment block parser. */
133{
134 public:
135 // command token
137
138 // command text (RCS tag)
140
141 // comment blocks
142
143 // list token info
144 bool isEnumList = false;
145 bool isCheckedList = false;
146 int indent = 0;
147
148 // sections
150
151 // simple section
154
155 // verbatim fragment
157
158 // xrefitem
159 int id = -1;
160
161 // html tag
163 bool endTag = false;
164 bool emptyTag = false;
166
167 // whitespace
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:
184 {
185 public:
188 private:
190 };
191
192 DocTokenizer();
195
196 TokenInfo *token();
197 [[maybe_unused]] TokenInfo *resetToken();
198
199 void setFileName(const DString &fileName);
200 DString getFileName() const;
201 void setLineNr(int lineno);
202 int getLineNr() const;
203
204 // operations on the scanner
205 void findSections(const DString &input,const Definition *d,
206 const DString &fileName);
207 void init(const char *input,const DString &fileName,
208 bool markdownSupport, bool insideHtmlLink);
209 void cleanup();
210 Token lex();
211 void unputString(const DString &tag);
212 void setStatePara();
213 void setStateTitle();
215 void setStateCode();
216 void setStateICode();
217 void setStateXmlCode();
218 void setStateHtmlOnly();
219 void setStateManOnly();
220 void setStateLatexOnly();
221 void setStateXmlOnly();
222 void setStateDbOnly();
223 void setStateRtfOnly();
224 void setStateVerbatim();
225 void setStateIVerbatim();
226 void setStateILiteral();
227 void setStateILiteralOpt();
228 void setStateDot();
229 void setStateMsc();
230 void setStateParam();
231 void setStateXRefItem();
232 void setStateFile();
233 void setStateIFile();
234 void setStatePattern();
235 void setStateLink();
236 void setStateCite();
237 void setStateDoxyConfig();
238 void setStateRef();
239 void setStateInternalRef();
240 void setStateText();
241 void setStateSkipTitle();
242 void setStateAnchor();
243 void setInsidePre(bool b);
244 void pushBackHtmlTag(const DString &tag);
245 void setStateSnippet();
246 void startAutoList();
247 void endAutoList();
248 void setStatePlantUML();
249 void setStateMermaid();
250 void setStateSetScope();
251 void setStatePlantUMLOpt();
252 void setStateMermaidOpt();
253 void setStateOptions();
254 void setStateBlock();
255 void setStateEmoji();
256 void setStateILine();
258 void setStateShowDate();
259 void setStatePrefix();
260
261 private:
262 friend class AutoSaveState;
263 friend class DocParser;
264 void pushState();
265 void popState();
266 void pushContext();
267 bool popContext();
268 struct Private;
269 std::unique_ptr<Private> p;
270};
271
272#endif
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
The common base class of all entity definitions found in the sources.
Definition definition.h:77
AutoSaveState(DocTokenizer &tok)
TokenInfo * token()
DString getFileName() const
void setStateTitleAttrValue()
void setStateILiteralOpt()
void setStateILiteral()
void unputString(const DString &tag)
void setStateCite()
void setStateSnippet()
void setStatePrefix()
void setStateEmoji()
void setStateMermaidOpt()
void setLineNr(int lineno)
friend class DocParser
void setStateCode()
void setStatePattern()
void startAutoList()
void setStateIFile()
void setStateSkipTitle()
void setStateParam()
void setStateBlock()
void setStatePlantUMLOpt()
void setStateAnchor()
void setStateRtfOnly()
void setStateVerbatim()
void setStateLink()
void setStateTitle()
void setStateFile()
void setStateLatexOnly()
void setStateManOnly()
void setStateShowDate()
void setInsidePre(bool b)
void findSections(const DString &input, const Definition *d, const DString &fileName)
void setStateXRefItem()
int getLineNr() const
void setStateText()
void setStateXmlCode()
void setStateDbOnly()
void setStateHtmlOnly()
void setStateInternalRef()
void pushBackHtmlTag(const DString &tag)
void init(const char *input, const DString &fileName, bool markdownSupport, bool insideHtmlLink)
void setStateILine()
void setFileName(const DString &fileName)
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()
Class representing a list of HTML attributes.
Definition htmlattrib.h:31
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
Data associated with a token used by the comment block parser.
DString simpleSectName
ParamDir paramDir
DString verb
DString sectionId
bool isEnumList
DString chars
HtmlAttribList attribs
DString simpleSectText
bool isCheckedList
DString attribsStr
bool isEMailAddr
DString text
DString name
#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