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
Marco Bubke
flatpak-qt-creator
Commits
1c3410d3
Commit
1c3410d3
authored
Jan 15, 2010
by
Roberto Raggi
Browse files
Simplified the handling of QML/JS comments
parent
ed1414a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/shared/qscripthighlighter/qscriptindenter.cpp
View file @
1c3410d3
...
...
@@ -222,28 +222,9 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t)
trimmed
.
append
(
QLatin1Char
(
'X'
));
}
else
if
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
))
{
int
i
=
0
;
int
e
=
token
.
length
;
if
(
token
.
offset
>
0
||
startState
==
0
)
{
if
(
token
.
length
>=
2
&&
t
.
midRef
(
token
.
offset
,
2
)
==
QLatin1String
(
"/*"
))
{
trimmed
.
append
(
QLatin1String
(
"/*"
));
i
+=
2
;
}
}
bool
needEndOfComment
=
false
;
if
(
e
>
2
&&
token
.
end
()
==
t
.
length
()
&&
scanner
.
endState
()
!=
0
)
{
needEndOfComment
=
true
;
e
-=
2
;
}
for
(;
i
<
e
;
++
i
)
for
(
int
i
=
0
;
i
<
token
.
length
;
++
i
)
trimmed
.
append
(
QLatin1Char
(
' '
));
if
(
needEndOfComment
)
trimmed
.
append
(
QLatin1String
(
"*/"
));
}
else
{
trimmed
.
append
(
t
.
midRef
(
token
.
offset
,
token
.
length
));
}
...
...
@@ -357,39 +338,6 @@ bool QScriptIndenter::readLine()
yyLinizerState
.
line
=
trimmedCodeLine
(
yyLinizerState
.
line
);
/*
Remove C-style comments that span multiple lines. If the
bottom line starts in a C-style comment, we are not aware
of that and eventually yyLine will contain a slash-aster.
Notice that both if's can be executed, since
yyLinizerState.inCComment is potentially set to false in
the first if. The order of the if's is also important.
*/
if
(
yyLinizerState
.
inComment
)
{
const
QLatin1String
slashAster
(
"/*"
);
k
=
yyLinizerState
.
line
.
indexOf
(
slashAster
);
if
(
k
==
-
1
)
{
yyLinizerState
.
line
.
clear
();
}
else
{
yyLinizerState
.
line
.
truncate
(
k
);
yyLinizerState
.
inComment
=
false
;
}
}
if
(
!
yyLinizerState
.
inComment
)
{
const
QLatin1String
asterSlash
(
"*/"
);
k
=
yyLinizerState
.
line
.
indexOf
(
asterSlash
);
if
(
k
!=
-
1
)
{
for
(
int
i
=
0
;
i
<
k
+
2
;
i
++
)
eraseChar
(
yyLinizerState
.
line
,
i
,
QLatin1Char
(
' '
));
yyLinizerState
.
inComment
=
true
;
}
}
/*
Remove preprocessor directives.
*/
...
...
@@ -449,7 +397,6 @@ bool QScriptIndenter::readLine()
void
QScriptIndenter
::
startLinizer
()
{
yyLinizerState
.
braceDepth
=
0
;
yyLinizerState
.
inComment
=
false
;
yyLinizerState
.
pendingRightBrace
=
false
;
yyLine
=
&
yyLinizerState
.
line
;
...
...
@@ -499,30 +446,7 @@ int QScriptIndenter::indentWhenBottomLineStartsInMultiLineComment()
break
;
}
const
QString
codeLine
=
trimmedCodeLine
(
blockText
);
int
k
=
codeLine
.
lastIndexOf
(
QLatin1String
(
"/*"
));
if
(
k
==
-
1
)
{
/*
We found a normal text line in a comment. Align the
bottom line with the text on this line.
*/
return
indentOfLine
(
codeLine
);
}
else
{
/*
The C-style comment starts on this line. If there is
text on the same line, align with it. Otherwise, align
with the slash-aster plus a given offset.
*/
int
indent
=
columnForIndex
(
codeLine
,
k
);
k
+=
2
;
while
(
k
<
yyLine
->
length
())
{
if
(
!
codeLine
.
at
(
k
).
isSpace
())
return
columnForIndex
(
codeLine
,
k
);
k
++
;
}
return
indent
+
ppCommentOffset
;
}
return
indentOfLine
(
blockText
);
}
/*
...
...
src/shared/qscripthighlighter/qscriptindenter.h
View file @
1c3410d3
...
...
@@ -94,13 +94,11 @@ private:
LinizerState
()
:
braceDepth
(
0
),
leftBraceFollows
(
false
),
inComment
(
false
),
pendingRightBrace
(
false
)
{
}
int
braceDepth
;
bool
leftBraceFollows
;
bool
inComment
;
bool
pendingRightBrace
;
QString
line
;
QList
<
QScriptIncrementalScanner
::
Token
>
tokens
;
...
...
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