Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
codeparser.cpp
Go to the documentation of this file.
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#include "codeparser.h"
5
6#include "config.h"
7#include "generator.h"
10#include "node.h"
11#include "qdocdatabase.h"
12
13#include <QtCore/qregularexpression.h>
14
16
17QList<CodeParser *> CodeParser::s_parsers;
18
19/*!
20 The constructor adds this code parser to the static
21 list of code parsers.
22 */
24{
26 s_parsers.prepend(this);
27}
28
29/*!
30 The destructor removes this code parser from the static
31 list of code parsers.
32 */
34{
35 s_parsers.removeAll(this);
36}
37
38/*!
39 Terminating a code parser is trivial.
40 */
42{
43 // nothing.
44}
45
46/*!
47 All the code parsers in the static list are initialized here,
48 after the qdoc configuration variables have been set.
49 */
51{
52 for (const auto &parser : std::as_const(s_parsers))
53 parser->initializeParser();
54}
55
56/*!
57 All the code parsers in the static list are terminated here.
58 */
60{
61 for (const auto parser : s_parsers)
62 parser->terminateParser();
63}
64
65CodeParser *CodeParser::parserForLanguage(const QString &language)
66{
67 for (const auto parser : std::as_const(s_parsers)) {
68 if (parser->language() == language)
69 return parser;
70 }
71 return nullptr;
72}
73
74CodeParser *CodeParser::parserForSourceFile(const QString &filePath)
75{
76 QString fileName = QFileInfo(filePath).fileName();
77
78 for (const auto &parser : s_parsers) {
79 const QStringList sourcePatterns = parser->sourceFileNameFilter();
80 for (const QString &pattern : sourcePatterns) {
81 auto re = QRegularExpression::fromWildcard(pattern, Qt::CaseInsensitive);
82 if (re.match(fileName).hasMatch())
83 return parser;
84 }
85 }
86 return nullptr;
87}
88
89/*!
90 \internal
91 */
92void CodeParser::extractPageLinkAndDesc(QStringView arg, QString *link, QString *desc)
93{
94 static const QRegularExpression bracedRegExp(
95 QRegularExpression::anchoredPattern(QLatin1String(R"(\{([^{}]*)\}(?:\{([^{}]*)\})?)")));
96 auto match = bracedRegExp.matchView(arg);
97 if (match.hasMatch()) {
98 *link = match.captured(1);
99 *desc = match.captured(2);
100 if (desc->isEmpty())
101 *desc = *link;
102 } else {
103 qsizetype spaceAt = arg.indexOf(QLatin1Char(' '));
104 if (arg.contains(QLatin1String(".html")) && spaceAt != -1) {
105 *link = arg.left(spaceAt).trimmed().toString();
106 *desc = arg.mid(spaceAt).trimmed().toString();
107 } else {
108 *link = arg.toString();
109 *desc = *link;
110 }
111 }
112}
113
114/*!
115 \internal
116 */
117void CodeParser::setLink(Node *node, Node::LinkType linkType, const QString &arg)
118{
119 QString link;
120 QString desc;
121 extractPageLinkAndDesc(arg, &link, &desc);
122 node->setLink(linkType, link, desc);
123}
124
125/*!
126 \brief Test for whether a doc comment warrants warnings.
127
128 Returns true if qdoc should report that it has found something
129 wrong with the qdoc comment in \a doc. Sometimes, qdoc should
130 not report the warning, for example, when the comment contains
131 the \c internal command, which normally means qdoc will not use
132 the comment in the documentation anyway, so there is no point
133 in reporting warnings about it.
134 */
136{
137 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
139 || !doc.metaCommandsUsed().contains(QStringLiteral("internal")));
140}
141
142QT_END_NAMESPACE
virtual void terminateParser()
Terminating a code parser is trivial.
CodeParser()
The constructor adds this code parser to the static list of code parsers.
QDocDatabase * m_qdb
Definition codeparser.h:139
static CodeParser * parserForLanguage(const QString &language)
static CodeParser * parserForSourceFile(const QString &filePath)
static bool isWorthWarningAbout(const Doc &doc)
Test for whether a doc comment warrants warnings.
virtual ~CodeParser()
The destructor removes this code parser from the static list of code parsers.
static void initialize()
All the code parsers in the static list are initialized here, after the qdoc configuration variables ...
static void terminate()
All the code parsers in the static list are terminated here.
Definition doc.h:31
static bool processInternalDocs(const InclusionPolicy &policy)
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
The Node class is the base class for all the nodes in QDoc's parse tree.