2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
|
|
|
|
|
#include <QtCore/QSet>
|
|
|
|
|
#include <QtCore/QtAlgorithms>
|
2010-01-28 13:12:52 +01:00
|
|
|
#include <QtCore/QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
using namespace QmlJSEditor;
|
2010-01-18 14:12:04 +01:00
|
|
|
using namespace QmlJS;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
Highlighter::Highlighter(QTextDocument *parent)
|
|
|
|
|
: QSyntaxHighlighter(parent),
|
2010-05-27 11:26:20 +02:00
|
|
|
m_qmlEnabled(true),
|
|
|
|
|
m_inMultilineComment(false)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
|
|
|
|
m_currentBlockParentheses.reserve(20);
|
|
|
|
|
m_braceDepth = 0;
|
2010-05-20 15:10:26 +02:00
|
|
|
m_foldingIndent = 0;
|
2010-02-15 12:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Highlighter::~Highlighter()
|
2009-09-28 14:49:39 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
bool Highlighter::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
|
|
|
}
|
|
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
void Highlighter::setQmlEnabled(bool qmlEnabled)
|
|
|
|
|
{
|
|
|
|
|
m_qmlEnabled = qmlEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextCharFormat Highlighter::labelTextCharFormat() const
|
2010-01-29 11:20:42 +01:00
|
|
|
{
|
|
|
|
|
return m_formats[LabelFormat];
|
|
|
|
|
}
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-29 10:22:18 +01:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
void Highlighter::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:
|
2009-09-28 14:49:39 +02:00
|
|
|
setFormat(token.offset, token.length, m_formats[KeywordFormat]);
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-29 11:53:41 +01:00
|
|
|
case Token::String:
|
|
|
|
|
setFormat(token.offset, token.length, m_formats[StringFormat]);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Token::Comment:
|
2010-05-27 11:26:20 +02:00
|
|
|
if (m_inMultilineComment && text.midRef(token.end() - 2, 2) == QLatin1String("*/")) {
|
|
|
|
|
onClosingParenthesis('-', token.end() - 1, index == tokens.size()-1);
|
|
|
|
|
m_inMultilineComment = false;
|
|
|
|
|
} else if (!m_inMultilineComment
|
|
|
|
|
&& m_scanner.state() == Scanner::MultiLineComment
|
|
|
|
|
&& index == tokens.size() - 1) {
|
|
|
|
|
onOpeningParenthesis('+', token.offset, index == 0);
|
|
|
|
|
m_inMultilineComment = true;
|
|
|
|
|
}
|
2010-01-29 11:53:41 +01:00
|
|
|
setFormat(token.offset, token.length, m_formats[CommentFormat]);
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
case Token::LeftParenthesis:
|
2010-05-20 15:10:26 +02:00
|
|
|
onOpeningParenthesis('(', 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:
|
2010-05-20 15:10:26 +02:00
|
|
|
onClosingParenthesis(')', 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:
|
2010-05-20 15:10:26 +02:00
|
|
|
onOpeningParenthesis('{', 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:
|
2010-05-20 15:10:26 +02:00
|
|
|
onClosingParenthesis('}', 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:
|
2010-05-20 15:10:26 +02:00
|
|
|
onOpeningParenthesis('[', 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:
|
2010-05-20 15:10:26 +02:00
|
|
|
onClosingParenthesis(']', 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-01-29 11:53:41 +01:00
|
|
|
const QStringRef spell = text.midRef(token.offset, token.length);
|
|
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
if (m_qmlEnabled && 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)) {
|
|
|
|
|
setFormat(token.offset, token.length, m_formats[KeywordFormat]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
} else if (m_qmlEnabled && index > 0 && maybeQmlBuiltinType(spell)) {
|
2010-01-29 11:53:41 +01:00
|
|
|
const Token &previousToken = tokens.at(index - 1);
|
|
|
|
|
if (previousToken.is(Token::Identifier) && text.at(previousToken.offset) == QLatin1Char('p')
|
|
|
|
|
&& text.midRef(previousToken.offset, previousToken.length) == QLatin1String("property")) {
|
|
|
|
|
setFormat(token.offset, token.length, m_formats[KeywordFormat]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-01-29 11:20:42 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-29 10:22:18 +01:00
|
|
|
if (index + 1 < tokens.size()) {
|
2010-04-07 08:49:09 +02:00
|
|
|
const Token &nextToken = tokens.at(index + 1);
|
2010-04-07 11:29:56 +02:00
|
|
|
|
|
|
|
|
bool maybeBinding = (index == 0 || checkStartOfBinding(tokens.at(index - 1)));
|
|
|
|
|
bool maybeOnBinding = false;
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
const Token &previousToken = tokens.at(index - 1);
|
|
|
|
|
if (text.midRef(previousToken.offset, previousToken.length) == QLatin1String("on")) {
|
|
|
|
|
maybeOnBinding = true;
|
|
|
|
|
maybeBinding = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-07 08:49:09 +02:00
|
|
|
if (text.at(token.offset).isUpper()
|
|
|
|
|
&& (nextToken.is(Token::LeftBrace)
|
|
|
|
|
|| text.midRef(nextToken.offset, nextToken.length) == QLatin1String("on"))) {
|
2010-01-29 10:22:18 +01:00
|
|
|
setFormat(token.offset, token.length, m_formats[TypeFormat]);
|
2010-04-07 11:29:56 +02:00
|
|
|
} else if (maybeBinding || maybeOnBinding) {
|
|
|
|
|
Token::Kind expectedTerminator = Token::Colon;
|
|
|
|
|
if (maybeOnBinding)
|
|
|
|
|
expectedTerminator = Token::LeftBrace;
|
|
|
|
|
|
2010-01-29 10:22:18 +01:00
|
|
|
const int start = index;
|
|
|
|
|
|
2010-04-15 15:35:52 +02:00
|
|
|
// put index on last identifier not followed by .identifier
|
|
|
|
|
while (index + 2 < tokens.size() &&
|
|
|
|
|
tokens.at(index + 1).is(Token::Dot) &&
|
|
|
|
|
tokens.at(index + 2).is(Token::Identifier)) {
|
2010-01-29 10:22:18 +01:00
|
|
|
index += 2;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-15 15:35:52 +02:00
|
|
|
if (index + 1 < tokens.size() && tokens.at(index + 1).is(expectedTerminator)) {
|
2010-01-29 10:22:18 +01:00
|
|
|
// it's a binding.
|
2010-04-15 15:35:52 +02:00
|
|
|
for (int i = start; i <= index; ++i) {
|
2010-01-29 10:22:18 +01:00
|
|
|
const Token &tok = tokens.at(i);
|
|
|
|
|
setFormat(tok.offset, tok.length, m_formats[LabelFormat]);
|
|
|
|
|
}
|
2010-01-14 16:48:06 +01:00
|
|
|
break;
|
2010-01-29 10:22:18 +01:00
|
|
|
} else {
|
|
|
|
|
index = start;
|
2010-01-14 16:48:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2009-10-07 16:31:08 +02: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;
|
2010-01-29 10:32:00 +01:00
|
|
|
for (int index = 0; index < tokens.size(); ++index) {
|
|
|
|
|
const Token &token = tokens.at(index);
|
2010-01-29 10:26:33 +01:00
|
|
|
setFormat(previousTokenEnd, token.begin() - previousTokenEnd, m_formats[VisualWhitespace]);
|
2010-01-29 10:32:00 +01:00
|
|
|
|
|
|
|
|
switch (token.kind) {
|
|
|
|
|
case Token::Comment:
|
|
|
|
|
case Token::String: {
|
|
|
|
|
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());
|
|
|
|
|
setFormat(start, i - start, m_formats[VisualWhitespace]);
|
|
|
|
|
} 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
|
|
|
|
2010-01-29 10:50:16 +01:00
|
|
|
setFormat(previousTokenEnd, text.length() - previousTokenEnd, m_formats[VisualWhitespace]);
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
bool Highlighter::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);
|
|
|
|
|
if (ch == QLatin1Char('p') && text == QLatin1String("property")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('a') && text == QLatin1String("alias")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('s') && text == QLatin1String("signal")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('p') && text == QLatin1String("property")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('r') && text == QLatin1String("readonly")) {
|
|
|
|
|
return true;
|
2010-01-29 11:23:06 +01:00
|
|
|
} else if (ch == QLatin1Char('i') && text == QLatin1String("import")) {
|
|
|
|
|
return true;
|
2010-04-07 08:49:09 +02:00
|
|
|
} else if (ch == QLatin1Char('o') && text == QLatin1String("on")) {
|
|
|
|
|
return true;
|
2010-01-29 11:20:42 +01:00
|
|
|
} else {
|
|
|
|
|
return false;
|
2009-10-08 14:57:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-29 11:53:41 +01:00
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
2010-01-29 11:53:41 +01:00
|
|
|
{
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QChar ch = text.at(0);
|
|
|
|
|
|
|
|
|
|
if (ch == QLatin1Char('i') && text == QLatin1String("int")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('b') && text == QLatin1String("bool")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('d') && text == QLatin1String("double")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('r') && text == QLatin1String("real")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('s') && text == QLatin1String("string")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('u') && text == QLatin1String("url")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('c') && text == QLatin1String("color")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('d') && text == QLatin1String("date")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('v') && text == QLatin1String("var")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ch == QLatin1Char('v') && text == QLatin1String("variant")) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
|
|
|
|
|
int Highlighter::onBlockStart()
|
|
|
|
|
{
|
|
|
|
|
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;
|
2010-05-20 15:10:26 +02:00
|
|
|
if (TextEditor::TextBlockUserData *userData = TextEditor::BaseTextDocumentLayout::testUserData(currentBlock())) {
|
|
|
|
|
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-05-27 14:46:30 +02:00
|
|
|
m_inMultilineComment = (previousState >> 8) & 0xff;
|
|
|
|
|
m_braceDepth = previousState >> 16;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-20 15:10:26 +02:00
|
|
|
void Highlighter::onBlockEnd(int state)
|
2010-02-15 12:27:25 +01:00
|
|
|
{
|
|
|
|
|
typedef TextEditor::TextBlockUserData TextEditorBlockData;
|
|
|
|
|
|
2010-05-27 14:46:30 +02:00
|
|
|
setCurrentBlockState((m_braceDepth << 16) | (m_inMultilineComment << 8) | state);
|
2010-05-20 15:10:26 +02:00
|
|
|
TextEditor::BaseTextDocumentLayout::setParentheses(currentBlock(), m_currentBlockParentheses);
|
|
|
|
|
TextEditor::BaseTextDocumentLayout::setFoldingIndent(currentBlock(), m_foldingIndent);
|
2010-02-15 12:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
2010-05-20 15:10:26 +02:00
|
|
|
void Highlighter::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)
|
|
|
|
|
TextEditor::BaseTextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true);
|
|
|
|
|
}
|
2010-02-15 12:27:25 +01:00
|
|
|
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos));
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-20 15:10:26 +02:00
|
|
|
void Highlighter::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)
|
|
|
|
|
TextEditor::BaseTextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true);
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|