2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
#include "qmljshighlighter.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSet>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2010-01-18 14:12:04 +01:00
|
|
|
using namespace QmlJS;
|
2014-08-27 13:38:02 +02:00
|
|
|
using namespace TextEditor;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
namespace QmlJSEditor {
|
|
|
|
|
|
|
|
|
|
QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent)
|
|
|
|
|
: SyntaxHighlighter(parent),
|
2010-05-27 11:26:20 +02:00
|
|
|
m_qmlEnabled(true),
|
2013-08-13 12:57:31 +02:00
|
|
|
m_braceDepth(0),
|
|
|
|
|
m_foldingIndent(0),
|
2010-05-27 11:26:20 +02:00
|
|
|
m_inMultilineComment(false)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
|
|
|
|
m_currentBlockParentheses.reserve(20);
|
2017-05-05 20:34:29 +02:00
|
|
|
setDefaultTextFormatCategories();
|
2010-02-15 12:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-24 02:45:30 +01:00
|
|
|
QmlJSHighlighter::~QmlJSHighlighter() = default;
|
2009-09-28 14:49:39 +02:00
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
bool QmlJSHighlighter::isQmlEnabled() const
|
2010-01-29 11:20:42 +01:00
|
|
|
{
|
2010-02-15 12:27:25 +01:00
|
|
|
return m_qmlEnabled;
|
2010-01-29 11:20:42 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
void QmlJSHighlighter::setQmlEnabled(bool qmlEnabled)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
|
|
|
|
m_qmlEnabled = qmlEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
void QmlJSHighlighter::highlightBlock(const QString &text)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-28 13:12:52 +01:00
|
|
|
const QList<Token> tokens = m_scanner(text, onBlockStart());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-29 10:22:18 +01:00
|
|
|
int index = 0;
|
|
|
|
|
while (index < tokens.size()) {
|
|
|
|
|
const Token &token = tokens.at(index);
|
2009-10-07 16:31:08 +02:00
|
|
|
|
2009-09-28 14:49:39 +02:00
|
|
|
switch (token.kind) {
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::Keyword:
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-29 11:53:41 +01:00
|
|
|
case Token::String:
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_STRING));
|
2010-01-29 11:53:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Token::Comment:
|
2010-05-27 11:26:20 +02:00
|
|
|
if (m_inMultilineComment && text.midRef(token.end() - 2, 2) == QLatin1String("*/")) {
|
2012-11-26 21:17:34 +02:00
|
|
|
onClosingParenthesis(QLatin1Char('-'), token.end() - 1, index == tokens.size()-1);
|
2010-05-27 11:26:20 +02:00
|
|
|
m_inMultilineComment = false;
|
|
|
|
|
} else if (!m_inMultilineComment
|
2011-06-03 08:49:40 +02:00
|
|
|
&& (m_scanner.state() & Scanner::MultiLineMask) == Scanner::MultiLineComment
|
2010-05-27 11:26:20 +02:00
|
|
|
&& index == tokens.size() - 1) {
|
2012-11-26 21:17:34 +02:00
|
|
|
onOpeningParenthesis(QLatin1Char('+'), token.offset, index == 0);
|
2010-05-27 11:26:20 +02:00
|
|
|
m_inMultilineComment = true;
|
|
|
|
|
}
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_COMMENT));
|
2010-01-29 11:53:41 +01:00
|
|
|
break;
|
|
|
|
|
|
2011-05-20 14:48:05 +02:00
|
|
|
case Token::RegExp:
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_STRING));
|
2011-05-20 14:48:05 +02:00
|
|
|
break;
|
|
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::LeftParenthesis:
|
2012-11-26 21:17:34 +02:00
|
|
|
onOpeningParenthesis(QLatin1Char('('), token.offset, index == 0);
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:53:41 +02:00
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::RightParenthesis:
|
2012-11-26 21:17:34 +02:00
|
|
|
onClosingParenthesis(QLatin1Char(')'), token.offset, index == tokens.size()-1);
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:53:41 +02:00
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::LeftBrace:
|
2012-11-26 21:17:34 +02:00
|
|
|
onOpeningParenthesis(QLatin1Char('{'), token.offset, index == 0);
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:22:29 +02:00
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::RightBrace:
|
2012-11-26 21:17:34 +02:00
|
|
|
onClosingParenthesis(QLatin1Char('}'), token.offset, index == tokens.size()-1);
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:22:29 +02:00
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::LeftBracket:
|
2012-11-26 21:17:34 +02:00
|
|
|
onOpeningParenthesis(QLatin1Char('['), token.offset, index == 0);
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:22:29 +02:00
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::RightBracket:
|
2012-11-26 21:17:34 +02:00
|
|
|
onClosingParenthesis(QLatin1Char(']'), token.offset, index == tokens.size()-1);
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:22:29 +02:00
|
|
|
|
2010-01-29 10:22:18 +01:00
|
|
|
case Token::Identifier: {
|
2010-11-10 11:06:59 +01:00
|
|
|
if (!m_qmlEnabled)
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-29 11:53:41 +01:00
|
|
|
const QStringRef spell = text.midRef(token.offset, token.length);
|
|
|
|
|
|
2010-11-10 11:06:59 +01:00
|
|
|
if (maybeQmlKeyword(spell)) {
|
2010-01-29 11:20:42 +01:00
|
|
|
// 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)) {
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
2010-01-29 11:20:42 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-22 17:07:27 +02:00
|
|
|
if (text.midRef(token.offset, token.length) == QLatin1String("enum")) {
|
|
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-11-10 11:06:59 +01:00
|
|
|
} else if (index > 0 && maybeQmlBuiltinType(spell)) {
|
2010-01-29 11:53:41 +01:00
|
|
|
const Token &previousToken = tokens.at(index - 1);
|
2018-05-22 17:07:27 +02:00
|
|
|
if (previousToken.is(Token::Identifier)
|
|
|
|
|
&& text.at(previousToken.offset) == QLatin1Char('p')
|
|
|
|
|
&& text.midRef(previousToken.offset, previousToken.length)
|
|
|
|
|
== QLatin1String("property")) {
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
2010-01-29 11:53:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2018-05-22 17:07:27 +02:00
|
|
|
} else if (index == 1) {
|
|
|
|
|
const Token &previousToken = tokens.at(0);
|
|
|
|
|
if (previousToken.is(Token::Identifier)
|
|
|
|
|
&& text.at(previousToken.offset) == QLatin1Char('e')
|
|
|
|
|
&& text.midRef(previousToken.offset, previousToken.length)
|
|
|
|
|
== QLatin1String("enum")) {
|
|
|
|
|
setFormat(token.offset, token.length, formatForCategory(C_ENUMERATION));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-01-29 11:20:42 +01:00
|
|
|
}
|
2010-01-29 10:22:18 +01:00
|
|
|
} break;
|
2009-10-07 16:31:08 +02:00
|
|
|
|
2010-01-28 13:12:52 +01:00
|
|
|
case Token::Delimiter:
|
2009-09-28 14:49:39 +02:00
|
|
|
break;
|
2009-05-11 11:53:41 +02:00
|
|
|
|
2009-10-07 16:31:08 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2010-01-29 10:22:18 +01:00
|
|
|
} // end swtich
|
2009-10-07 16:31:08 +02:00
|
|
|
|
2010-01-29 10:22:18 +01:00
|
|
|
++index;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-29 10:26:33 +01:00
|
|
|
int previousTokenEnd = 0;
|
2018-11-24 02:45:30 +01:00
|
|
|
for (const auto &token : tokens) {
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(previousTokenEnd, token.begin() - previousTokenEnd, formatForCategory(C_VISUAL_WHITESPACE));
|
2010-01-29 10:32:00 +01:00
|
|
|
|
|
|
|
|
switch (token.kind) {
|
|
|
|
|
case Token::Comment:
|
2011-05-20 14:48:05 +02:00
|
|
|
case Token::String:
|
|
|
|
|
case Token::RegExp: {
|
2010-01-29 10:32:00 +01:00
|
|
|
int i = token.begin(), e = token.end();
|
|
|
|
|
while (i < e) {
|
|
|
|
|
const QChar ch = text.at(i);
|
|
|
|
|
if (ch.isSpace()) {
|
|
|
|
|
const int start = i;
|
|
|
|
|
do {
|
|
|
|
|
++i;
|
|
|
|
|
} while (i < e && text.at(i).isSpace());
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(start, i - start, formatForCategory(C_VISUAL_WHITESPACE));
|
2010-01-29 10:32:00 +01:00
|
|
|
} else {
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
} // end of switch
|
|
|
|
|
|
2010-01-29 10:26:33 +01:00
|
|
|
previousTokenEnd = token.end();
|
|
|
|
|
}
|
2010-01-28 13:12:52 +01:00
|
|
|
|
2017-05-05 20:34:29 +02:00
|
|
|
setFormat(previousTokenEnd, text.length() - previousTokenEnd, formatForCategory(C_VISUAL_WHITESPACE));
|
2010-01-29 10:50:16 +01:00
|
|
|
|
2010-01-29 11:20:42 +01:00
|
|
|
setCurrentBlockState(m_scanner.state());
|
2010-05-20 15:10:26 +02:00
|
|
|
onBlockEnd(m_scanner.state());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
2009-10-08 14:57:18 +02:00
|
|
|
{
|
2010-01-29 11:20:42 +01:00
|
|
|
if (text.isEmpty())
|
|
|
|
|
return false;
|
2009-10-08 14:57:18 +02:00
|
|
|
|
2010-01-29 11:20:42 +01:00
|
|
|
const QChar ch = text.at(0);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (ch == QLatin1Char('p') && text == QLatin1String("property"))
|
2010-01-29 11:20:42 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('a') && text == QLatin1String("alias"))
|
2010-01-29 11:20:42 +01:00
|
|
|
return true;
|
2020-04-08 09:26:13 +02:00
|
|
|
else if (ch == QLatin1Char('c') && text == QLatin1String("component"))
|
|
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('s') && text == QLatin1String("signal"))
|
2010-01-29 11:20:42 +01:00
|
|
|
return true;
|
2020-04-08 09:26:13 +02:00
|
|
|
else if (ch == QLatin1Char('r') && (text == QLatin1String("readonly") || text == QLatin1String("required")))
|
2010-01-29 11:20:42 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('i') && text == QLatin1String("import"))
|
2010-01-29 11:23:06 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('o') && text == QLatin1String("on"))
|
2010-04-07 08:49:09 +02:00
|
|
|
return true;
|
2018-05-22 17:07:27 +02:00
|
|
|
else if (ch == QLatin1Char('e') && text == QLatin1String("enum"))
|
|
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-01-29 11:20:42 +01:00
|
|
|
return false;
|
2009-10-08 14:57:18 +02:00
|
|
|
}
|
2010-01-29 11:53:41 +01:00
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
2010-01-29 11:53:41 +01:00
|
|
|
{
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QChar ch = text.at(0);
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (ch == QLatin1Char('a') && text == QLatin1String("action"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('b') && text == QLatin1String("bool"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('c') && text == QLatin1String("color"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('d') && text == QLatin1String("date"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('d') && text == QLatin1String("double"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('e') && text == QLatin1String("enumeration"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('f') && text == QLatin1String("font"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('i') && text == QLatin1String("int"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('l') && text == QLatin1String("list"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
2013-08-20 18:15:05 +02:00
|
|
|
else if (ch == QLatin1Char('m') && text == QLatin1String("matrix4x4"))
|
|
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('p') && text == QLatin1String("point"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
2013-08-20 18:15:05 +02:00
|
|
|
else if (ch == QLatin1Char('q') && text == QLatin1String("quaternion"))
|
|
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('r') && text == QLatin1String("real"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('r') && text == QLatin1String("rect"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('s') && text == QLatin1String("size"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('s') && text == QLatin1String("string"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('t') && text == QLatin1String("time"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('u') && text == QLatin1String("url"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('v') && text == QLatin1String("variant"))
|
2010-01-29 11:53:41 +01:00
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('v') && text == QLatin1String("var"))
|
2011-10-06 09:53:08 +02:00
|
|
|
return true;
|
2013-08-20 18:15:05 +02:00
|
|
|
else if (ch == QLatin1Char('v') && text == QLatin1String("vector2d"))
|
|
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (ch == QLatin1Char('v') && text == QLatin1String("vector3d"))
|
2011-09-19 13:16:05 +02:00
|
|
|
return true;
|
2013-08-20 18:15:05 +02:00
|
|
|
else if (ch == QLatin1Char('v') && text == QLatin1String("vector4d"))
|
|
|
|
|
return true;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-01-29 11:53:41 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
int QmlJSHighlighter::onBlockStart()
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
|
|
|
|
m_currentBlockParentheses.clear();
|
|
|
|
|
m_braceDepth = 0;
|
2010-05-20 15:10:26 +02:00
|
|
|
m_foldingIndent = 0;
|
2010-05-27 14:46:30 +02:00
|
|
|
m_inMultilineComment = false;
|
2019-12-04 08:19:53 +01:00
|
|
|
if (TextBlockUserData *userData = TextDocumentLayout::textUserData(currentBlock())) {
|
2010-05-20 15:10:26 +02:00
|
|
|
userData->setFoldingIndent(0);
|
|
|
|
|
userData->setFoldingStartIncluded(false);
|
|
|
|
|
userData->setFoldingEndIncluded(false);
|
|
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
|
|
|
|
|
int state = 0;
|
|
|
|
|
int previousState = previousBlockState();
|
|
|
|
|
if (previousState != -1) {
|
|
|
|
|
state = previousState & 0xff;
|
2010-06-15 14:34:18 +02:00
|
|
|
m_braceDepth = (previousState >> 8);
|
2011-06-03 08:49:40 +02:00
|
|
|
m_inMultilineComment = ((state & Scanner::MultiLineMask) == Scanner::MultiLineComment);
|
2010-02-15 12:27:25 +01:00
|
|
|
}
|
2010-05-20 15:10:26 +02:00
|
|
|
m_foldingIndent = m_braceDepth;
|
2010-02-15 12:27:25 +01:00
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
void QmlJSHighlighter::onBlockEnd(int state)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
2010-06-15 14:28:36 +02:00
|
|
|
setCurrentBlockState((m_braceDepth << 8) | state);
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout::setParentheses(currentBlock(), m_currentBlockParentheses);
|
|
|
|
|
TextDocumentLayout::setFoldingIndent(currentBlock(), m_foldingIndent);
|
2010-02-15 12:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
void QmlJSHighlighter::onOpeningParenthesis(QChar parenthesis, int pos, bool atStart)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
2010-05-27 11:26:20 +02:00
|
|
|
if (parenthesis == QLatin1Char('{') || parenthesis == QLatin1Char('[') || parenthesis == QLatin1Char('+')) {
|
2010-02-15 12:27:25 +01:00
|
|
|
++m_braceDepth;
|
2010-05-20 15:10:26 +02:00
|
|
|
// if a folding block opens at the beginning of a line, treat the entire line
|
|
|
|
|
// as if it were inside the folding block
|
|
|
|
|
if (atStart)
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true);
|
2010-05-20 15:10:26 +02:00
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
void QmlJSHighlighter::onClosingParenthesis(QChar parenthesis, int pos, bool atEnd)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
2010-05-27 11:26:20 +02:00
|
|
|
if (parenthesis == QLatin1Char('}') || parenthesis == QLatin1Char(']') || parenthesis == QLatin1Char('-')) {
|
2010-02-15 12:27:25 +01:00
|
|
|
--m_braceDepth;
|
2010-05-20 15:10:26 +02:00
|
|
|
if (atEnd)
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true);
|
2010-05-20 15:10:26 +02:00
|
|
|
else
|
|
|
|
|
m_foldingIndent = qMin(m_braceDepth, m_foldingIndent); // folding indent is the minimum brace depth of a block
|
|
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Closed, parenthesis, pos));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 13:38:02 +02:00
|
|
|
} // namespace QmlJSEditor
|