- enhancement: Syntax color support for binaray integer literals.

- enhancement: Syntax color support for suffix in integer/float literals.
This commit is contained in:
Roy Qu 2023-03-08 13:23:47 +08:00
parent b176215d1f
commit 9c04759602
7 changed files with 119 additions and 17 deletions

View File

@ -10,6 +10,10 @@ Red Panda C++ Version 2.17
- fix: After project's default encoding is changed in the project options dialog, all project files' encoding are wrongly setted to the new encoding.(They should be "Project default") - fix: After project's default encoding is changed in the project options dialog, all project files' encoding are wrongly setted to the new encoding.(They should be "Project default")
- enhancement: Make project's default encoding setting in the project options dialog more user friendly. - enhancement: Make project's default encoding setting in the project options dialog more user friendly.
- fix: In project options dialog's file page, Project's default encoding name is not updated when it's changed. - fix: In project options dialog's file page, Project's default encoding name is not updated when it's changed.
- enhancement: Improve the compatibility with Dev-C++ for project configuations saved by Redpanda-C++.
- enhancement: Syntax color support for binaray integer literals.
- enhancement: Syntax color support for suffix in integer/float literals.
Red Panda C++ Version 2.16 Red Panda C++ Version 2.16

View File

@ -1048,13 +1048,13 @@ bool Project::saveAsTemplate(const QString &templateFolder,
if (!mOptions.libDirs.isEmpty()) if (!mOptions.libDirs.isEmpty())
ini->SetValue("Project", "Libs", relativePaths(mOptions.libDirs).join(";").toUtf8()); ini->SetValue("Project", "Libs", relativePaths(mOptions.libDirs).join(";").toUtf8());
if (!mOptions.compilerCmd.isEmpty()) if (!mOptions.compilerCmd.isEmpty())
ini->SetValue("Project", "Compiler", textToLines(mOptions.compilerCmd).join(";CONFIG_LINE;").toUtf8()); ini->SetValue("Project", "Compiler", textToLines(mOptions.compilerCmd).join(" ").toUtf8());
if (!mOptions.cppCompilerCmd.isEmpty()) if (!mOptions.cppCompilerCmd.isEmpty())
ini->SetValue("Project", "CppCompiler", textToLines(mOptions.cppCompilerCmd).join(";CONFIG_LINE;").toUtf8()); ini->SetValue("Project", "CppCompiler", textToLines(mOptions.cppCompilerCmd).join(" ").toUtf8());
if (!mOptions.linkerCmd.isEmpty()) if (!mOptions.linkerCmd.isEmpty())
ini->SetValue("Project", "Linker",textToLines(mOptions.linkerCmd).join(";CONFIG_LINE;").toUtf8()); ini->SetValue("Project", "Linker",textToLines(mOptions.linkerCmd).join(" ").toUtf8());
if (!mOptions.resourceCmd.isEmpty()) if (!mOptions.resourceCmd.isEmpty())
ini->SetValue("Project", "ResourceCommand",textToLines(mOptions.resourceCmd).join(";CONFIG_LINE;").toUtf8()); ini->SetValue("Project", "ResourceCommand",textToLines(mOptions.resourceCmd).join(" ").toUtf8());
ini->SetBoolValue("Project", "IsCpp", mOptions.isCpp); ini->SetBoolValue("Project", "IsCpp", mOptions.isCpp);
if (mOptions.includeVersionInfo) if (mOptions.includeVersionInfo)
ini->SetBoolValue("Project", "IncludeVersionInfo", true); ini->SetBoolValue("Project", "IncludeVersionInfo", true);
@ -1152,10 +1152,10 @@ void Project::saveOptions()
ini.SetValue("Project","ResourceIncludes", toByteArray(relativePaths(mOptions.resourceIncludes).join(";"))); ini.SetValue("Project","ResourceIncludes", toByteArray(relativePaths(mOptions.resourceIncludes).join(";")));
ini.SetValue("Project","MakeIncludes", toByteArray(relativePaths(mOptions.makeIncludes).join(";"))); ini.SetValue("Project","MakeIncludes", toByteArray(relativePaths(mOptions.makeIncludes).join(";")));
ini.SetValue("Project","PrivateResource", toByteArray(mOptions.privateResource)); ini.SetValue("Project","PrivateResource", toByteArray(mOptions.privateResource));
ini.SetValue("Project","Compiler", toByteArray(textToLines(mOptions.compilerCmd).join(";CONFIG_LINE;"))); ini.SetValue("Project","Compiler", toByteArray(textToLines(mOptions.compilerCmd).join(" ")));
ini.SetValue("Project","CppCompiler", toByteArray(textToLines(mOptions.cppCompilerCmd).join(";CONFIG_LINE;"))); ini.SetValue("Project","CppCompiler", toByteArray(textToLines(mOptions.cppCompilerCmd).join(" ")));
ini.SetValue("Project","Linker", toByteArray(textToLines(mOptions.linkerCmd).join(";CONFIG_LINE;"))); ini.SetValue("Project","Linker", toByteArray(textToLines(mOptions.linkerCmd).join(" ")));
ini.SetValue("Project", "ResourceCommand", toByteArray(textToLines(mOptions.resourceCmd).join(";CONFIG_LINE;"))); ini.SetValue("Project", "ResourceCommand", toByteArray(textToLines(mOptions.resourceCmd).join(" ")));
ini.SetLongValue("Project","IsCpp", mOptions.isCpp); ini.SetLongValue("Project","IsCpp", mOptions.isCpp);
ini.SetValue("Project","Icon", toByteArray(extractRelativePath(directory(), mOptions.icon))); ini.SetValue("Project","Icon", toByteArray(extractRelativePath(directory(), mOptions.icon)));
ini.SetValue("Project","ExeOutput", toByteArray(extractRelativePath(directory(),mOptions.exeOutput))); ini.SetValue("Project","ExeOutput", toByteArray(extractRelativePath(directory(),mOptions.exeOutput)));
@ -1956,6 +1956,8 @@ void Project::loadOptions(SimpleIni& ini)
} }
mOptions.type = static_cast<ProjectType>(ini.GetLongValue("Project", "type", 0)); mOptions.type = static_cast<ProjectType>(ini.GetLongValue("Project", "type", 0));
// ;CONFIG_LINE; is used in olded version config files (<2.17)
// keep it for compatibility
mOptions.compilerCmd = fromByteArray(ini.GetValue("Project", "Compiler", "")).replace(";CONFIG_LINE;","\n"); mOptions.compilerCmd = fromByteArray(ini.GetValue("Project", "Compiler", "")).replace(";CONFIG_LINE;","\n");
mOptions.cppCompilerCmd = fromByteArray(ini.GetValue("Project", "CppCompiler", "")).replace(";CONFIG_LINE;","\n"); mOptions.cppCompilerCmd = fromByteArray(ini.GetValue("Project", "CppCompiler", "")).replace(";CONFIG_LINE;","\n");
mOptions.linkerCmd = fromByteArray(ini.GetValue("Project", "Linker", "")).replace(";CONFIG_LINE;","\n"); mOptions.linkerCmd = fromByteArray(ini.GetValue("Project", "Linker", "")).replace(";CONFIG_LINE;","\n");

