F: Improve old reference loading

This commit is contained in:
Ivan 2024-08-30 18:27:52 +03:00
parent e4727b52ab
commit d456220006
6 changed files with 60 additions and 12 deletions

View File

@ -1,3 +1,5 @@
30.08.2024 Экстеор 4.9.4
• исправлена загрузка файлов версий 2017-2020 годов
14.06.2024 Экстеор 4.9.3 14.06.2024 Экстеор 4.9.3
• Грамматика: разрешено использование одного аргумента для мультифильтра - Fi1,2[X1*X1](S1) • Грамматика: разрешено использование одного аргумента для мультифильтра - Fi1,2[X1*X1](S1)
• исправлена ошибка, приводившая к некорректному вычислению типизаций рекурсии с пустым множеством • исправлена ошибка, приводившая к некорректному вычислению типизаций рекурсии с пустым множеством

View File

@ -1182,8 +1182,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,9,3,1000 FILEVERSION 4,9,4,1000
PRODUCTVERSION 4,9,3,1000 PRODUCTVERSION 4,9,4,1000
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -1201,13 +1201,13 @@ BEGIN
VALUE "Comments", "Ýêñïëèêàòîð òåîðèé " VALUE "Comments", "Ýêñïëèêàòîð òåîðèé "
VALUE "CompanyName", "ÍÏ ÖÈÂÒ ÊÎÍÖÅÏÒ" VALUE "CompanyName", "ÍÏ ÖÈÂÒ ÊÎÍÖÅÏÒ"
VALUE "FileDescription", "Ýêñòåîð 4.9" VALUE "FileDescription", "Ýêñòåîð 4.9"
VALUE "FileVersion", "4.9.3.1000" VALUE "FileVersion", "4.9.4.1000"
VALUE "InternalName", "Ýêñòåîð 4.9" VALUE "InternalName", "Ýêñòåîð 4.9"
VALUE "LegalCopyright", "Copyright © NPMP CIHT CONCEPT 1994-2024" VALUE "LegalCopyright", "Copyright © NPMP CIHT CONCEPT 1994-2024"
VALUE "LegalTrademarks", "Ýêñòåîð™" VALUE "LegalTrademarks", "Ýêñòåîð™"
VALUE "OriginalFilename", "Exteor.exe" VALUE "OriginalFilename", "Exteor.exe"
VALUE "ProductName", "Ýêñòåîð 4.9" VALUE "ProductName", "Ýêñòåîð 4.9"
VALUE "ProductVersion", "4.9.3.1000" VALUE "ProductVersion", "4.9.4.1000"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -4,6 +4,11 @@
#include "xtr/core/Encoder.h" #include "xtr/core/Encoder.h"
#include <string>
#include <string_view>
#include <regex>
#include <algorithm>
using ccl::semantic::ConceptRecord; using ccl::semantic::ConceptRecord;
using ccl::semantic::CstType; using ccl::semantic::CstType;
using ccl::lang::ManagedText; using ccl::lang::ManagedText;
@ -11,6 +16,40 @@ using ccl::lang::LexicalTerm;
namespace xtr::io { namespace xtr::io {
namespace details {
static void FixOldReferences(std::string& target) {
static const std::regex referencePattern(R"(\@\{([A-Z]\d+)\|([A-Z]+)\|([A-Z]+)\|\d+\})");
std::vector<std::pair<std::string, std::string>> replacements{};
std::sregex_iterator iter(target.begin(), target.end(), referencePattern);
std::sregex_iterator end{};
while (iter != end) {
std::smatch match = *iter;
std::string part1 = match[1].str(); // e.g., "D4"
std::string part2 = match[2].str(); // e.g., "ABLT"
std::string part3 = match[3].str(); // e.g., "PLUR"
std::transform(part2.begin(), part2.end(), part2.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
std::transform(part3.begin(), part3.end(), part3.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
std::string newReference = "@{" + part1 + "|" + part2 + "," + part3 + "}";
replacements.emplace_back(match.str(), newReference);
iter++;
}
for (const auto& [oldRef, newRef] : replacements) {
size_t pos = 0;
while ((pos = target.find(oldRef, pos)) != std::string::npos) {
target.replace(pos, oldRef.length(), newRef);
pos += newRef.length();
}
}
}
}
void LegacyCstLoader::LoadBasicProperties(BOOL oldType) { void LegacyCstLoader::LoadBasicProperties(BOOL oldType) {
const auto sName = ar.Load<CString>(); const auto sName = ar.Load<CString>();
auto sComment = ar.Load<CString>(); auto sComment = ar.Load<CString>();
@ -73,11 +112,14 @@ void LegacyCstLoader::LoadTerms(const BOOL hasTerms, const BOOL multipleTerms) {
termRefs.at(0) = terms.at(0); termRefs.at(0) = terms.at(0);
} }
cst->term = LexicalTerm{ mfc::ToSTL(termRefs.at(0)), mfc::ToSTL(terms.at(0)) }; auto termRaw = mfc::ToSTL(termRefs.at(0));
details::FixOldReferences(termRaw);
cst->term = LexicalTerm{ termRaw, mfc::ToSTL(terms.at(0)) };
for (uint8_t j = 0; j < size(TERM_FORMS); ++j) { for (uint8_t j = 0; j < size(TERM_FORMS); ++j) {
const auto formText = mfc::ToSTL(termForms.at(0).at(j)); auto manualForm = mfc::ToSTL(termForms.at(0).at(j));
if (!formText.empty()) { if (!manualForm.empty()) {
cst->term.SetForm(TERM_FORMS.at(j), formText); details::FixOldReferences(manualForm);
cst->term.SetForm(TERM_FORMS.at(j), manualForm);
} }
} }
} }
@ -91,7 +133,9 @@ void LegacyCstLoader::LoadInterpretation(const BOOL loadWithRef) {
if (needEncoding) { if (needEncoding) {
encode::EncodeToUnicode(sInterpretation); encode::EncodeToUnicode(sInterpretation);
} }
cst->definition = ManagedText{ mfc::ToSTL(sInterpretationRef), mfc::ToSTL(sInterpretation) }; auto interpretationRaw = mfc::ToSTL(sInterpretationRef);
details::FixOldReferences(interpretationRaw);
cst->definition = ManagedText{ interpretationRaw, mfc::ToSTL(sInterpretation) };
} }
void LegacyCstLoader::LoadID() { void LegacyCstLoader::LoadID() {
@ -120,7 +164,8 @@ void LegacyCoreLoader::DoLoad(ccl::semantic::RSCore& core) {
} }
ccl::lang::ManagedText LegacyCoreLoader::LoadText() { ccl::lang::ManagedText LegacyCoreLoader::LoadText() {
const auto rawText = ar.Load<std::string>(); auto rawText = ar.Load<std::string>();
details::FixOldReferences(rawText);
const auto cache = ar.Load<std::string>(); const auto cache = ar.Load<std::string>();
return ccl::lang::ManagedText{ rawText, cache }; return ccl::lang::ManagedText{ rawText, cache };
} }
@ -129,8 +174,9 @@ ccl::lang::LexicalTerm LegacyCoreLoader::LoadTerm() {
using ccl::lang::TERM_FORMS; using ccl::lang::TERM_FORMS;
ccl::lang::LexicalTerm term{ LoadText() }; ccl::lang::LexicalTerm term{ LoadText() };
for (uint8_t j = 0; j < size(TERM_FORMS); ++j) { for (uint8_t j = 0; j < size(TERM_FORMS); ++j) {
const auto manualForm = ar.Load<std::string>(); auto manualForm = ar.Load<std::string>();
if (!std::empty(manualForm)) { if (!std::empty(manualForm)) {
details::FixOldReferences(manualForm);
term.SetForm(TERM_FORMS.at(j), manualForm); term.SetForm(TERM_FORMS.at(j), manualForm);
} }
} }

Binary file not shown.

View File

@ -152,7 +152,7 @@ TEST_F(UTDocuments, RSModelSaveLoad) {
TEST_F(UTDocuments, RSModelCalculate) { TEST_F(UTDocuments, RSModelCalculate) {
MockRSModelDoc document{}; MockRSModelDoc document{};
const auto filePath = ::LocalPathToGlobal(LR"(Data\Тест_Модели\TestCalculate.rsm)"); const auto filePath = ::LocalPathToGlobal(LR"(Data\Model\TestCalculate.rsm)");
ASSERT_TRUE(document.LoadFrom(filePath)); ASSERT_TRUE(document.LoadFrom(filePath));
document.model->Calculations().RecalculateAll(); document.model->Calculations().RecalculateAll();
EXPECT_EQ(document.model->Calculations().Count(ccl::semantic::EvalStatus::AXIOM_FAIL), 0U); EXPECT_EQ(document.model->Calculations().Count(ccl::semantic::EvalStatus::AXIOM_FAIL), 0U);