Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
d78e64db
Commit
d78e64db
authored
Jan 29, 2010
by
Roberto Raggi
Browse files
Fixed the highlihting of bindings and types.
parent
2dd5bebd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/libs/qmljs/qmljshighlighter.cpp
View file @
d78e64db
...
...
@@ -57,17 +57,28 @@ QScriptHighlighter::QScriptHighlighter(bool duiEnabled, QTextDocument *parent):
bool
QScriptHighlighter
::
isDuiEnabled
()
const
{
return
m_duiEnabled
;
}
static
bool
checkStartOfBinding
(
const
Token
&
token
)
{
switch
(
token
.
kind
)
{
case
Token
::
Semicolon
:
case
Token
::
LeftBrace
:
case
Token
::
RightBrace
:
case
Token
::
LeftBracket
:
case
Token
::
RightBracket
:
return
true
;
default:
return
false
;
}
// end of switch
}
void
QScriptHighlighter
::
highlightBlock
(
const
QString
&
text
)
{
const
QList
<
Token
>
tokens
=
m_scanner
(
text
,
onBlockStart
());
QTextCharFormat
emptyFormat
;
int
lastEnd
=
0
;
for
(
int
i
=
0
;
i
<
tokens
.
size
();
++
i
)
{
const
Token
token
=
tokens
.
at
(
i
);
if
(
token
.
offset
!=
lastEnd
)
setFormat
(
lastEnd
,
token
.
offset
-
lastEnd
,
m_formats
[
VisualWhitespace
]);
int
index
=
0
;
while
(
index
<
tokens
.
size
())
{
const
Token
&
token
=
tokens
.
at
(
index
);
switch
(
token
.
kind
)
{
case
Token
::
Keyword
:
...
...
@@ -110,43 +121,42 @@ void QScriptHighlighter::highlightBlock(const QString &text)
onClosingParenthesis
(
']'
,
token
.
offset
);
break
;
case
Token
::
Identifier
:
if
(
m_duiEnabled
&&
(
i
+
1
)
<
tokens
.
size
()
&&
tokens
.
at
(
i
+
1
).
is
(
Token
::
Colon
))
{
int
j
=
i
;
for
(;
j
!=
-
1
;
--
j
)
{
const
Token
&
tok
=
tokens
.
at
(
j
);
if
(
tok
.
is
(
Token
::
Dot
)
||
tok
.
is
(
Token
::
Identifier
))
{
setFormat
(
tok
.
offset
,
tok
.
length
,
m_formats
[
LabelFormat
]);
}
else
{
case
Token
::
Identifier
:
{
if
(
index
+
1
<
tokens
.
size
())
{
if
(
tokens
.
at
(
index
+
1
).
is
(
Token
::
LeftBrace
)
&&
text
.
at
(
token
.
offset
).
isUpper
())
{
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
TypeFormat
]);
}
else
if
(
index
==
0
||
checkStartOfBinding
(
tokens
.
at
(
index
-
1
)))
{
const
int
start
=
index
;
++
index
;
// skip the identifier.
while
(
index
+
1
<
tokens
.
size
()
&&
tokens
.
at
(
index
).
is
(
Token
::
Dot
)
&&
tokens
.
at
(
index
+
1
).
is
(
Token
::
Identifier
))
{
index
+=
2
;
}
if
(
index
<
tokens
.
size
()
&&
tokens
.
at
(
index
).
is
(
Token
::
Colon
))
{
// it's a binding.
for
(
int
i
=
start
;
i
<
index
;
++
i
)
{
const
Token
&
tok
=
tokens
.
at
(
i
);
setFormat
(
tok
.
offset
,
tok
.
length
,
m_formats
[
LabelFormat
]);
}
break
;
}
else
{
index
=
start
;
}
}
}
else
{
const
QChar
c
=
text
.
at
(
token
.
offset
);
if
((
m_duiEnabled
&&
c
.
isUpper
())
||
(
!
m_duiEnabled
&&
c
==
QLatin1Char
(
'Q'
)))
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
TypeFormat
]);
else
setFormat
(
token
.
offset
,
token
.
length
,
emptyFormat
);
}
break
;
case
Token
::
Colon
:
if
(
m_duiEnabled
&&
i
>
0
&&
tokens
.
at
(
i
-
1
).
kind
==
Token
::
Identifier
)
setFormat
(
token
.
offset
,
token
.
length
,
m_formats
[
LabelFormat
]);
else
setFormat
(
token
.
offset
,
token
.
length
,
emptyFormat
);
break
;
}
break
;
case
Token
::
Delimiter
:
setFormat
(
token
.
offset
,
token
.
length
,
emptyFormat
);
break
;
default:
break
;
}
}
// end swtich
lastEnd
=
token
.
end
()
;
++
index
;
}
int
firstNonSpace
=
0
;
...
...
@@ -156,11 +166,6 @@ void QScriptHighlighter::highlightBlock(const QString &text)
firstNonSpace
=
tk
.
offset
;
}
if
(
firstNonSpace
>
lastEnd
)
setFormat
(
lastEnd
,
firstNonSpace
-
lastEnd
,
m_formats
[
VisualWhitespace
]);
else
if
(
text
.
length
()
>
lastEnd
)
setFormat
(
lastEnd
,
text
.
length
()
-
lastEnd
,
m_formats
[
VisualWhitespace
]);
setCurrentBlockState
(
m_scanner
.
endState
());
onBlockEnd
(
m_scanner
.
endState
(),
firstNonSpace
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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