6#include <QtCore/qregularexpression.h>
13#include <private/qqmljsast_p.h>
14#include <private/qqmljsastfwd_p.h>
15#include <private/qqmljsengine_p.h>
16#include <private/qqmljslexer_p.h>
17#include <private/qqmljsparser_p.h>
22
23
27 static const QRegularExpression regExp(QStringLiteral(
"^\\s*(import |([A-Z][a-z0-9]*)+\\s?{)"));
28 if (!regExp.match(code).hasMatch())
31 QQmlJS::Engine engine;
32 QQmlJS::Lexer lexer(&engine);
33 QQmlJS::Parser parser(&engine);
35 QString newCode = code;
36 extractPragmas(newCode);
37 lexer.setCode(newCode, 1);
39 return parser.parse();
43
44
45
52
53
54
57 return language ==
"QML";
61
62
71 return addMarkUp(code, relative, location);
75
76
77
78
81 QString name = linkTag(node, taggedNode(node));
90 QQmlJS::Engine engine;
91 QQmlJS::Lexer lexer(&engine);
93 QString newCode = code;
94 QList<QQmlJS::SourceLocation> pragmas = extractPragmas(newCode);
95 lexer.setCode(newCode, 1);
97 QQmlJS::Parser parser(&engine);
100 if (parser.parse()) {
101 QQmlJS::AST::UiProgram *ast = parser.ast();
105 QQmlJS::AST::Node::accept(ast, &visitor);
109 + QStringLiteral(
"Unable to analyze QML snippet. The output is incomplete."));
111 output = visitor.markedUpCode();
113 location.warning(QStringLiteral(
"Unable to parse QML snippet: \"%1\" at line %2, column %3")
114 .arg(parser.errorMessage())
115 .arg(parser.errorLineNumber())
116 .arg(parser.errorColumnNumber()));
117 output = protect(code);
124
125
126
130
131
132
133
134
135
136
139 QList<QQmlJS::SourceLocation> removed;
141 QQmlJS::Lexer l(
nullptr);
142 l.setCode(script, 0);
147 if (token != QQmlJSGrammar::T_DOT)
150 int startOffset = l.tokenOffset();
151 int startLine = l.tokenStartLine();
152 int startColumn = l.tokenStartColumn();
156 if (token != QQmlJSGrammar::T_PRAGMA && token != QQmlJSGrammar::T_IMPORT)
159 while (startLine == l.tokenStartLine()) {
160 endOffset = l.tokenLength() + l.tokenOffset();
163 replaceWithSpace(script, startOffset, endOffset - startOffset);
164 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.
bool isFunction(Genus g=DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.
LinkType
An unsigned char value that probably should be moved out of the Node base class.
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.