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
qqmldomscanner_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLDOMSCANNER_P_H
5#define QQMLDOMSCANNER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmldom_global.h"
20
21#include <QStringList>
22#include <QStringView>
23#include <QtQml/private/qqmljslexer_p.h>
24#include <QtQml/private/qqmljsgrammar_p.h>
25
27
28namespace QQmlJS {
29namespace Dom {
30
32{
34public:
35 static bool lexKindIsDelimiter(int kind);
36 static bool lexKindIsJSKeyword(int kind);
37 static bool lexKindIsIdentifier(int kind);
38 static bool lexKindIsStringType(int kind);
39 static bool lexKindIsInvalid(int kind);
40 static bool lexKindIsQmlReserved(int kind);
41 static bool lexKindIsComment(int kind);
42
43 inline Token() = default;
44 inline Token(int o, int l, int lexKind) : offset(o), length(l), lexKind(lexKind) { }
45 inline int begin() const { return offset; }
46 inline int end() const { return offset + length; }
47 void dump(const Sink &s, QStringView line = QStringView()) const;
48 QString toString(QStringView line = QStringView()) const
49 {
50 return dumperToString([line, this](const Sink &s) { this->dump(s, line); });
51 }
52
53 static int compare(const Token &t1, const Token &t2)
54 {
55 if (int c = t1.offset - t2.offset)
56 return c;
57 if (int c = t1.length - t2.length)
58 return c;
59 return int(t1.lexKind) - int(t2.lexKind);
60 }
61
62 int offset = 0;
63 int length = 0;
65};
66
67inline int operator==(const Token &t1, const Token &t2)
68{
69 return Token::compare(t1, t2) == 0;
70}
71inline int operator!=(const Token &t1, const Token &t2)
72{
73 return Token::compare(t1, t2) != 0;
74}
75
77{
78public:
80 {
82 bool regexpMightFollow = true;
83 bool isMultiline() const;
84 bool isMultilineComment() const;
85 };
86
87 QList<Token> operator()(QStringView text, const State &startState);
88 State state() const;
89
90private:
91 bool _qmlMode = true;
92 State _state;
93};
94
95} // namespace Dom
96} // namespace QQmlJS
97QT_END_NAMESPACE
98#endif
const Token & tokenAt(int idx) const
QStringView tokenText(const Token &token) const
FormatPartialStatus(const FormatPartialStatus &o)=default
FormatPartialStatus & operator=(const FormatPartialStatus &o)=default
void enterState(FormatTextStatus::StateType newState)
bool tryInsideExpression(bool alsoExpression)
void defaultOnEnter(FormatTextStatus::StateType newState, int *indentDepth, int *savedIndentDepth) const
void turnIntoState(FormatTextStatus::StateType newState)
FormatPartialStatus(QStringView line, const FormatOptions &options, const FormatTextStatus &initialStatus)
bool operator==(const State &other) const
static bool isBracelessState(StateType type)
static FormatTextStatus initialStatus(int baseIndent=0)
void pushState(StateType type, quint16 savedIndentDepth)
State state(int belowTop=0) const
static bool isExpressionEndState(StateType type)
QList< Token > operator()(QStringView text, const State &startState)
QString toString(QStringView line=QStringView()) const
void dump(const Sink &s, QStringView line=QStringView()) const
static bool lexKindIsIdentifier(int kind)
static bool lexKindIsQmlReserved(int kind)
static bool lexKindIsComment(int kind)
static bool lexKindIsJSKeyword(int kind)
Token(int o, int l, int lexKind)
static bool lexKindIsStringType(int kind)
static int compare(const Token &t1, const Token &t2)
static bool lexKindIsInvalid(int kind)
FormatPartialStatus formatCodeLine(QStringView line, const FormatOptions &options, const FormatTextStatus &initialStatus)
int operator==(const Token &t1, const Token &t2)
int indentForLineStartingWithToken(const FormatTextStatus &oldStatus, const FormatOptions &, int tokenKind)
FormatTextStatus::State State
int operator!=(const Token &t1, const Token &t2)
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
#define QMLDOM_EXPORT