Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
18798383
"src/plugins/qnx/blackberrydebugtokenuploader.h" did not exist on "3fa55b7ab9b1d6ae10fac1c9bcc653e9000157f8"
Commit
18798383
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Use the QML/JS incremental scanner in the indenter.
parent
f3b738bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shared/qscripthighlighter/qscriptindenter.cpp
+64
-83
64 additions, 83 deletions
src/shared/qscripthighlighter/qscriptindenter.cpp
src/shared/qscripthighlighter/qscriptindenter.h
+3
-4
3 additions, 4 deletions
src/shared/qscripthighlighter/qscriptindenter.h
with
67 additions
and
87 deletions
src/shared/qscripthighlighter/qscriptindenter.cpp
+
64
−
83
View file @
18798383
...
@@ -66,6 +66,7 @@
...
@@ -66,6 +66,7 @@
*/
*/
#include
"qscriptindenter.h"
#include
"qscriptindenter.h"
#include
"qscriptincrementalscanner.h"
#include
<QtDebug>
#include
<QtDebug>
using
namespace
SharedTools
;
using
namespace
SharedTools
;
...
@@ -82,12 +83,9 @@ const int QScriptIndenter::SmallRoof = 40;
...
@@ -82,12 +83,9 @@ const int QScriptIndenter::SmallRoof = 40;
const
int
QScriptIndenter
::
BigRoof
=
400
;
const
int
QScriptIndenter
::
BigRoof
=
400
;
QScriptIndenter
::
QScriptIndenter
()
QScriptIndenter
::
QScriptIndenter
()
:
literal
(
QRegExp
(
QLatin1String
(
"([
\"
'])(?:
\\\\
.|[^
\\\\
])*
\\
1"
))),
:
label
(
QRegExp
(
QLatin1String
(
"^
\\
s*((?:case
\\
b([^:])+|[a-zA-Z_0-9.]+)(?:
\\
s+)?:)(?!:)"
))),
label
(
QRegExp
(
QLatin1String
(
"^
\\
s*((?:case
\\
b([^:])+|[a-zA-Z_0-9.]+)(?:
\\
s+)?:)(?!:)"
))),
inlineCComment
(
QRegExp
(
QLatin1String
(
"/
\\
*.*
\\
*/"
))),
braceX
(
QRegExp
(
QLatin1String
(
"^
\\
s*
\\
}
\\
s*(?:else|catch)
\\
b"
))),
braceX
(
QRegExp
(
QLatin1String
(
"^
\\
s*
\\
}
\\
s*(?:else|catch)
\\
b"
))),
iflikeKeyword
(
QRegExp
(
QLatin1String
(
"
\\
b(?:catch|do|for|if|while|with)
\\
b"
))),
iflikeKeyword
(
QRegExp
(
QLatin1String
(
"
\\
b(?:catch|do|for|if|while|with)
\\
b"
)))
propertylikeKeyword
(
QRegExp
(
QLatin1String
(
"^
\\
s*
\\
b(?:property|signal|import|readonly|return)
\\
b"
)))
{
{
/*
/*
...
@@ -120,9 +118,6 @@ QScriptIndenter::QScriptIndenter()
...
@@ -120,9 +118,6 @@ QScriptIndenter::QScriptIndenter()
yyLine
=
0
;
yyLine
=
0
;
yyBraceDepth
=
0
;
yyBraceDepth
=
0
;
yyLeftBraceFollows
=
0
;
yyLeftBraceFollows
=
0
;
literal
.
setMinimal
(
true
);
inlineCComment
.
setMinimal
(
true
);
}
}
QScriptIndenter
::~
QScriptIndenter
()
QScriptIndenter
::~
QScriptIndenter
()
...
@@ -209,98 +204,84 @@ void QScriptIndenter::eraseChar(QString &t, int k, QChar ch) const
...
@@ -209,98 +204,84 @@ void QScriptIndenter::eraseChar(QString &t, int k, QChar ch) const
Removes some nefast constructs from a code line and returns the
Removes some nefast constructs from a code line and returns the
resulting line.
resulting line.
*/
*/
QString
QScriptIndenter
::
trimmedCodeLine
(
const
QString
&
t
)
const
QString
QScriptIndenter
::
trimmedCodeLine
(
const
QString
&
t
)
{
{
QString
trimmed
=
t
;
QScriptIncrementalScanner
scanner
;
int
k
;
/*
int
state
=
yyLinizerState
.
iter
.
userState
();
Replace character and string literals by X's, since they may
if
(
state
==
-
1
)
contain confusing characters (such as '{' and ';'). "Hello!" is
state
=
0
;
replaced by XXXXXXXX. The literals are rigourously of the same
state
=
state
&
0xff
;
length before and after; otherwise, we would break alignment of
continuation lines.
*/
k
=
0
;
while
((
k
=
literal
.
indexIn
(
trimmed
,
k
))
!=
-
1
)
{
for
(
int
i
=
0
;
i
<
literal
.
matchedLength
();
i
++
)
eraseChar
(
trimmed
,
k
+
i
,
QLatin1Char
(
'X'
));
k
+=
literal
.
matchedLength
();
}
/*
yyLinizerState
.
tokens
=
scanner
(
t
,
state
);
Replace inline C-style comments by spaces. Other comments are
QString
trimmed
;
handled elsewhere.
int
previousTokenEnd
=
0
;
*/
foreach
(
const
QScriptIncrementalScanner
::
Token
&
token
,
yyLinizerState
.
tokens
)
{
k
=
0
;
trimmed
.
append
(
t
.
midRef
(
previousTokenEnd
,
token
.
begin
()
-
previousTokenEnd
));
while
((
k
=
inlineCComment
.
indexIn
(
trimmed
,
k
))
!=
-
1
)
{
for
(
int
i
=
0
;
i
<
inlineCComment
.
matchedLength
();
i
++
)
eraseChar
(
trimmed
,
k
+
i
,
QLatin1Char
(
' '
));
k
+=
inlineCComment
.
matchedLength
();
}
/*
if
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
String
))
{
Replace goto and switch labels by whitespace, but be careful
for
(
int
i
=
0
;
i
<
token
.
length
;
++
i
)
with this case:
trimmed
.
append
(
QLatin1Char
(
'X'
));
foo1: bar1;
}
else
if
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
))
{
bar2;
for
(
int
i
=
0
;
i
<
token
.
length
;
++
i
)
*/
trimmed
.
append
(
QLatin1Char
(
' '
));
bool
insertSemicolon
=
fa
lse
;
}
e
lse
{
while
(
trimmed
.
lastIndexOf
(
QLatin1Char
(
':'
))
!=
-
1
&&
label
.
indexIn
(
trimmed
)
!=
-
1
)
{
trimmed
.
append
(
t
.
midRef
(
token
.
offset
,
token
.
length
));
insertSemicolon
=
true
;
}
const
QString
cap1
=
label
.
cap
(
1
);
previousTokenEnd
=
token
.
end
();
int
pos1
=
label
.
pos
(
1
);
}
int
stop
=
cap1
.
length
();
if
(
pos1
+
stop
<
trimmed
.
length
()
&&
ppIndentSize
<
stop
)
int
index
=
yyLinizerState
.
tokens
.
size
()
-
1
;
stop
=
ppIndentSize
;
for
(;
index
!=
-
1
;
--
index
)
{
const
QScriptIncrementalScanner
::
Token
&
token
=
yyLinizerState
.
tokens
.
at
(
index
);
if
(
token
.
isNot
(
QScriptIncrementalScanner
::
Token
::
Comment
))
break
;
}
int
i
=
0
;
bool
isBinding
=
false
;
while
(
i
<
stop
)
{
foreach
(
const
QScriptIncrementalScanner
::
Token
&
token
,
yyLinizerState
.
tokens
)
{
eraseChar
(
trimmed
,
pos1
+
i
,
QLatin1Char
(
';'
));
if
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Colon
))
{
i
++
;
isBinding
=
true
;
}
break
;
while
(
i
<
cap1
.
length
())
{
eraseChar
(
trimmed
,
pos1
+
i
,
QLatin1Char
(
';'
));
i
++
;
}
}
}
}
/*
if
(
index
!=
-
1
)
{
Remove C++-style comments.
const
QScriptIncrementalScanner
::
Token
&
last
=
yyLinizerState
.
tokens
.
at
(
index
);
*/
k
=
trimmed
.
indexOf
(
QRegExp
(
QLatin1String
(
"
\\
s*//"
)));
switch
(
last
.
kind
)
{
if
(
k
!=
-
1
)
case
QScriptIncrementalScanner
::
Token
::
LeftParenthesis
:
trimmed
.
truncate
(
k
);
case
QScriptIncrementalScanner
::
Token
::
LeftBrace
:
case
QScriptIncrementalScanner
::
Token
::
Semicolon
:
if
(
!
insertSemicolon
&&
!
trimmed
.
isEmpty
())
{
case
QScriptIncrementalScanner
::
Token
::
Operator
:
const
QChar
ch
=
trimmed
.
at
(
trimmed
.
length
()
-
1
);
switch
(
ch
.
unicode
())
{
case
','
:
case
']'
:
case
'"'
:
case
'\''
:
case
'_'
:
insertSemicolon
=
true
;
break
;
break
;
default:
case
QScriptIncrementalScanner
::
Token
::
RightParenthesis
:
if
(
ch
.
isLetterOrNumber
())
{
case
QScriptIncrementalScanner
::
Token
::
RightBrace
:
if
(
!
trimmed
.
endsWith
(
QLatin1String
(
"else"
)))
if
(
isBinding
)
insertSemicolon
=
true
;
trimmed
.
append
(
QLatin1Char
(
';'
));
}
else
if
(
trimmed
.
indexOf
(
propertylikeKeyword
)
!=
-
1
)
break
;
insertSemicolon
=
true
;
case
QScriptIncrementalScanner
::
Token
::
Colon
:
case
QScriptIncrementalScanner
::
Token
::
LeftBracket
:
case
QScriptIncrementalScanner
::
Token
::
RightBracket
:
trimmed
.
append
(
QLatin1Char
(
';'
));
break
;
case
QScriptIncrementalScanner
::
Token
::
Identifier
:
case
QScriptIncrementalScanner
::
Token
::
Keyword
:
if
(
t
.
midRef
(
last
.
offset
,
last
.
length
)
!=
QLatin1String
(
"else"
))
trimmed
.
append
(
QLatin1Char
(
';'
));
break
;
break
;
}
}
if
(
insertSemicolon
)
default:
trimmed
.
append
(
QLatin1Char
(
';'
));
trimmed
.
append
(
QLatin1Char
(
';'
));
break
;
}
// end of switch
}
return
trimmed
;
return
trimmed
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/shared/qscripthighlighter/qscriptindenter.h
+
3
−
4
View file @
18798383
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#ifndef QTSCRIPTINDENTER_H
#ifndef QTSCRIPTINDENTER_H
#define QTSCRIPTINDENTER_H
#define QTSCRIPTINDENTER_H
#include
<qscripthighlighter/qscriptincrementalscanner.h>
#include
<QtCore/QRegExp>
#include
<QtCore/QRegExp>
#include
<QtCore/QStringList>
#include
<QtCore/QStringList>
#include
<QtGui/QTextBlock>
#include
<QtGui/QTextBlock>
...
@@ -57,7 +58,7 @@ private:
...
@@ -57,7 +58,7 @@ private:
bool
isOnlyWhiteSpace
(
const
QString
&
t
)
const
;
bool
isOnlyWhiteSpace
(
const
QString
&
t
)
const
;
int
columnForIndex
(
const
QString
&
t
,
int
index
)
const
;
int
columnForIndex
(
const
QString
&
t
,
int
index
)
const
;
int
indentOfLine
(
const
QString
&
t
)
const
;
int
indentOfLine
(
const
QString
&
t
)
const
;
QString
trimmedCodeLine
(
const
QString
&
t
)
const
;
QString
trimmedCodeLine
(
const
QString
&
t
);
void
eraseChar
(
QString
&
t
,
int
k
,
QChar
ch
)
const
;
void
eraseChar
(
QString
&
t
,
int
k
,
QChar
ch
)
const
;
QChar
lastParen
(
const
QString
&
t
)
const
;
QChar
lastParen
(
const
QString
&
t
)
const
;
...
@@ -102,6 +103,7 @@ private:
...
@@ -102,6 +103,7 @@ private:
bool
inComment
;
bool
inComment
;
bool
pendingRightBrace
;
bool
pendingRightBrace
;
QString
line
;
QString
line
;
QList
<
QScriptIncrementalScanner
::
Token
>
tokens
;
QTextBlock
iter
;
QTextBlock
iter
;
};
};
...
@@ -127,12 +129,9 @@ private:
...
@@ -127,12 +129,9 @@ private:
const
int
*
yyBraceDepth
;
const
int
*
yyBraceDepth
;
const
bool
*
yyLeftBraceFollows
;
const
bool
*
yyLeftBraceFollows
;
QRegExp
literal
;
QRegExp
label
;
QRegExp
label
;
QRegExp
inlineCComment
;
QRegExp
braceX
;
QRegExp
braceX
;
QRegExp
iflikeKeyword
;
QRegExp
iflikeKeyword
;
QRegExp
propertylikeKeyword
;
};
};
}
// namespace SharedTools
}
// namespace SharedTools
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment