1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef ATOM_H
5#define ATOM_H
6
7#include "genustypes.h"
8#include "location.h"
9
10#include <QtCore/qdebug.h>
11#include <QtCore/qstringlist.h>
12
13QT_BEGIN_NAMESPACE
14
15class Tree;
16class LinkAtom;
17
18class Atom
19{
20public:
21 enum AtomType {
22 AnnotatedList,
23 AutoLink,
24 BaseName,
25 BR,
26 BriefLeft,
27 BriefRight,
28 C,
29 CaptionLeft,
30 CaptionRight,
31 Code,
32 CodeBad,
33 CodeQuoteArgument,
34 CodeQuoteCommand,
35 ComparesLeft,
36 ComparesRight,
37 DetailsLeft,
38 DetailsRight,
39 DivLeft,
40 DivRight,
41 ExampleFileLink,
42 ExampleImageLink,
43 FootnoteLeft,
44 FootnoteRight,
45 FormatElse,
46 FormatEndif,
47 FormatIf,
48 FormattingLeft,
49 FormattingRight,
50 GeneratedList,
51 HR,
52 Image,
53 ImageText,
54 ImportantLeft,
55 ImportantRight,
56 InlineImage,
57 Keyword,
58 LegaleseLeft,
59 LegaleseRight,
60 LineBreak,
61 Link,
62 LinkNode,
63 ListLeft,
64 ListItemNumber,
65 ListTagLeft,
66 ListTagRight,
67 ListItemLeft,
68 ListItemRight,
69 ListRight,
70 NavAutoLink,
71 NavLink,
72 Nop,
73 NoteLeft,
74 NoteRight,
75 ParaLeft,
76 ParaRight,
77 Qml,
78 QuotationLeft,
79 QuotationRight,
80 RawString,
81 SectionLeft,
82 SectionRight,
83 SectionHeadingLeft,
84 SectionHeadingRight,
85 SidebarLeft,
86 SidebarRight,
87 SinceList,
88 SinceTagLeft,
89 SinceTagRight,
90 SnippetCommand,
91 SnippetIdentifier,
92 SnippetLocation,
93 String,
94 TableLeft,
95 TableRight,
96 TableHeaderLeft,
97 TableHeaderRight,
98 TableRowLeft,
99 TableRowRight,
100 TableItemLeft,
101 TableItemRight,
102 TableOfContents,
103 Target,
104 UnhandledFormat,
105 WarningLeft,
106 WarningRight,
107 UnknownCommand,
108 Last = UnknownCommand
109 };
110
111 friend class LinkAtom;
112
113 explicit Atom(AtomType type, const QString &string = "") : m_type(type), m_strs(string) { }
114
115 Atom(AtomType type, const QString &p1, const QString &p2) : m_type(type), m_strs(p1)
116 {
117 if (!p2.isEmpty())
118 m_strs << p2;
119 }
120
121 Atom(Atom *previous, AtomType type, const QString &string)
122 : m_next(previous->m_next), m_type(type), m_strs(string)
123 {
124 previous->m_next = this;
125 }
126
127 Atom(Atom *previous, AtomType type, const QString &p1, const QString &p2)
128 : m_next(previous->m_next), m_type(type), m_strs(p1)
129 {
130 if (!p2.isEmpty())
131 m_strs << p2;
132 previous->m_next = this;
133 }
134
135 virtual ~Atom() = default;
136
137 void appendChar(QChar ch) { m_strs[0] += ch; }
138 void concatenateString(const QString &string) { m_strs[0] += string; }
139 void append(const QString &string) { m_strs << string; }
140 void chopString() { m_strs[0].chop(n: 1); }
141 void setString(const QString &string) { m_strs[0] = string; }
142 Atom *next() { return m_next; }
143 void setNext(Atom *newNext) { m_next = newNext; }
144
145 [[nodiscard]] const Atom *find(AtomType t) const;
146 [[nodiscard]] const Atom *find(AtomType t, const QString &s) const;
147 [[nodiscard]] const Atom *next() const { return m_next; }
148 [[nodiscard]] const Atom *next(AtomType t) const;
149 [[nodiscard]] const Atom *next(AtomType t, const QString &s) const;
150 [[nodiscard]] AtomType type() const { return m_type; }
151 [[nodiscard]] QString typeString() const;
152 [[nodiscard]] const QString &string() const { return m_strs[0]; }
153 [[nodiscard]] const QString &string(int i) const { return m_strs[i]; }
154 [[nodiscard]] qsizetype count() const { return m_strs.size(); }
155 [[nodiscard]] QString linkText() const;
156 [[nodiscard]] const QStringList &strings() const { return m_strs; }
157
158 [[nodiscard]] virtual bool isLinkAtom() const { return false; }
159 virtual Genus genus() { return Genus::DontCare; }
160 virtual Tree *domain() { return nullptr; }
161 virtual void resolveSquareBracketParams() {}
162
163protected:
164 Atom *m_next = nullptr;
165 AtomType m_type {};
166 QStringList m_strs {};
167};
168
169class LinkAtom : public Atom
170{
171public:
172 LinkAtom(const QString &p1, const QString &p2, Location location = Location());
173 LinkAtom(const LinkAtom &t);
174 LinkAtom(Atom *previous, const LinkAtom &t);
175 ~LinkAtom() override = default;
176
177 [[nodiscard]] bool isLinkAtom() const override { return true; }
178 Genus genus() override
179 {
180 resolveSquareBracketParams();
181 return m_genus;
182 }
183 Tree *domain() override
184 {
185 resolveSquareBracketParams();
186 return m_domain;
187 }
188 void resolveSquareBracketParams() override;
189
190public:
191 Location location;
192
193protected:
194 bool m_resolved {};
195 Genus m_genus {};
196 Tree *m_domain {};
197 QString m_squareBracketParams {};
198};
199
200#define ATOM_FORMATTING_BOLD "bold"
201#define ATOM_FORMATTING_INDEX "index"
202#define ATOM_FORMATTING_ITALIC "italic"
203#define ATOM_FORMATTING_LINK "link"
204#define ATOM_FORMATTING_NOTRANSLATE "notranslate"
205#define ATOM_FORMATTING_PARAMETER "parameter"
206#define ATOM_FORMATTING_SPAN "span "
207#define ATOM_FORMATTING_SUBSCRIPT "subscript"
208#define ATOM_FORMATTING_SUPERSCRIPT "superscript"
209#define ATOM_FORMATTING_TELETYPE "teletype"
210#define ATOM_FORMATTING_TRADEMARK "trademark"
211#define ATOM_FORMATTING_UICONTROL "uicontrol"
212#define ATOM_FORMATTING_UNDERLINE "underline"
213
214#define ATOM_LIST_BULLET "bullet"
215#define ATOM_LIST_TAG "tag"
216#define ATOM_LIST_VALUE "value"
217#define ATOM_LIST_LOWERALPHA "loweralpha"
218#define ATOM_LIST_LOWERROMAN "lowerroman"
219#define ATOM_LIST_NUMERIC "numeric"
220#define ATOM_LIST_UPPERALPHA "upperalpha"
221#define ATOM_LIST_UPPERROMAN "upperroman"
222
223QT_END_NAMESPACE
224
225#endif
226

source code of qttools/src/qdoc/qdoc/src/qdoc/atom.h