- enhancement: Syntax highlighting for c++ attributes.
fix: mingw build errors
This commit is contained in:
parent
86cc3e170e
commit
e72b780dc3
1
NEWS.md
1
NEWS.md
|
@ -73,6 +73,7 @@ Red Panda C++ Version 2.27
|
||||||
- fix: Option 'Pause after run in console' for tools doesn't work.
|
- fix: Option 'Pause after run in console' for tools doesn't work.
|
||||||
- fix: Filename that contains '&' doesn't correctly displayed in the editor tab.
|
- fix: Filename that contains '&' doesn't correctly displayed in the editor tab.
|
||||||
- enhancement: Type induction for "auto &&" vars.
|
- enhancement: Type induction for "auto &&" vars.
|
||||||
|
- enhancement: Syntax highlighting for c++ attributes.
|
||||||
|
|
||||||
Red Panda C++ Version 2.26
|
Red Panda C++ Version 2.26
|
||||||
- enhancement: Code suggestion for embedded std::vectors.
|
- enhancement: Code suggestion for embedded std::vectors.
|
||||||
|
|
|
@ -86,6 +86,7 @@
|
||||||
#include <QMimeType>
|
#include <QMimeType>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#define DATA_KEY_INITIAL_DCHAR_SEQ "initialDCharSeq"
|
||||||
|
#define DATA_KEY_IN_ATTRIBUTE "inAttribute"
|
||||||
|
|
||||||
namespace QSynedit {
|
namespace QSynedit {
|
||||||
|
|
||||||
static const QSet<QString> CppStatementKeyWords {
|
static const QSet<QString> CppStatementKeyWords {
|
||||||
|
@ -152,6 +155,21 @@ const QSet<QString> CppSyntaxer::Keywords {
|
||||||
|
|
||||||
"nullptr",
|
"nullptr",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const QSet<QString> CppSyntaxer::StandardAttributes {
|
||||||
|
"noreturn",
|
||||||
|
"carries_dependency",
|
||||||
|
"deprecated",
|
||||||
|
"fallthrough",
|
||||||
|
"nodiscard",
|
||||||
|
"maybe_unused",
|
||||||
|
"likely",
|
||||||
|
"unlikely",
|
||||||
|
"no_unique_address",
|
||||||
|
"assume",
|
||||||
|
"optimize_for_synchronized"
|
||||||
|
};
|
||||||
|
|
||||||
CppSyntaxer::CppSyntaxer(): Syntaxer()
|
CppSyntaxer::CppSyntaxer(): Syntaxer()
|
||||||
{
|
{
|
||||||
mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
|
mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
|
||||||
|
@ -293,6 +311,12 @@ bool CppSyntaxer::isCharEscaping(int state)
|
||||||
return state == RangeState::rsCharEscaping;
|
return state == RangeState::rsCharEscaping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppSyntaxer::isInAttribute(const SyntaxState &state)
|
||||||
|
{
|
||||||
|
return state.extraData.contains(DATA_KEY_IN_ATTRIBUTE)
|
||||||
|
&& state.extraData[DATA_KEY_IN_ATTRIBUTE].toBool();
|
||||||
|
}
|
||||||
|
|
||||||
CppSyntaxer::TokenId CppSyntaxer::getTokenId()
|
CppSyntaxer::TokenId CppSyntaxer::getTokenId()
|
||||||
{
|
{
|
||||||
return mTokenId;
|
return mTokenId;
|
||||||
|
@ -652,6 +676,8 @@ void CppSyntaxer::procIdentifier()
|
||||||
if (CppStatementKeyWords.contains(word)) {
|
if (CppStatementKeyWords.contains(word)) {
|
||||||
pushIndents(IndentType::Statement);
|
pushIndents(IndentType::Statement);
|
||||||
}
|
}
|
||||||
|
} else if (isInAttribute(mRange) && StandardAttributes.contains(word)) {
|
||||||
|
mTokenId = TokenId::Key;
|
||||||
} else {
|
} else {
|
||||||
mTokenId = TokenId::Identifier;
|
mTokenId = TokenId::Identifier;
|
||||||
}
|
}
|
||||||
|
@ -1002,7 +1028,7 @@ void CppSyntaxer::procRawString()
|
||||||
mTokenId = TokenId::RawString;
|
mTokenId = TokenId::RawString;
|
||||||
QString rawStringInitialDCharSeq;
|
QString rawStringInitialDCharSeq;
|
||||||
if (mRange.state == RangeState::rsRawString)
|
if (mRange.state == RangeState::rsRawString)
|
||||||
mRange.extraData = std::make_shared<QVariant>("");
|
mRange.extraData[DATA_KEY_INITIAL_DCHAR_SEQ] = "";
|
||||||
while (mRun<mLineSize) {
|
while (mRun<mLineSize) {
|
||||||
if (mRange.state!=RangeState::rsRawStringNotEscaping &&
|
if (mRange.state!=RangeState::rsRawStringNotEscaping &&
|
||||||
(mLine[mRun].isSpace()
|
(mLine[mRun].isSpace()
|
||||||
|
@ -1019,16 +1045,16 @@ void CppSyntaxer::procRawString()
|
||||||
case '(':
|
case '(':
|
||||||
if (mRange.state==RangeState::rsRawString) {
|
if (mRange.state==RangeState::rsRawString) {
|
||||||
mRange.state = RangeState::rsRawStringNotEscaping;
|
mRange.state = RangeState::rsRawStringNotEscaping;
|
||||||
mRange.extraData = std::make_shared<QVariant>(rawStringInitialDCharSeq);
|
mRange.extraData[DATA_KEY_INITIAL_DCHAR_SEQ] = rawStringInitialDCharSeq;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ')':
|
case ')':
|
||||||
if (mRange.state == RangeState::rsRawStringNotEscaping) {
|
if (mRange.state == RangeState::rsRawStringNotEscaping) {
|
||||||
rawStringInitialDCharSeq = mRange.extraData->toString();
|
rawStringInitialDCharSeq = mRange.extraData[DATA_KEY_INITIAL_DCHAR_SEQ].toString();
|
||||||
if ( mLine.mid(mRun+1,rawStringInitialDCharSeq.length()) == rawStringInitialDCharSeq) {
|
if ( mLine.mid(mRun+1,rawStringInitialDCharSeq.length()) == rawStringInitialDCharSeq) {
|
||||||
mRun = mRun+rawStringInitialDCharSeq.length();
|
mRun = mRun+rawStringInitialDCharSeq.length();
|
||||||
mRange.state = RangeState::rsRawStringEnd;
|
mRange.state = RangeState::rsRawStringEnd;
|
||||||
mRange.extraData = nullptr;
|
mRange.extraData.remove(DATA_KEY_INITIAL_DCHAR_SEQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1137,7 +1163,16 @@ void CppSyntaxer::procSpace()
|
||||||
|
|
||||||
void CppSyntaxer::procSquareClose()
|
void CppSyntaxer::procSquareClose()
|
||||||
{
|
{
|
||||||
mRun+=1;
|
mRun++;
|
||||||
|
if (mRun < mLineSize && mLine[mRun]==']') {
|
||||||
|
if (mRange.extraData.contains(DATA_KEY_IN_ATTRIBUTE)
|
||||||
|
&& mRange.extraData[DATA_KEY_IN_ATTRIBUTE].toBool()) {
|
||||||
|
mTokenId = TokenId::Symbol;
|
||||||
|
mRun++;
|
||||||
|
mRange.extraData.remove(DATA_KEY_IN_ATTRIBUTE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
mTokenId = TokenId::Symbol;
|
mTokenId = TokenId::Symbol;
|
||||||
mRange.bracketLevel--;
|
mRange.bracketLevel--;
|
||||||
if (mRange.bracketLevel<0)
|
if (mRange.bracketLevel<0)
|
||||||
|
@ -1147,10 +1182,16 @@ void CppSyntaxer::procSquareClose()
|
||||||
|
|
||||||
void CppSyntaxer::procSquareOpen()
|
void CppSyntaxer::procSquareOpen()
|
||||||
{
|
{
|
||||||
mRun+=1;
|
mRun++;
|
||||||
|
if (mRun < mLineSize && mLine[mRun]=='[') {
|
||||||
|
mRun++;
|
||||||
|
mTokenId = TokenId::Symbol;
|
||||||
|
mRange.extraData[DATA_KEY_IN_ATTRIBUTE]=true;
|
||||||
|
} else{
|
||||||
mTokenId = TokenId::Symbol;
|
mTokenId = TokenId::Symbol;
|
||||||
mRange.bracketLevel++;
|
mRange.bracketLevel++;
|
||||||
pushIndents(IndentType::Bracket);
|
pushIndents(IndentType::Bracket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppSyntaxer::procStar()
|
void CppSyntaxer::procStar()
|
||||||
|
|
|
@ -90,12 +90,15 @@ public:
|
||||||
|
|
||||||
static const QSet<QString> ValidIntegerSuffixes;
|
static const QSet<QString> ValidIntegerSuffixes;
|
||||||
|
|
||||||
|
static const QSet<QString> StandardAttributes;
|
||||||
|
|
||||||
bool isStringToNextLine(int state);
|
bool isStringToNextLine(int state);
|
||||||
bool isRawStringStart(int state);
|
bool isRawStringStart(int state);
|
||||||
bool isRawStringNoEscape(int state);
|
bool isRawStringNoEscape(int state);
|
||||||
bool isRawStringEnd(int state);
|
bool isRawStringEnd(int state);
|
||||||
bool isCharNotFinished(int state);
|
bool isCharNotFinished(int state);
|
||||||
bool isCharEscaping(int state);
|
bool isCharEscaping(int state);
|
||||||
|
bool isInAttribute(const SyntaxState &state);
|
||||||
|
|
||||||
TokenId getTokenId();
|
TokenId getTokenId();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QVector>
|
#include <QVariant>
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
|
|
||||||
namespace QSynedit {
|
namespace QSynedit {
|
||||||
|
@ -57,7 +57,7 @@ struct SyntaxState {
|
||||||
QVector<IndentInfo> indents; // indents stack (needed by auto indent)
|
QVector<IndentInfo> indents; // indents stack (needed by auto indent)
|
||||||
IndentInfo lastUnindent;
|
IndentInfo lastUnindent;
|
||||||
bool hasTrailingSpaces;
|
bool hasTrailingSpaces;
|
||||||
std::shared_ptr<QVariant> extraData;
|
QMap<QString,QVariant> extraData;
|
||||||
|
|
||||||
bool operator==(const SyntaxState& s2);
|
bool operator==(const SyntaxState& s2);
|
||||||
IndentInfo getLastIndent();
|
IndentInfo getLastIndent();
|
||||||
|
|
Loading…
Reference in New Issue