From e5e322dea42e8e395d819d7c101d7e3fa14b92a5 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 30 Jun 2023 10:53:58 +0800 Subject: [PATCH] - enhancement: correctly highlight multiline raw string literals. - change: remove "Assembly" color scheme item (it's not used anymore). --- NEWS.md | 2 + RedPandaIDE/colorscheme.cpp | 8 +-- RedPandaIDE/parser/cppparser.cpp | 2 +- libs/qsynedit/qsynedit/syntaxer/cpp.cpp | 76 ++++++++----------------- libs/qsynedit/qsynedit/syntaxer/cpp.h | 8 +-- 5 files changed, 33 insertions(+), 63 deletions(-) diff --git a/NEWS.md b/NEWS.md index b2108880..bdeccf85 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index 5e36d68d..8c3c14ae 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -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"), diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index e57709ef..d33f5109 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -3338,7 +3338,7 @@ bool CppParser::handleStatement() } void CppParser::handleStructs(bool isTypedef) -{ +{ bool isFriend = false; QString prefix = mTokenizer[mIndex]->text; if (prefix == "friend") { diff --git a/libs/qsynedit/qsynedit/syntaxer/cpp.cpp b/libs/qsynedit/qsynedit/syntaxer/cpp.cpp index 5080d909..0f4a3fef 100644 --- a/libs/qsynedit/qsynedit/syntaxer/cpp.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/cpp.cpp @@ -154,9 +154,6 @@ const QSet CppSyntaxer::Keywords { }; CppSyntaxer::CppSyntaxer(): Syntaxer() { - mAsmAttribute = std::make_shared(SYNS_AttrAssembler, - TokenType::Embeded); - addAttribute(mAsmAttribute); mCharAttribute = std::make_shared(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 && 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 mCustomTypeKeywords; - PTokenAttribute mAsmAttribute; PTokenAttribute mPreprocessorAttribute; PTokenAttribute mInvalidAttribute; PTokenAttribute mNumberAttribute;