F: Improve old reference loading
This commit is contained in:
parent
e4727b52ab
commit
d456220006
|
@ -1,3 +1,5 @@
|
|||
30.08.2024 Экстеор 4.9.4
|
||||
• исправлена загрузка файлов версий 2017-2020 годов
|
||||
14.06.2024 Экстеор 4.9.3
|
||||
• Грамматика: разрешено использование одного аргумента для мультифильтра - Fi1,2[X1*X1](S1)
|
||||
• исправлена ошибка, приводившая к некорректному вычислению типизаций рекурсии с пустым множеством
|
||||
|
|
|
@ -1182,8 +1182,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 4,9,3,1000
|
||||
PRODUCTVERSION 4,9,3,1000
|
||||
FILEVERSION 4,9,4,1000
|
||||
PRODUCTVERSION 4,9,4,1000
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -1201,13 +1201,13 @@ BEGIN
|
|||
VALUE "Comments", "Ýêñïëèêàòîð òåîðèé "
|
||||
VALUE "CompanyName", "ÍÏ ÖÈÂÒ ÊÎÍÖÅÏÒ"
|
||||
VALUE "FileDescription", "Ýêñòåîð 4.9"
|
||||
VALUE "FileVersion", "4.9.3.1000"
|
||||
VALUE "FileVersion", "4.9.4.1000"
|
||||
VALUE "InternalName", "Ýêñòåîð 4.9"
|
||||
VALUE "LegalCopyright", "Copyright © NPMP CIHT CONCEPT 1994-2024"
|
||||
VALUE "LegalTrademarks", "Ýêñòåîð™"
|
||||
VALUE "OriginalFilename", "Exteor.exe"
|
||||
VALUE "ProductName", "Ýêñòåîð 4.9"
|
||||
VALUE "ProductVersion", "4.9.3.1000"
|
||||
VALUE "ProductVersion", "4.9.4.1000"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
|
||||
#include "xtr/core/Encoder.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <regex>
|
||||
#include <algorithm>
|
||||
|
||||
using ccl::semantic::ConceptRecord;
|
||||
using ccl::semantic::CstType;
|
||||
using ccl::lang::ManagedText;
|
||||
|
@ -11,6 +16,40 @@ using ccl::lang::LexicalTerm;
|
|||
|
||||
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) {
|
||||
const auto sName = 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
const auto formText = mfc::ToSTL(termForms.at(0).at(j));
|
||||
if (!formText.empty()) {
|
||||
cst->term.SetForm(TERM_FORMS.at(j), formText);
|
||||
auto manualForm = mfc::ToSTL(termForms.at(0).at(j));
|
||||
if (!manualForm.empty()) {
|
||||
details::FixOldReferences(manualForm);
|
||||
cst->term.SetForm(TERM_FORMS.at(j), manualForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +133,9 @@ void LegacyCstLoader::LoadInterpretation(const BOOL loadWithRef) {
|
|||
if (needEncoding) {
|
||||
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() {
|
||||
|
@ -120,7 +164,8 @@ void LegacyCoreLoader::DoLoad(ccl::semantic::RSCore& core) {
|
|||
}
|
||||
|
||||
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>();
|
||||
return ccl::lang::ManagedText{ rawText, cache };
|
||||
}
|
||||
|
@ -129,8 +174,9 @@ ccl::lang::LexicalTerm LegacyCoreLoader::LoadTerm() {
|
|||
using ccl::lang::TERM_FORMS;
|
||||
ccl::lang::LexicalTerm term{ LoadText() };
|
||||
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)) {
|
||||
details::FixOldReferences(manualForm);
|
||||
term.SetForm(TERM_FORMS.at(j), manualForm);
|
||||
}
|
||||
}
|
||||
|
|
BIN
test/Data/Model/TestCalculate.rsm
Normal file
BIN
test/Data/Model/TestCalculate.rsm
Normal file
Binary file not shown.
Binary file not shown.
|
@ -152,7 +152,7 @@ TEST_F(UTDocuments, RSModelSaveLoad) {
|
|||
|
||||
TEST_F(UTDocuments, RSModelCalculate) {
|
||||
MockRSModelDoc document{};
|
||||
const auto filePath = ::LocalPathToGlobal(LR"(Data\Тест_Модели\TestCalculate.rsm)");
|
||||
const auto filePath = ::LocalPathToGlobal(LR"(Data\Model\TestCalculate.rsm)");
|
||||
ASSERT_TRUE(document.LoadFrom(filePath));
|
||||
document.model->Calculations().RecalculateAll();
|
||||
EXPECT_EQ(document.model->Calculations().Count(ccl::semantic::EvalStatus::AXIOM_FAIL), 0U);
|
||||
|
|
Loading…
Reference in New Issue
Block a user