- enhancement: Highlight words in the string/comments.

This commit is contained in:
Roy Qu 2024-03-28 18:25:36 +08:00
parent 4ac5bc3a40
commit 23c3644871
4 changed files with 69 additions and 95 deletions

View File

@ -103,6 +103,7 @@ Red Panda C++ Version 2.27
- change: Don't turn on the code format option "indent class" by default. - change: Don't turn on the code format option "indent class" by default.
- enhancement: Add compiler set by choose the executable. - enhancement: Add compiler set by choose the executable.
- fix: Compile info for project doesn't have name of the project executable. - fix: Compile info for project doesn't have name of the project executable.
- enhancement: Highlight words in the string/comments.
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.

View File

@ -1342,6 +1342,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (((attr->tokenType() == QSynedit::TokenType::Identifier) if (((attr->tokenType() == QSynedit::TokenType::Identifier)
|| (attr->tokenType() == QSynedit::TokenType::Keyword) || (attr->tokenType() == QSynedit::TokenType::Keyword)
|| (attr->tokenType() == QSynedit::TokenType::Preprocessor) || (attr->tokenType() == QSynedit::TokenType::Preprocessor)
|| (attr->tokenType() == QSynedit::TokenType::String)
|| (attr->tokenType() == QSynedit::TokenType::Comment)
) )
&& (token == mCurrentHighlightedWord)) { && (token == mCurrentHighlightedWord)) {
// occurrencies of the selected identifier // occurrencies of the selected identifier
@ -1883,6 +1885,8 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
(attri->tokenType()==QSynedit::TokenType::Identifier) (attri->tokenType()==QSynedit::TokenType::Identifier)
|| (attri->tokenType() == QSynedit::TokenType::Keyword) || (attri->tokenType() == QSynedit::TokenType::Keyword)
|| (attri->tokenType() == QSynedit::TokenType::Preprocessor) || (attri->tokenType() == QSynedit::TokenType::Preprocessor)
|| (attri->tokenType() == QSynedit::TokenType::String)
|| (attri->tokenType() == QSynedit::TokenType::Comment)
)) { )) {
mCurrentHighlightedWord = token; mCurrentHighlightedWord = token;
} else { } else {

View File

@ -3186,7 +3186,6 @@ bool Settings::CompilerSets::addSets(const QString &folder, const QString& c_pro
if (set->binDirs().contains(folder) && extractFileName(set->CCompiler())==c_prog) if (set->binDirs().contains(folder) && extractFileName(set->CCompiler())==c_prog)
return false; return false;
} }
qDebug()<<folder<<c_prog;
// Default, release profile // Default, release profile
PCompilerSet baseSet = addSet(folder,c_prog); PCompilerSet baseSet = addSet(folder,c_prog);
if (!baseSet || baseSet->name().isEmpty()) if (!baseSet || baseSet->name().isEmpty())

View File

