- Enhancement: Improved Raw string support

This commit is contained in:
Roy Qu 2024-02-20 17:25:37 +08:00
parent 20339b3e9a
commit 522722c418
5 changed files with 47 additions and 7 deletions

View File

@ -46,6 +46,7 @@ Red Panda C++ Version 2.26
- Fix: Expression that starts with full scoped variables might be treated as var definition. - Fix: Expression that starts with full scoped variables might be treated as var definition.
- Enhancement: Don't auto-indent in raw string. - Enhancement: Don't auto-indent in raw string.
- Fix: Function list is not correctly retrived for full-scoped functions. - Fix: Function list is not correctly retrived for full-scoped functions.
- Enhancement: Improved Raw string support
Red Panda C++ Version 2.25 Red Panda C++ Version 2.25

View File

@ -4351,7 +4351,6 @@ void Editor::updateFunctionTip(bool showTip)
// Don't bother scanning the database when there's no identifier to scan for // Don't bother scanning the database when there's no identifier to scan for
// Only do the cumbersome list filling when showing a new tooltip... // Only do the cumbersome list filling when showing a new tooltip...
if (s != pMainWindow->functionTip()->functionFullName() if (s != pMainWindow->functionTip()->functionFullName()
&& !mParser->parsing()) { && !mParser->parsing()) {
pMainWindow->functionTip()->clearTips(); pMainWindow->functionTip()->clearTips();

View File

@ -748,16 +748,38 @@ void CppTokenizer::skipRawString()
{ {
mCurrent++; //skip R mCurrent++; //skip R
bool noEscape = false; bool noEscape = false;
bool findDCharSeq = true;
QString dCharSeq;
while(true) { while(true) {
mCurrent++; mCurrent++;
switch(mCurrent->unicode()) { switch(mCurrent->unicode()) {
case '(': case '(':
noEscape = true; if (findDCharSeq) {
noEscape = true;
findDCharSeq = false;
}
break; break;
case ')': case ')':
noEscape = false; if (noEscape) {
bool ok=true;
QChar* pChar=mCurrent+1;
for (int i=0;i<dCharSeq.length();i++) {
if (*pChar!=dCharSeq[i]) {
ok=false;
break;
}
pChar++;
}
if (ok && *pChar=='\"') {
noEscape = false;
mCurrent = pChar;
}
}
break; break;
} }
if (findDCharSeq) {
dCharSeq+=*mCurrent;
}
if (*mCurrent == 0) if (*mCurrent == 0)
break; break;
if ((*mCurrent == '"') && !noEscape) if ((*mCurrent == '"') && !noEscape)

View File

@ -963,8 +963,13 @@ void CppSyntaxer::procQuestion()
void CppSyntaxer::procRawString() void CppSyntaxer::procRawString()
{ {
mTokenId = TokenId::RawString; mTokenId = TokenId::RawString;
if (mRange.state == RangeState::rsRawString)
mRawStringInitialDCharSeq="";
while (mRun<mLineSize) { while (mRun<mLineSize) {
if (mRange.state!=RangeState::rsRawStringNotEscaping && (mLine[mRun]=='"')) { if (mRange.state!=RangeState::rsRawStringNotEscaping &&
(mLine[mRun]=='"'
|| mLine[mRun].isSpace()
|| mLine[mRun].unicode()>127)) {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
mRun+=1; mRun+=1;
return; return;
@ -974,14 +979,25 @@ void CppSyntaxer::procRawString()
case '\t': case '\t':
return; return;
case '(': case '(':
if (mRange.state==RangeState::rsRawString) if (mRange.state==RangeState::rsRawString) {
mRange.state = RangeState::rsRawStringNotEscaping; mRange.state = RangeState::rsRawStringNotEscaping;
mRawStringInitialDCharSeq += "\"";
}
break; break;
case ')': case ')':
if (mRange.state == RangeState::rsRawStringNotEscaping) qDebug()<<mRawStringInitialDCharSeq;
mRange.state = RangeState::rsRawStringEnd; qDebug()<<mLine.mid(mRun+1,mRawStringInitialDCharSeq.length());
qDebug()<<(mLine.mid(mRun+1,mRawStringInitialDCharSeq.length()) == mRawStringInitialDCharSeq);
if (mRange.state == RangeState::rsRawStringNotEscaping
&& mLine.mid(mRun+1,mRawStringInitialDCharSeq.length()) == mRawStringInitialDCharSeq) {
mRun = mRun+1+mRawStringInitialDCharSeq.length();
mRange.state = RangeState::rsUnknown;
return;
}
break; break;
} }
if (mRange.state == RangeState::rsRawString)
mRawStringInitialDCharSeq += mLine[mRun];
mRun+=1; mRun+=1;
} }
if (mRun>=mLineSize && mRange.state != RangeState::rsRawStringNotEscaping) if (mRun>=mLineSize && mRange.state != RangeState::rsRawStringNotEscaping)

View File

@ -159,6 +159,8 @@ private:
int mLeftBraces; int mLeftBraces;
int mRightBraces; int mRightBraces;
QString mRawStringInitialDCharSeq;
QSet<QString> mCustomTypeKeywords; QSet<QString> mCustomTypeKeywords;
PTokenAttribute mPreprocessorAttribute; PTokenAttribute mPreprocessorAttribute;