forked from qt-creator/qt-creator
Introduced QmlJSScanner::scanComments/setScanComments(onoff).
This commit is contained in:
@@ -77,7 +77,8 @@ const _Tp *end(const _Tp (&a)[N])
|
|||||||
}
|
}
|
||||||
|
|
||||||
QmlJSScanner::QmlJSScanner()
|
QmlJSScanner::QmlJSScanner()
|
||||||
: m_state(0)
|
: _state(0),
|
||||||
|
_scanComments(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +86,16 @@ QmlJSScanner::~QmlJSScanner()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QmlJSScanner::scanComments() const
|
||||||
|
{
|
||||||
|
return _scanComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlJSScanner::setScanComments(bool scanComments)
|
||||||
|
{
|
||||||
|
_scanComments = scanComments;
|
||||||
|
}
|
||||||
|
|
||||||
static bool isIdentifierChar(QChar ch)
|
static bool isIdentifierChar(QChar ch)
|
||||||
{
|
{
|
||||||
switch (ch.unicode()) {
|
switch (ch.unicode()) {
|
||||||
@@ -116,14 +127,14 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
|
|||||||
MultiLineComment = 1
|
MultiLineComment = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
m_state = startState;
|
_state = startState;
|
||||||
QList<Token> tokens;
|
QList<Token> tokens;
|
||||||
|
|
||||||
// ### handle multi line comment state.
|
// ### handle multi line comment state.
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
if (m_state == MultiLineComment) {
|
if (_state == MultiLineComment) {
|
||||||
const int start = index;
|
const int start = index;
|
||||||
while (index < text.length()) {
|
while (index < text.length()) {
|
||||||
const QChar ch = text.at(index);
|
const QChar ch = text.at(index);
|
||||||
@@ -132,7 +143,7 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
|
|||||||
la = text.at(index + 1);
|
la = text.at(index + 1);
|
||||||
|
|
||||||
if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
|
if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
|
||||||
m_state = Normal;
|
_state = Normal;
|
||||||
index += 2;
|
index += 2;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -140,7 +151,8 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens.append(Token(start, index - start, Token::Comment));
|
if (_scanComments)
|
||||||
|
tokens.append(Token(start, index - start, Token::Comment));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (index < text.length()) {
|
while (index < text.length()) {
|
||||||
@@ -153,12 +165,13 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
|
|||||||
switch (ch.unicode()) {
|
switch (ch.unicode()) {
|
||||||
case '/':
|
case '/':
|
||||||
if (la == QLatin1Char('/')) {
|
if (la == QLatin1Char('/')) {
|
||||||
tokens.append(Token(index, text.length() - index, Token::Comment));
|
if (_scanComments)
|
||||||
|
tokens.append(Token(index, text.length() - index, Token::Comment));
|
||||||
index = text.length();
|
index = text.length();
|
||||||
} else if (la == QLatin1Char('*')) {
|
} else if (la == QLatin1Char('*')) {
|
||||||
const int start = index;
|
const int start = index;
|
||||||
index += 2;
|
index += 2;
|
||||||
m_state = MultiLineComment;
|
_state = MultiLineComment;
|
||||||
while (index < text.length()) {
|
while (index < text.length()) {
|
||||||
const QChar ch = text.at(index);
|
const QChar ch = text.at(index);
|
||||||
QChar la;
|
QChar la;
|
||||||
@@ -166,14 +179,15 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
|
|||||||
la = text.at(index + 1);
|
la = text.at(index + 1);
|
||||||
|
|
||||||
if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
|
if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
|
||||||
m_state = Normal;
|
_state = Normal;
|
||||||
index += 2;
|
index += 2;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tokens.append(Token(start, index - start, Token::Comment));
|
if (_scanComments)
|
||||||
|
tokens.append(Token(start, index - start, Token::Comment));
|
||||||
} else {
|
} else {
|
||||||
tokens.append(Token(index++, 1, Token::Delimiter));
|
tokens.append(Token(index++, 1, Token::Delimiter));
|
||||||
}
|
}
|
||||||
@@ -285,7 +299,7 @@ QList<Token> QmlJSScanner::operator()(const QString &text, int startState)
|
|||||||
|
|
||||||
int QmlJSScanner::state() const
|
int QmlJSScanner::state() const
|
||||||
{
|
{
|
||||||
return m_state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJSScanner::isKeyword(const QString &text) const
|
bool QmlJSScanner::isKeyword(const QString &text) const
|
||||||
|
|||||||
@@ -80,13 +80,17 @@ public:
|
|||||||
QmlJSScanner();
|
QmlJSScanner();
|
||||||
virtual ~QmlJSScanner();
|
virtual ~QmlJSScanner();
|
||||||
|
|
||||||
|
bool scanComments() const;
|
||||||
|
void setScanComments(bool scanComments);
|
||||||
|
|
||||||
QList<Token> operator()(const QString &text, int startState = 0);
|
QList<Token> operator()(const QString &text, int startState = 0);
|
||||||
int state() const;
|
int state() const;
|
||||||
|
|
||||||
bool isKeyword(const QString &text) const;
|
bool isKeyword(const QString &text) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_state;
|
int _state;
|
||||||
|
bool _scanComments: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlJS
|
} // namespace QmlJS
|
||||||
|
|||||||
Reference in New Issue
Block a user