View File

@ -93,3 +93,4 @@ void ProjectCompileParamatersWidget::updateIcons(const QSize &/*size*/)
pIconsManager->setIcon(ui->btnChooseLib, IconsManager::ACTION_MISC_FOLDER); pIconsManager->setIcon(ui->btnChooseLib, IconsManager::ACTION_MISC_FOLDER);
} }

View File

@ -41,7 +41,6 @@ protected:
private slots: private slots:
void on_btnChooseLib_clicked(); void on_btnChooseLib_clicked();
// SettingsWidget interface
protected: protected:
void updateIcons(const QSize &size) override; void updateIcons(const QSize &size) override;
}; };

View File

@ -52,7 +52,7 @@
<item> <item>
<widget class="QTabWidget" name="tabCommands"> <widget class="QTabWidget" name="tabCommands">
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="tabCCompiler"> <widget class="QWidget" name="tabCCompiler">
<attribute name="title"> <attribute name="title">

View File

@ -31,7 +31,18 @@ static const QSet<QString> CppStatementKeyWords {
"while", "while",
"do" "do"
}; };
const QSet<QString> CppSyntaxer::ValidIntegerSuffixes {
"u",
"ll",
"z",
"l",
"uz",
"zu",
"ull",
"llu",
"lu",
"ul"
};
const QSet<QString> CppSyntaxer::Keywords { const QSet<QString> CppSyntaxer::Keywords {
@ -676,6 +687,9 @@ void CppSyntaxer::procNumber(bool isFloat)
if (mLine[mRun+1]=='x' || mLine[mRun+1]=='X') { if (mLine[mRun+1]=='x' || mLine[mRun+1]=='X') {
mTokenId=TokenId::Hex; mTokenId=TokenId::Hex;
mRun+=2; mRun+=2;
} else if (mLine[mRun+1]=='b' || mLine[mRun+1]=='B') {
mTokenId=TokenId::Binary;
mRun+=2;
} else if (mLine[mRun+1]>='0' && mLine[mRun+1]<='7') { } else if (mLine[mRun+1]>='0' && mLine[mRun+1]<='7') {
mTokenId=TokenId::Octal; mTokenId=TokenId::Octal;
mRun+=2; mRun+=2;
@ -690,6 +704,9 @@ void CppSyntaxer::procNumber(bool isFloat)
case TokenId::Octal: case TokenId::Octal:
procOctNumber(); procOctNumber();
break; break;
case TokenId::Binary:
procBinNumber();
break;
default: default:
procDecNumber(); procDecNumber();
} }
@ -700,12 +717,6 @@ void CppSyntaxer::procDecNumber()
while (mRun<mLineSize) { while (mRun<mLineSize) {
switch(mLine[mRun].unicode()) { switch(mLine[mRun].unicode()) {
case '\'':
if (mTokenId != TokenId::Number) {
return;
}
mRun++;
break;
case '.': case '.':
if (mTokenId != TokenId::Number) { if (mTokenId != TokenId::Number) {
mTokenId = TokenId::Unknown; mTokenId = TokenId::Unknown;
@ -724,6 +735,7 @@ void CppSyntaxer::procDecNumber()
case '7': case '7':
case '8': case '8':
case '9': case '9':
case '\'':
mRun++; mRun++;
break; break;
case 'e': case 'e':
@ -734,6 +746,7 @@ void CppSyntaxer::procDecNumber()
mRun++; mRun++;
break; break;
default: default:
procNumberSuffix();
return; return;
} }
} }
@ -774,6 +787,7 @@ void CppSyntaxer::procHexNumber()
case 'D': case 'D':
case 'E': case 'E':
case 'F': case 'F':
case '\'':
mRun++; mRun++;
break; break;
case 'p': case 'p':
@ -784,6 +798,7 @@ void CppSyntaxer::procHexNumber()
mRun++; mRun++;
break; break;
default: default:
procNumberSuffix();
return; return;
} }
} }
@ -802,14 +817,85 @@ void CppSyntaxer::procOctNumber()
case '5': case '5':
case '6': case '6':
case '7': case '7':
case '\'':
mRun++; mRun++;
break; break;
default: default:
procIntegerSuffix();
return; return;
} }
} }
} }
void CppSyntaxer::procBinNumber()
{
while (mRun<mLineSize) {
switch(mLine[mRun].unicode()) {
case '0':
case '1':
case '\'':
mRun++;
break;
default:
procIntegerSuffix();
return;
}
}
}
void CppSyntaxer::procNumberSuffix()
{
if (mTokenId==TokenId::HexFloat
|| mTokenId==TokenId::Float )
procFloatSuffix();
else
procIntegerSuffix();
}
void CppSyntaxer::procIntegerSuffix()
{
if (mRun>=mLineSize)
return;
int i=mRun;
bool shouldExit = false;
while (i<mLineSize && !shouldExit) {
switch (mLine[i].unicode()) {
case 'u':
case 'U':
case 'l':
case 'L':
case 'z':
case 'Z':
i++;
break;
default:
shouldExit=true;
}
}
if (i>mRun) {
QString s=mLine.mid(mRun,i-mRun).toLower();
if (ValidIntegerSuffixes.contains(s)) {
mRun=i;
}
}
return ;
}
void CppSyntaxer::procFloatSuffix()
{
if (mRun>=mLineSize)
return;
switch (mLine[mRun].unicode()) {
case 'f':
case 'F':
case 'l':
case 'L':
mRun++;
break;
}
return ;
}
void CppSyntaxer::procOr() void CppSyntaxer::procOr()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -1427,6 +1513,8 @@ const PTokenAttribute &CppSyntaxer::getTokenAttribute() const
return mHexAttribute; return mHexAttribute;
case TokenId::Octal: case TokenId::Octal:
return mOctAttribute; return mOctAttribute;
case TokenId::Binary:
return mOctAttribute;
case TokenId::Space: case TokenId::Space:
return mWhitespaceAttribute; return mWhitespaceAttribute;
case TokenId::String: case TokenId::String:

View File

@ -41,6 +41,7 @@ class CppSyntaxer: public Syntaxer
Hex, Hex,
HexFloat, HexFloat,
Octal, Octal,
Binary,
RawString RawString
}; };
@ -88,6 +89,8 @@ public:
static const QSet<QString> Keywords; static const QSet<QString> Keywords;
static const QSet<QString> ValidIntegerSuffixes;
TokenId getTokenId(); TokenId getTokenId();
private: private:
void procAndSymbol(); void procAndSymbol();
@ -114,6 +117,11 @@ private:
void procDecNumber(); void procDecNumber();
void procHexNumber(); void procHexNumber();
void procOctNumber(); void procOctNumber();
void procBinNumber();
void procNumberSuffix();
void procIntegerSuffix();
void procFloatSuffix();
void procOr(); void procOr();
void procPlus(); void procPlus();
void procPoint(); void procPoint();