- enhancement: correctly highlight multiline raw string literals.

- change: remove "Assembly" color scheme item (it's not used anymore).
This commit is contained in:
Roy Qu 2023-06-30 10:53:58 +08:00
parent 8ad9e22976
commit e5e322dea4
5 changed files with 33 additions and 63 deletions

View File

@ -16,6 +16,8 @@ Red Panda C++ Version 2.23
- enhancement: When deleteing files in the files/project view, try moving to the trash bin instead.
- fix: GNU assembly files (.s) are not shown in the files view.
- fix: "typedef struct" that don't have definition of the struct is not correctly parsed.
- enhancement: correctly highlight multiline raw string literals.
- change: remove "Assembly" color scheme item (it's not used anymore).
Red Panda C++ Version 2.22

View File

@ -429,10 +429,10 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isBundled, bool
void ColorManager::initItemDefines()
{
//Token highlight colors
addDefine(SYNS_AttrAssembler,
QObject::tr("Assembler"),
QObject::tr("Syntax"),
true,true,true);
// addDefine(SYNS_AttrAssembler,
// QObject::tr("Assembler"),
// QObject::tr("Syntax"),
// true,true,true);
addDefine(SYNS_AttrCharacter,
QObject::tr("Character"),
QObject::tr("Syntax"),

View File

@ -154,9 +154,6 @@ const QSet<QString> CppSyntaxer::Keywords {
};
CppSyntaxer::CppSyntaxer(): Syntaxer()
{
mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
TokenType::Embeded);
addAttribute(mAsmAttribute);
mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
TokenType::Character);
addAttribute(mCharAttribute);
@ -201,11 +198,6 @@ CppSyntaxer::CppSyntaxer(): Syntaxer()
resetState();
}
const PTokenAttribute &CppSyntaxer::asmAttribute() const
{
return mAsmAttribute;
}
const PTokenAttribute &CppSyntaxer::preprocessorAttribute() const
{
return mPreprocessorAttribute;
@ -273,13 +265,7 @@ const PTokenAttribute &CppSyntaxer::localVarAttribute() const
CppSyntaxer::TokenId CppSyntaxer::getTokenId()
{
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock)
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
|| mTokenId == TokenId::Null)) {
return TokenId::Asm;
} else {
return mTokenId;
}
return mTokenId;
}
void CppSyntaxer::procAndSymbol()
@ -334,11 +320,7 @@ void CppSyntaxer::procAnsiCStyleComment()
case '*':
if (mRun+1<mLineSize && mLine[mRun+1] == '/') {
mRun += 2;
if (mRange.state == RangeState::rsAnsiCAsm) {
mRange.state = RangeState::rsAsm;
} else if (mRange.state == RangeState::rsAnsiCAsmBlock){
mRange.state = RangeState::rsAsmBlock;
} else if (mRange.state == RangeState::rsDirectiveComment &&
if (mRange.state == RangeState::rsDirectiveComment &&
mRun<mLineSize && mLine[mRun]!='\r' && mLine[mRun]!='\n') {
mRange.state = RangeState::rsMultiLineDirective;
} else {
@ -376,9 +358,7 @@ void CppSyntaxer::procBraceClose()
{
mRun += 1;
mTokenId = TokenId::Symbol;
if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = rsUnknown;
} else if (mRange.state == RangeState::rsDefineRemaining)
if (mRange.state == RangeState::rsDefineRemaining)
return;
mRange.braceLevel -= 1;
@ -399,10 +379,7 @@ void CppSyntaxer::procBraceOpen()
{
mRun += 1;
mTokenId = TokenId::Symbol;
if (mRange.state == RangeState::rsAsm) {
mRange.state = RangeState::rsAsmBlock;
mAsmStart = true;
} else if (mRange.state == RangeState::rsDefineRemaining)
if (mRange.state == RangeState::rsDefineRemaining)
return;
mRange.braceLevel += 1;
@ -950,30 +927,30 @@ void CppSyntaxer::procQuestion()
void CppSyntaxer::procRawString()
{
bool noEscaping = false;
mTokenId = TokenId::RawString;
while (mRun<mLineSize) {
if (!noEscaping && (mLine[mRun]=='"')) {
if (mRange.state!=RangeState::rsRawStringNotEscaping && (mLine[mRun]=='"')) {
mRange.state = RangeState::rsUnknown;
mRun+=1;
break;
return;
}
switch (mLine[mRun].unicode()) {
case ' ':
case '\t':
return;
case '(':
if (!noEscaping)
noEscaping = true;
if (mRange.state==RangeState::rsRawString)
mRange.state = RangeState::rsRawStringNotEscaping;
break;
case ')':
if (noEscaping)
noEscaping = false;
if (mRange.state == RangeState::rsRawStringNotEscaping)
mRange.state = RangeState::rsRawStringEnd;
break;
}
mRun+=1;
}
mRange.state = RangeState::rsUnknown;
if (mRun>=mLineSize && mRange.state != RangeState::rsRawStringNotEscaping)
mRange.state = RangeState::rsUnknown;
}
void CppSyntaxer::procRoundClose()
@ -998,8 +975,6 @@ void CppSyntaxer::procSemiColon()
{
mRun += 1;
mTokenId = TokenId::Symbol;
if (mRange.state == RangeState::rsAsm)
mRange.state = RangeState::rsUnknown;
while (mRange.getLastIndentType() == IndentType::Statement) {
popIndents(IndentType::Statement);
}
@ -1019,11 +994,7 @@ void CppSyntaxer::procSlash()
return;
case '*': // C style comment
mTokenId = TokenId::Comment;
if (mRange.state == RangeState::rsAsm) {
mRange.state = RangeState::rsAnsiCAsm;
} else if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = RangeState::rsAnsiCAsmBlock;
} else if (mRange.state == RangeState::rsDirective) {
if (mRange.state == RangeState::rsDirective) {
mRange.state = RangeState::rsDirectiveComment;
} else {
mRange.state = RangeState::rsAnsiC;
@ -1484,8 +1455,6 @@ bool CppSyntaxer::getTokenFinished() const
bool CppSyntaxer::isLastLineCommentNotFinished(int state) const
{
return (state == RangeState::rsAnsiC ||
state == RangeState::rsAnsiCAsm ||
state == RangeState::rsAnsiCAsmBlock ||
state == RangeState::rsDirectiveComment||
state == RangeState::rsCppComment);
}
@ -1508,8 +1477,6 @@ QString CppSyntaxer::getToken() const
const PTokenAttribute &CppSyntaxer::getTokenAttribute() const
{
switch (mTokenId) {
case TokenId::Asm:
return mAsmAttribute;
case TokenId::Comment:
return mCommentAttribute;
case TokenId::Directive:
@ -1555,17 +1522,18 @@ int CppSyntaxer::getTokenPos()
void CppSyntaxer::next()
{
mAsmStart = false;
mTokenPos = mRun;
do {
if (mRun>=mLineSize) {
procNull();
break;
}
if (mRun<mLineSize && isSpaceChar(mLine[mRun])) {
procSpace();
break;
}
switch (mRange.state) {
case RangeState::rsAnsiC:
case RangeState::rsAnsiCAsm:
case RangeState::rsAnsiCAsmBlock:
case RangeState::rsDirectiveComment:
//qDebug()<<"*0-0-0*";
procAnsiCStyleComment();
@ -1610,6 +1578,12 @@ void CppSyntaxer::next()
//qDebug()<<"*9-0-0*";
procDefineRemaining();
break;
case RangeState::rsRawStringNotEscaping:
case RangeState::rsRawString:
case RangeState::rsRawStringEnd:
//qDebug()<<"*9-0-0*";
procRawString();
break;
default:
//qDebug()<<"*a-0-0*";
mRange.state = RangeState::rsUnknown;
@ -1619,6 +1593,7 @@ void CppSyntaxer::next()
} else if (mRun+1<mLineSize && mLine[mRun] == 'R' && mLine[mRun+1] == '"') {
//qDebug()<<"*c-0-0*";
mRun+=2;
mRange.state = RangeState::rsRawString;
procRawString();
} else if (mRun+1<mLineSize && (mLine[mRun] == 'L' || mLine[mRun] == 'u' || mLine[mRun]=='U') && mLine[mRun+1]=='\"') {
//qDebug()<<"*d-0-0*";
@ -1680,7 +1655,6 @@ void CppSyntaxer::resetState()
mRange.indents.clear();
mRange.lastUnindent=IndentInfo{IndentType::None,0};
mRange.hasTrailingSpaces = false;
mAsmStart = false;
}
QString CppSyntaxer::languageName()

View File

@ -24,7 +24,6 @@ namespace QSynedit {
class CppSyntaxer: public Syntaxer
{
enum class TokenId {
Asm,
Comment,
Directive,
Identifier,
@ -46,8 +45,7 @@ class CppSyntaxer: public Syntaxer
};
enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
rsUnknown, rsAnsiC, rsDirective, rsDirectiveComment, rsString,
rsMultiLineString, rsMultiLineDirective, rsCppComment,
rsStringEscapeSeq,
rsRawString, rsSpace,rsRawStringNotEscaping,rsRawStringEnd,rsChar,
@ -59,8 +57,6 @@ public:
CppSyntaxer(const CppSyntaxer&)=delete;
CppSyntaxer operator=(const CppSyntaxer&)=delete;
const PTokenAttribute &asmAttribute() const;
const PTokenAttribute &preprocessorAttribute() const;
const PTokenAttribute &invalidAttribute() const;
@ -148,7 +144,6 @@ private:
void pushIndents(IndentType indentType, int line=-1);
private:
bool mAsmStart;
SyntaxState mRange;
// SynRangeState mSpaceRange;
QString mLine;
@ -164,7 +159,6 @@ private:
QSet<QString> mCustomTypeKeywords;
PTokenAttribute mAsmAttribute;
PTokenAttribute mPreprocessorAttribute;
PTokenAttribute mInvalidAttribute;
PTokenAttribute mNumberAttribute;