6#include <QtCore/qregularexpression.h>
14#include <private/qqmljsast_p.h>
15#include <private/qqmljsastfwd_p.h>
16#include <private/qqmljsengine_p.h>
17#include <private/qqmljslexer_p.h>
18#include <private/qqmljsparser_p.h>
23
24
28 static const QRegularExpression regExp(QStringLiteral(
"^\\s*(import |([A-Z][a-z0-9]*)+\\s?{)"));
29 if (!regExp.match(code).hasMatch())
32 QQmlJS::Engine engine;
33 QQmlJS::Lexer lexer(&engine);
34 QQmlJS::Parser parser(&engine);
36 QString newCode = code;
37 extractPragmas(newCode);
38 lexer.setCode(newCode, 1);
40 return parser.parse();
44
45
46
53
54
55
58 return language ==
"qml";
62
63
72 return addMarkUp(code, relative, location);
76
77
78
79
82 QString name = linkTag(node, taggedNode(node));
91 if (code.trimmed().isEmpty()) {
92 qCDebug(lcQdoc,
"QML markup requested for empty code at %ls",
93 qUtf16Printable(location.toString()));
97 QQmlJS::Engine engine;
98 QQmlJS::Lexer lexer(&engine);
100 QString newCode = code;
101 QList<QQmlJS::SourceLocation> pragmas = extractPragmas(newCode);
102 lexer.setCode(newCode, 1);
104 QQmlJS::Parser parser(&engine);
107 if (parser.parse()) {
108 QQmlJS::AST::UiProgram *ast = parser.ast();
112 QQmlJS::AST::Node::accept(ast, &visitor);
116 + QStringLiteral(
"Unable to analyze QML snippet. The output is incomplete."));
118 output = visitor.markedUpCode();
120 location.warning(QStringLiteral(
"Unable to parse QML snippet: \"%1\" at line %2, column %3")
121 .arg(parser.errorMessage())
122 .arg(parser.errorLineNumber())
123 .arg(parser.errorColumnNumber()));
124 output = protect(code);
131
132
133
137
138
139
140
141
142
143
146 QList<QQmlJS::SourceLocation> removed;
148 QQmlJS::Lexer l(
nullptr);
149 l.setCode(script, 0);
154 if (token != QQmlJSGrammar::T_DOT)
157 int startOffset = l.tokenOffset();
158 int startLine = l.tokenStartLine();
159 int startColumn = l.tokenStartColumn();
163 if (token != QQmlJSGrammar::T_PRAGMA && token != QQmlJSGrammar::T_IMPORT)
166 while (startLine == l.tokenStartLine()) {
167 endOffset = l.tokenLength() + l.tokenOffset();
170 replaceWithSpace(script, startOffset, endOffset - startOffset);
171 removed.append(QQmlJS::SourceLocation(startOffset, endOffset - startOffset, startLine,
The Atom class is the fundamental unit for representing documents internally.
AtomType
\value AnnotatedList \value AutoLink \value BaseName \value BriefLeft \value BriefRight \value C \val...
The Location class provides a way to mark a location in a file.
QString markedUpName(const Node *node) override
Constructs and returns the marked up name for the node.
Atom::AtomType atomType() const override
Returns the type of atom used to represent QML code in the documentation.
Combined button and popup list for selecting options.
void replaceWithSpace(QString &str, int idx, int n)
Copy and paste from src/declarative/qml/qdeclarativescriptparser.cpp.
The Node class is the base class for all the nodes in QDoc's parse tree.
bool isFunction(Genus g=Genus::DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.