@ -349,9 +349,19 @@ void CppSyntaxer::procCppStyleComment()
return; return;
} }
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
bool isWord = isIdentChar(mLine[mRun]);
while (mRun<mLineSize) { while (mRun<mLineSize) {
if (isSpaceChar(mLine[mRun])) if (isSpaceChar(mLine[mRun])) {
break; break;
} else {
if (isWord) {
if (!isIdentChar(mLine[mRun]))
break;
} else {
if (isIdentChar(mLine[mRun]))
break;
}
}
mRun++; mRun++;
} }
if (mRun<mLineSize) { if (mRun<mLineSize) {
@ -364,48 +374,51 @@ void CppSyntaxer::procCppStyleComment()
void CppSyntaxer::procDocstring() void CppSyntaxer::procDocstring()
{ {
bool finishProcess = false;
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
if (mRun>=mLineSize) { if (mRun>=mLineSize) {
procNull(); procNull();
return; return;
} }
bool isWord = isIdentChar(mLine[mRun]);
while (mRun<mLineSize) { while (mRun<mLineSize) {
switch(mLine[mRun].unicode()) { if(isSpaceChar(mLine[mRun]))
case ' ': break;
case '\t': else if (mLine[mRun] == '*') {
return;
case '*':
if (mRun+1<mLineSize && mLine[mRun+1] == '/') { if (mRun+1<mLineSize && mLine[mRun+1] == '/') {
if (isWord)
break;
mRun += 2; mRun += 2;
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
finishProcess = true;
} else
mRun+=1;
break; break;
default:
mRun+=1;
} }
if (finishProcess) } else {
if (isWord) {
if (!isIdentChar(mLine[mRun]))
break; break;
} else {
if (isIdentChar(mLine[mRun]))
break;
}
}
mRun++;
} }
} }
void CppSyntaxer::procAnsiCStyleComment() void CppSyntaxer::procAnsiCStyleComment()
{ {
bool finishProcess = false;
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
if (mRun>=mLineSize) { if (mRun>=mLineSize) {
procNull(); procNull();
return; return;
} }
bool isWord = isIdentChar(mLine[mRun]);
while (mRun<mLineSize) { while (mRun<mLineSize) {
switch(mLine[mRun].unicode()) { if(isSpaceChar(mLine[mRun])) {
case ' ': break;
case '\t': } else if (mLine[mRun] == '*') {
return;
case '*':
if (mRun+1<mLineSize && mLine[mRun+1] == '/') { if (mRun+1<mLineSize && mLine[mRun+1] == '/') {
if (isWord)
break;
mRun += 2; mRun += 2;
if (mRange.state == RangeState::rsDirectiveComment && if (mRange.state == RangeState::rsDirectiveComment &&
mRun<mLineSize && mLine[mRun]!='\r' && mLine[mRun]!='\n') { mRun<mLineSize && mLine[mRun]!='\r' && mLine[mRun]!='\n') {
@ -413,15 +426,18 @@ void CppSyntaxer::procAnsiCStyleComment()
} else { } else {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
finishProcess = true;
} else
mRun+=1;
break; break;
default:
mRun+=1;
} }
if (finishProcess) } else {
if (isWord) {
if (!isIdentChar(mLine[mRun]))
break; break;
} else {
if (isIdentChar(mLine[mRun]))
break;
}
}
mRun++;
} }
} }
@ -1126,9 +1142,7 @@ void CppSyntaxer::procSlash()
if (mRun < mLineSize) { if (mRun < mLineSize) {
if (mRange.state == RangeState::rsAnsiC && mLine[mRun] == '*' ) { if (mRange.state == RangeState::rsAnsiC && mLine[mRun] == '*' ) {
mRange.state = RangeState::rsDocstring; mRange.state = RangeState::rsDocstring;
procDocstring(); }
} else
procAnsiCStyleComment();
} }
return; return;
case '=': case '=':
@ -1208,63 +1222,6 @@ void CppSyntaxer::procStar()
} }
} }
//void CppSyntaxer::stringEndProc()
//{
// mTokenId = TokenId::String;
// if (mRun>=mLineSize) {
// nullProc();
// return;
// }
// mRange.state = RangeState::rsUnknown;
// while (mRun<mLineSize) {
// if (mLine[mRun]=='"') {
// mRun += 1;
// break;
// } else if (isSpaceChar(mLine[mRun])) {
// mRange.state = RangeState::rsString;
// return;
// } else if (mLine[mRun]=='\\') {
// if (mRun == mLineSize-1) {
// mRun+=1;
// mRange.state = RangeState::rsMultiLineString;
// return;
// }
// if (mRun+1<mLineSize) {
// switch(mLine[mRun+1].unicode()) {
// case '\'':
// case '"':
// case '\\':
// case '?':
// case 'a':
// case 'b':
// case 'f':
// case 'n':
// case 'r':
// case 't':
// case 'v':
// case '0':
// case '1':
// case '2':
// case '3':
// case '4':
// case '5':
// case '6':
// case '7':
// case '8':
// case '9':
// case 'x':
// case 'u':
// case 'U':
// mRange.state = RangeState::rsMultiLineStringEscapeSeq;
// return;
// }
// }
// }
// mRun += 1;
// }
//}
void CppSyntaxer::procStringEscapeSeq() void CppSyntaxer::procStringEscapeSeq()
{ {
mTokenId = TokenId::StringEscapeSeq; mTokenId = TokenId::StringEscapeSeq;
@ -1341,8 +1298,11 @@ void CppSyntaxer::procString()
return; return;
} }
mTokenId = TokenId::String; mTokenId = TokenId::String;
bool isWord = isIdentChar(mLine[mRun]);
while (mRun < mLineSize) { while (mRun < mLineSize) {
if (mLine[mRun]=='"') { if (mLine[mRun]=='"') {
if (isWord)
break;
mRun++; mRun++;
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
return; return;
@ -1384,6 +1344,16 @@ void CppSyntaxer::procString()
return; return;
} }
} }
} else {
if (isWord) {
if (!isIdentChar(mLine[mRun])) {
break;
}
} else {
if (isIdentChar(mLine[mRun])) {
break;
}
}
} }
mRun+=1; mRun+=1;
} }
@ -1395,7 +1365,7 @@ void CppSyntaxer::procStringStart()
{ {
mTokenId = TokenId::String; mTokenId = TokenId::String;
mRange.state = RangeState::rsString; mRange.state = RangeState::rsString;
mRun += 1; mRun++; //skip \"
if (mRun>=mLineSize) { if (mRun>=mLineSize) {
mRange.state = RangeState::rsStringUnfinished; mRange.state = RangeState::rsStringUnfinished;
return; return;