Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
922c607b
Commit
922c607b
authored
Jan 29, 2010
by
Roberto Raggi
Browse files
Highlight QML context types.
parent
913e2483
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/libs/qmljs/qmljshighlighter.cpp
View file @
922c607b
...
...
@@ -90,6 +90,14 @@ void QScriptHighlighter::highlightBlock(const QString &text)
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
KeywordFormat
]);
break
;
case
Token
::
String
:
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
StringFormat
]);
break
;
case
Token
::
Comment
:
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
CommentFormat
]);
break
;
case
Token
::
LeftParenthesis
:
onOpeningParenthesis
(
'('
,
token
.
offset
);
break
;
...
...
@@ -115,7 +123,9 @@ void QScriptHighlighter::highlightBlock(const QString &text)
break
;
case
Token
::
Identifier
:
{
if
(
m_duiEnabled
&&
maybeQmlKeyword
(
text
.
midRef
(
token
.
offset
,
token
.
length
)))
{
const
QStringRef
spell
=
text
.
midRef
(
token
.
offset
,
token
.
length
);
if
(
m_duiEnabled
&&
maybeQmlKeyword
(
spell
))
{
// check the previous token
if
(
index
==
0
||
tokens
.
at
(
index
-
1
).
isNot
(
Token
::
Dot
))
{
if
(
index
+
1
==
tokens
.
size
()
||
tokens
.
at
(
index
+
1
).
isNot
(
Token
::
Colon
))
{
...
...
@@ -123,6 +133,13 @@ void QScriptHighlighter::highlightBlock(const QString &text)
break
;
}
}
}
else
if
(
m_duiEnabled
&&
index
>
0
&&
maybeQmlBuiltinType
(
spell
))
{
const
Token
&
previousToken
=
tokens
.
at
(
index
-
1
);
if
(
previousToken
.
is
(
Token
::
Identifier
)
&&
text
.
at
(
previousToken
.
offset
)
==
QLatin1Char
(
'p'
)
&&
text
.
midRef
(
previousToken
.
offset
,
previousToken
.
length
)
==
QLatin1String
(
"property"
))
{
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
KeywordFormat
]);
break
;
}
}
if
(
index
+
1
<
tokens
.
size
())
{
...
...
@@ -247,3 +264,35 @@ bool QScriptHighlighter::maybeQmlKeyword(const QStringRef &text) const
return
false
;
}
}
bool
QScriptHighlighter
::
maybeQmlBuiltinType
(
const
QStringRef
&
text
)
const
{
if
(
text
.
isEmpty
())
return
false
;
const
QChar
ch
=
text
.
at
(
0
);
if
(
ch
==
QLatin1Char
(
'i'
)
&&
text
==
QLatin1String
(
"int"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'b'
)
&&
text
==
QLatin1String
(
"bool"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'd'
)
&&
text
==
QLatin1String
(
"double"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'r'
)
&&
text
==
QLatin1String
(
"real"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
's'
)
&&
text
==
QLatin1String
(
"string"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'u'
)
&&
text
==
QLatin1String
(
"url"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'c'
)
&&
text
==
QLatin1String
(
"color"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'd'
)
&&
text
==
QLatin1String
(
"date"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'v'
)
&&
text
==
QLatin1String
(
"var"
))
{
return
true
;
}
else
if
(
ch
==
QLatin1Char
(
'v'
)
&&
text
==
QLatin1String
(
"variant"
))
{
return
true
;
}
else
{
return
false
;
}
}
src/libs/qmljs/qmljshighlighter.h
View file @
922c607b
...
...
@@ -67,6 +67,7 @@ protected:
virtual
void
onClosingParenthesis
(
QChar
parenthesis
,
int
pos
);
bool
maybeQmlKeyword
(
const
QStringRef
&
text
)
const
;
bool
maybeQmlBuiltinType
(
const
QStringRef
&
text
)
const
;
protected:
QmlJSScanner
m_scanner
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment