Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmljslexer_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 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
// Qt-Security score:significant
4
5
#
ifndef
QQMLJSLEXER_P_H
6
#
define
QQMLJSLEXER_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
private
/
qqmljsglobal_p
.
h
>
20
#
include
<
private
/
qqmljsgrammar_p
.
h
>
21
22
#
include
<
QtCore
/
qstring
.
h
>
23
#
include
<
QtCore
/
qstack
.
h
>
24
25
QT_BEGIN_NAMESPACE
26
27
class
QDebug;
28
29
namespace
QQmlJS
{
30
31
class
Engine
;
32
struct
DiagnosticMessage
;
33
class
Directives;
34
35
class
QML_PARSER_EXPORT
Lexer
:
public
QQmlJSGrammar
36
{
37
public
:
38
enum
Error
{
39
NoError
,
40
IllegalCharacter
,
41
IllegalNumber
,
42
UnclosedStringLiteral
,
43
IllegalEscapeSequence
,
44
IllegalUnicodeEscapeSequence
,
45
UnclosedComment
,
46
IllegalExponentIndicator
,
47
IllegalIdentifier
,
48
IllegalHexadecimalEscapeSequence
49
};
50
51
enum
RegExpBodyPrefix
{
52
NoPrefix
,
53
EqualPrefix
54
};
55
56
enum
RegExpFlag
{
57
RegExp_Global
= 0x01,
58
RegExp_IgnoreCase
= 0x02,
59
RegExp_Multiline
= 0x04,
60
RegExp_Unicode
= 0x08,
61
RegExp_Sticky
= 0x10
62
};
63
64
enum
ParseModeFlags
{
65
QmlMode
= 0x1,
66
YieldIsKeyword
= 0x2,
67
StaticIsKeyword
= 0x4
68
};
69
70
enum
class
ImportState
{
71
SawImport
,
72
NoQmlImport
73
};
74
75
enum
class
LexMode
{
WholeCode
,
LineByLine
};
76
77
enum
class
CodeContinuation
{
Reset
,
Continue
};
78
79
public
:
80
Lexer
(
Engine
*
engine
,
LexMode
lexMode
=
LexMode
::
WholeCode
);
81
82
bool
qmlMode
()
const
;
83
bool
yieldIsKeyWord
()
const
{
return
_state
.
generatorLevel
!= 0; }
84
void
setStaticIsKeyword
(
bool
b
) {
_staticIsKeyword
=
b
; }
85
86
QString
code
()
const
;
87
void
setCode
(
const
QString
&
code
,
int
lineno
,
bool
qmlMode
=
true
,
88
CodeContinuation
codeContinuation
=
CodeContinuation
::
Reset
);
89
90
int
lex
();
91
92
bool
scanRegExp
(
RegExpBodyPrefix
prefix
=
NoPrefix
);
93
bool
scanDirectives
(
Directives
*
directives
,
DiagnosticMessage
*
error
);
94
95
int
regExpFlags
()
const
{
return
_state
.
patternFlags
; }
96
QString
regExpPattern
()
const
{
return
_tokenText
; }
97
98
int
tokenKind
()
const
{
return
_state
.
tokenKind
; }
99
int
tokenOffset
()
const
{
return
_currentOffset
+
_tokenStartPtr
-
_code
.
unicode
(); }
100
int
tokenLength
()
const
{
return
_tokenLength
; }
101
102
int
tokenStartLine
()
const
{
return
_tokenLine
; }
103
int
tokenStartColumn
()
const
{
return
_tokenColumn
; }
104
105
inline
QStringView
tokenSpell
()
const
{
return
_tokenSpell
; }
106
inline
QStringView
rawString
()
const
{
return
_rawString
; }
107
double
tokenValue
()
const
{
return
_state
.
tokenValue
; }
108
QString
tokenText
()
const
;
109
110
Error
errorCode
()
const
;
111
QString
errorMessage
()
const
;
112
113
std
::
optional
<
DiagnosticMessage
>
illegalFileLengthError
()
const
;
114
115
bool
canInsertAutomaticSemicolon
(
int
token
)
const
;
116
117
enum
ParenthesesState
{
118
IgnoreParentheses
,
119
CountParentheses
,
120
BalancedParentheses
121
};
122
123
enum
class
CommentState
{
NoComment
,
HadComment
,
InMultilineComment
};
124
125
void
enterGeneratorBody
() { ++
_state
.
generatorLevel
; }
126
void
leaveGeneratorBody
() { --
_state
.
generatorLevel
; }
127
128
struct
State
129
{
130
Error
errorCode
=
NoError
;
131
132
QChar
currentChar
= u'\n';
133
double
tokenValue
= 0;
134
135
// parentheses state
136
ParenthesesState
parenthesesState
=
IgnoreParentheses
;
137
int
parenthesesCount
= 0;
138
139
// template string stack
140
QStack
<
int
>
outerTemplateBraceCount
;
141
int
bracesCount
= -1;
142
143
int
stackToken
= -1;
144
145
int
patternFlags
= 0;
146
int
tokenKind
= 0;
147
ImportState
importState
=
ImportState
::
NoQmlImport
;
148
149
bool
validTokenText
=
false
;
150
bool
prohibitAutomaticSemicolon
=
false
;
151
bool
restrictedKeyword
=
false
;
152
bool
terminator
=
false
;
153
bool
followsClosingBrace
=
false
;
154
bool
delimited
=
true
;
155
bool
handlingDirectives
=
false
;
156
CommentState
comments
=
CommentState
::
NoComment
;
157
int
generatorLevel
= 0;
158
159
friend
bool
operator
==(
State
const
&
s1
,
State
const
&
s2
)
160
{
161
if
(
s1
.
errorCode
!=
s2
.
errorCode
)
162
return
false
;
163
if
(
s1
.
currentChar
!=
s2
.
currentChar
)
164
return
false
;
165
if
(
s1
.
tokenValue
!=
s2
.
tokenValue
)
166
return
false
;
167
if
(
s1
.
parenthesesState
!=
s2
.
parenthesesState
)
168
return
false
;
169
if
(
s1
.
parenthesesCount
!=
s2
.
parenthesesCount
)
170
return
false
;
171
if
(
s1
.
outerTemplateBraceCount
!=
s2
.
outerTemplateBraceCount
)
172
return
false
;
173
if
(
s1
.
bracesCount
!=
s2
.
bracesCount
)
174
return
false
;
175
if
(
s1
.
stackToken
!=
s2
.
stackToken
)
176
return
false
;
177
if
(
s1
.
patternFlags
!=
s2
.
patternFlags
)
178
return
false
;
179
if
(
s1
.
tokenKind
!=
s2
.
tokenKind
)
180
return
false
;
181
if
(
s1
.
importState
!=
s2
.
importState
)
182
return
false
;
183
if
(
s1
.
validTokenText
!=
s2
.
validTokenText
)
184
return
false
;
185
if
(
s1
.
prohibitAutomaticSemicolon
!=
s2
.
prohibitAutomaticSemicolon
)
186
return
false
;
187
if
(
s1
.
restrictedKeyword
!=
s2
.
restrictedKeyword
)
188
return
false
;
189
if
(
s1
.
terminator
!=
s2
.
terminator
)
190
return
false
;
191
if
(
s1
.
followsClosingBrace
!=
s2
.
followsClosingBrace
)
192
return
false
;
193
if
(
s1
.
delimited
!=
s2
.
delimited
)
194
return
false
;
195
if
(
s1
.
handlingDirectives
!=
s2
.
handlingDirectives
)
196
return
false
;
197
if
(
s1
.
generatorLevel
!=
s2
.
generatorLevel
)
198
return
false
;
199
return
true
;
200
}
201
202
friend
bool
operator
!=(
State
const
&
s1
,
State
const
&
s2
) {
return
!(
s1
==
s2
); }
203
204
friend
QML_PARSER_EXPORT
QDebug
operator
<<(
QDebug
dbg
,
State
const
&
s
);
205
};
206
207
const
State
&
state
()
const
;
208
void
setState
(
const
State
&
state
);
209
210
protected
:
211
static
int
classify
(
QStringView
s
,
int
parseModeFlags
);
212
213
private
:
214
int
parseModeFlags
()
const
;
215
bool
prevTerminator
()
const
;
216
bool
followsClosingBrace
()
const
;
217
inline
void
scanChar
();
218
inline
QChar
peekChar
();
219
int
scanToken
();
220
int
scanNumber
(
QChar
ch
);
221
int
scanVersionNumber
(
QChar
ch
);
222
enum
ScanStringMode
:
char16_t
{
223
SingleQuote
=
'\''
,
224
DoubleQuote
=
'"'
,
225
TemplateHead
=
'`'
,
226
TemplateContinuation
= 0
227
};
228
int
scanString
(
ScanStringMode
mode
);
229
230
bool
isLineTerminator
()
const
;
231
unsigned
isLineTerminatorSequence
()
const
;
232
static
bool
isIdentLetter
(
QChar
c
);
233
static
bool
isDecimalDigit
(
ushort
c
);
234
static
bool
isHexDigit
(
QChar
c
);
235
static
bool
isOctalDigit
(
ushort
c
);
236
237
void
syncProhibitAutomaticSemicolon
();
238
uint
decodeUnicodeEscapeCharacter
(
bool
*
ok
);
239
QChar
decodeHexEscapeCharacter
(
bool
*
ok
);
240
241
friend
QML_PARSER_EXPORT
QDebug
operator
<<(
QDebug
dbg
,
const
Lexer
&
l
);
242
243
private
:
244
Engine
*
_engine
;
245
246
LexMode
_lexMode
=
LexMode
::
WholeCode
;
247
QString
_code
;
248
const
QChar
*
_endPtr
;
249
bool
_qmlMode
;
250
bool
_staticIsKeyword
=
false
;
251
252
bool
_skipLinefeed
=
false
;
253
254
int
_currentLineNumber
= 0;
255
int
_currentColumnNumber
= 0;
256
int
_currentOffset
= 0;
257
258
int
_tokenLength
= 0;
259
int
_tokenLine
= 0;
260
int
_tokenColumn
= 0;
261
262
QString
_tokenText
;
263
QString
_errorMessage
;
264
QStringView
_tokenSpell
;
265
QStringView
_rawString
;
266
267
const
QChar
*
_codePtr
=
nullptr
;
268
const
QChar
*
_tokenStartPtr
=
nullptr
;
269
270
State
_state
;
271
};
272
273
}
// end of namespace QQmlJS
274
275
QT_END_NAMESPACE
276
277
#
endif
// LEXER_H
QQmlJS::Engine
Definition
qqmljsengine_p.h:61
QQmlJS::Lexer
Definition
qqmljslexer_p.h:36
QQmlJS
Definition
qv4bytecodegenerator_p.h:27
regExpFlagFromChar
static int regExpFlagFromChar(const QChar &ch)
Definition
qqmljslexer.cpp:25
isIdentifierPart
static bool isIdentifierPart(uint ch)
Definition
qqmljslexer.cpp:518
convertHex
static QChar convertHex(QChar c1, QChar c2)
Definition
qqmljslexer.cpp:47
uriTokens
static const int uriTokens[]
Definition
qqmljslexer.cpp:1607
isUriToken
static bool isUriToken(int token)
Definition
qqmljslexer.cpp:1661
convertHex
static unsigned char convertHex(ushort c)
Definition
qqmljslexer.cpp:37
isIdentifierStart
static bool isIdentifierStart(uint ch)
Definition
qqmljslexer.cpp:496
QQmlJS::DiagnosticMessage
Definition
qqmljsdiagnosticmessage_p.h:71
qtdeclarative
src
qml
parser
qqmljslexer_p.h
Generated on
for Qt by
1.18.0