From a3a48358253c9dea0dd3661118073c976c205a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=BD=D0=B0=20=D0=A2=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8C=D0=B5=D0=B2=D0=B0?= Date: Mon, 17 Jun 2024 19:35:46 +0300 Subject: [PATCH 1/5] (#345) Cyr-fix --- refal/FrameFormatter.ref | 11 +++++++++-- refal/MathMode.ref | 5 ++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/refal/FrameFormatter.ref b/refal/FrameFormatter.ref index 14f6a60c..bd7433a4 100644 --- a/refal/FrameFormatter.ref +++ b/refal/FrameFormatter.ref @@ -128,7 +128,14 @@ FindSeparator { TakePrefix { 0 e.Rest = (e.Rest); s.Size = (); - s.Length s.Sym e.Rest = s.Sym > e.Rest>; + s.Length s.Sym e.Rest + , : + { e.A1 s.Sym e.A2 = s.Sym > e.Rest>; + e.A + , e.Rest : s.S1 e.Rest1 + = s.Sym s.S1 >> e.Rest1>; + e.A = s.Sym (); + }; } Weight { @@ -772,4 +779,4 @@ ChooseContent { = ; -} +} \ No newline at end of file diff --git a/refal/MathMode.ref b/refal/MathMode.ref index 739941ac..ceaa62cf 100644 --- a/refal/MathMode.ref +++ b/refal/MathMode.ref @@ -14,7 +14,7 @@ $ENTRY Trim { /* Hacked derivatives. TODO: parameterize by indices activation */ SpecialSymbolList { = (NOREGEX ('eps')('\\empt'))(NOREGEX ('DERIV')('\\delta_'))(OK ('FIRST')('\\First'))(OK ('FOLLOW')('\\Follow'))(OK ('LAST')('\\Last')) - (OK ('UNION')('\\cup'))(OK ('\\{')('\\{'))(OK ('\\}')('\\}'))(OK ('{')('\\{'))(OK ('}')('\\}'))(OK ('[')('['))(OK (']')(']')) + (OK ('UNION')('\\cup'))(OK ('\\{')('\\{'))(OK ('\\}')('\\}'))(OK ('{')('\\{'))(OK ('}')('\\}'))(OK ('[[')('{'))(OK (']]')('}')) (NOREGEX ('LANG')('\\Lang'))(OK ('\\&')('\\memref'))(NOREGEX ('\\textasciicircum')('\\mathbf{\\textasciicircum}\\hspace{-0.2ex}')) (OK ('>->>')('\\transit'))(MEM ('MEMLOPEN') ('\\langle o:\\,'))(MEM ('MEMR')('\\rangle'))(MEM ('MEMLCLOSE')('\\langle c:\\,')); @@ -250,7 +250,7 @@ $ENTRY NonASCII { } $ENTRY ASCIIStandard { - = '$%&*()-_=+`~!@#;:\'\"<>,./?[]{}\\|^ \t\n'; + = '$%&*()-_=+`~!@#;:\'\"<>,./?[]{}\\|^ \t\n\r'; } $ENTRY Nempty { @@ -273,4 +273,3 @@ $ENTRY Max { s.Rest = s.2; }; } - From dad028fa6c181cc0124051499625b5bd7e3a61bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=BD=D0=B0=20=D0=A2=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8C=D0=B5=D0=B2=D0=B0?= <79749959+mathhyyn@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:32:53 +0300 Subject: [PATCH 2/5] (#345) & -> #& ^ -> #^ --- .../AutomatonToImage/src/AutomatonToImage.cpp | 29 ++++++++++++++++--- libs/Logger/src/LogTemplate.cpp | 11 ++----- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libs/AutomatonToImage/src/AutomatonToImage.cpp b/libs/AutomatonToImage/src/AutomatonToImage.cpp index 9e731e58..19ce80cf 100644 --- a/libs/AutomatonToImage/src/AutomatonToImage.cpp +++ b/libs/AutomatonToImage/src/AutomatonToImage.cpp @@ -1,17 +1,35 @@ #include #include #include +#include +#include #include "AutomatonToImage/AutomatonToImage.h" using std::ifstream; using std::string; using std::stringstream; +using std::cout; +using std::ofstream; +using std::vector; AutomatonToImage::AutomatonToImage() {} AutomatonToImage::~AutomatonToImage() {} +string replace_for_rendering2(const string& s) { + vector> substrs_to_replace = {{"\\^", "#^ "}, + {"&", "#&"}}; + + string result = s; + for (const auto& [old_substr, new_substr] : substrs_to_replace) { + std::regex re(old_substr); + result = std::regex_replace(result, re, new_substr); + } + + return result; +} + void remove_file(string dir, string file, bool guarded = false) { stringstream command; command << "cd " << dir; @@ -32,13 +50,16 @@ void remove_file(string dir, string file, bool guarded = false) { string AutomatonToImage::to_image(string automaton) { remove_file("refal", "Meta_log.raux", true); remove_file("refal", "Aux_input.raux", true); - FILE* fo; - fo = fopen("./refal/input.dot", "wt"); - fprintf(fo, "%s", automaton.c_str()); - fclose(fo); + ofstream fo; + fo.open("./refal/input.dot", ofstream::trunc); + if (fo.is_open()) + fo << replace_for_rendering2(automaton); + fo.close(); system("cd refal && refgo Preprocess+MathMode+FrameFormatter input.dot > " "error_Preprocess.raux"); + system("cd refal && dot2tex -ftikz -tmath \"Mod_input.dot\" > input.tex"); + system("cd refal && refgo Postprocess+MathMode+FrameFormatter input.tex > " "error_Postprocess.raux " "2>&1"); diff --git a/libs/Logger/src/LogTemplate.cpp b/libs/Logger/src/LogTemplate.cpp index 720d12f6..a52e09e1 100644 --- a/libs/Logger/src/LogTemplate.cpp +++ b/libs/Logger/src/LogTemplate.cpp @@ -145,7 +145,7 @@ string LogTemplate::render() const { automaton = std::get(param.value).to_txt(); else automaton = std::get(param.value).to_txt(); - automaton = replace_for_rendering(automaton); + // automaton = replace_for_rendering(automaton); size_t hash = hasher(automaton); if (cache_automatons.count(hash) != 0) { c_graph = cache_automatons[hash]; @@ -245,14 +245,9 @@ string LogTemplate::log_table(Table t) { table += "$\\begin{array}{" + format + "}\\rowcolor{HeaderColor}\n"; table += cols + "\\hline\n"; for (int i = 0; i < t.rows.size(); i++) { - string r = t.rows[i] == " " ? "eps" : t.rows[i]; - row = r + " & "; + row = t.rows[i] == " " ? "eps" : t.rows[i]; for (int j = 0; j < t.columns.size(); j++) { - if (j != t.columns.size() - 1) { - row = row + t.data[i * t.columns.size() + j] + " &"; - } else { - row = row + t.data[i * t.columns.size() + j] + "\\\\"; - } + row += " & " + replace_for_rendering(t.data[i * t.columns.size() + j]); } table += row + "\n"; } From b82f21c561011b7fdf27023740b8b5bae2cc4b7c Mon Sep 17 00:00:00 2001 From: TonitaN Date: Mon, 17 Jun 2024 22:49:59 +0300 Subject: [PATCH 3/5] =?UTF-8?q?(#345)=20=D0=9E=D0=B1=D1=91=D1=80=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D0=BE=D1=81=D1=82=D1=80=D0=BE=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=20+=20=D0=BC=D0=B0=D0=BA=D1=80=D0=BE=D1=81=D1=8B=20&^?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Logger/src/LogTemplate.cpp | 2 +- refal/MathMode.ref | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libs/Logger/src/LogTemplate.cpp b/libs/Logger/src/LogTemplate.cpp index a52e09e1..e05172b3 100644 --- a/libs/Logger/src/LogTemplate.cpp +++ b/libs/Logger/src/LogTemplate.cpp @@ -249,7 +249,7 @@ string LogTemplate::log_table(Table t) { for (int j = 0; j < t.columns.size(); j++) { row += " & " + replace_for_rendering(t.data[i * t.columns.size() + j]); } - table += row + "\n"; + table += row + "\\\\\n"; } table += "\\end{array}$\n"; return table; diff --git a/refal/MathMode.ref b/refal/MathMode.ref index ceaa62cf..abd6dfcb 100644 --- a/refal/MathMode.ref +++ b/refal/MathMode.ref @@ -15,7 +15,10 @@ $ENTRY Trim { SpecialSymbolList { = (NOREGEX ('eps')('\\empt'))(NOREGEX ('DERIV')('\\delta_'))(OK ('FIRST')('\\First'))(OK ('FOLLOW')('\\Follow'))(OK ('LAST')('\\Last')) (OK ('UNION')('\\cup'))(OK ('\\{')('\\{'))(OK ('\\}')('\\}'))(OK ('{')('\\{'))(OK ('}')('\\}'))(OK ('[[')('{'))(OK (']]')('}')) - (NOREGEX ('LANG')('\\Lang'))(OK ('\\&')('\\memref'))(NOREGEX ('\\textasciicircum')('\\mathbf{\\textasciicircum}\\hspace{-0.2ex}')) + (NOREGEX ('LANG')('\\Lang')) + (OK ('#&')('\\memref'))(OK ('\\&')('\\memref')) + (NOREGEX ('#^')('\\mathbf{\\textasciicircum}\\hspace{-0.2ex}')) + (NOREGEX ('\\textasciicircum')('\\mathbf{\\textasciicircum}\\hspace{-0.2ex}')) (OK ('>->>')('\\transit'))(MEM ('MEMLOPEN') ('\\langle o:\\,'))(MEM ('MEMR')('\\rangle'))(MEM ('MEMLCLOSE')('\\langle c:\\,')); } @@ -43,10 +46,10 @@ SeparateModes { , )(s.1)>)s.2> : {True True = ; - e.OtherValues = '\\regexpstr{'' }' e.Image; + e.OtherValues = > e.Image; }; = e.Image; - e.Nempt = '\\regexpstr{'' }' e.Image; + e.Nempt = > e.Image; }; MEM = ; OK = ; @@ -57,7 +60,7 @@ SeparateModes { False , : { = ; - e.Nempty = '\\regexpstr{'' }'; + e.Nempty = >; }; }; (e.Spec) Text (e.Prefix) s.Sym e.Rest @@ -75,7 +78,13 @@ SeparateModes { }; (e.Spec) Text (e.Prefix) = '\\text{'e.Prefix' }'; (e.Spec) Normal ( ) = ; - (e.Spec) Normal (e.Prefix) = '\\regexpstr{'' }'; + (e.Spec) Normal (e.Prefix) = >; +} + +WrapInRegexpstr { + e.x'\\\\'e.y = '\\regexpstr{'e.x' }\\\\'; + = ; + e.y = '\\regexpstr{'e.y' }'; } AdjustSpaceBeforeStar { @@ -273,3 +282,4 @@ $ENTRY Max { s.Rest = s.2; }; } + From 44e03204cb3517630bb1d6fb2ed6a627deb2f47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=BD=D0=B0=20=D0=A2=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8C=D0=B5=D0=B2=D0=B0?= Date: Tue, 18 Jun 2024 01:55:56 +0300 Subject: [PATCH 4/5] (#299) write_to_file and review fix --- .../AutomatonToImage/src/AutomatonToImage.cpp | 36 +++++++++---------- libs/Logger/src/LogTemplate.cpp | 1 - 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/libs/AutomatonToImage/src/AutomatonToImage.cpp b/libs/AutomatonToImage/src/AutomatonToImage.cpp index 19ce80cf..1d2d99bd 100644 --- a/libs/AutomatonToImage/src/AutomatonToImage.cpp +++ b/libs/AutomatonToImage/src/AutomatonToImage.cpp @@ -1,25 +1,24 @@ #include #include +#include #include #include -#include #include "AutomatonToImage/AutomatonToImage.h" +using std::cout; using std::ifstream; +using std::ofstream; using std::string; using std::stringstream; -using std::cout; -using std::ofstream; using std::vector; AutomatonToImage::AutomatonToImage() {} AutomatonToImage::~AutomatonToImage() {} -string replace_for_rendering2(const string& s) { - vector> substrs_to_replace = {{"\\^", "#^ "}, - {"&", "#&"}}; +string replace_before_dot2tex(const string& s) { + vector> substrs_to_replace = {{"\\^", "#^ "}, {"&", "#&"}}; string result = s; for (const auto& [old_substr, new_substr] : substrs_to_replace) { @@ -30,6 +29,14 @@ string replace_for_rendering2(const string& s) { return result; } +void write_to_file(const string& file_name, const string& content) { + ofstream file; + file.open(file_name, ofstream::trunc); + if (file.is_open()) + file << replace_before_dot2tex(content); + file.close(); +} + void remove_file(string dir, string file, bool guarded = false) { stringstream command; command << "cd " << dir; @@ -51,13 +58,10 @@ string AutomatonToImage::to_image(string automaton) { remove_file("refal", "Meta_log.raux", true); remove_file("refal", "Aux_input.raux", true); ofstream fo; - fo.open("./refal/input.dot", ofstream::trunc); - if (fo.is_open()) - fo << replace_for_rendering2(automaton); - fo.close(); + write_to_file("./refal/input.dot", replace_before_dot2tex(automaton)); system("cd refal && refgo Preprocess+MathMode+FrameFormatter input.dot > " "error_Preprocess.raux"); - + system("cd refal && dot2tex -ftikz -tmath \"Mod_input.dot\" > input.tex"); system("cd refal && refgo Postprocess+MathMode+FrameFormatter input.tex > " @@ -88,16 +92,10 @@ string AutomatonToImage::to_image(string automaton) { string AutomatonToImage::colorize(string automaton, string metadata) { - FILE* fo; - FILE* md; ifstream infile_for_Final; - fo = fopen("./refal/Col_input.tex", "wt"); - fprintf(fo, "%s", automaton.c_str()); - fclose(fo); + write_to_file("./refal/Col_input.tex", automaton); if (metadata != "") { - md = fopen("./refal/Meta_input.raux", "wt"); - fprintf(md, "%s", metadata.c_str()); - fclose(md); + write_to_file("./refal/Meta_input.raux", metadata); system("cd refal && refgo Colorize+MathMode Col_input.tex > " "error_Colorize.raux"); infile_for_Final.open("./refal/Final_input.tex"); diff --git a/libs/Logger/src/LogTemplate.cpp b/libs/Logger/src/LogTemplate.cpp index e05172b3..34a6c93b 100644 --- a/libs/Logger/src/LogTemplate.cpp +++ b/libs/Logger/src/LogTemplate.cpp @@ -145,7 +145,6 @@ string LogTemplate::render() const { automaton = std::get(param.value).to_txt(); else automaton = std::get(param.value).to_txt(); - // automaton = replace_for_rendering(automaton); size_t hash = hasher(automaton); if (cache_automatons.count(hash) != 0) { c_graph = cache_automatons[hash]; From 06f33f7b94645e2d903f767ce79ce7facd1d9db9 Mon Sep 17 00:00:00 2001 From: TonitaN Date: Mon, 17 Jun 2024 23:28:50 +0300 Subject: [PATCH 5/5] =?UTF-8?q?(#345)=20=D0=A0=D0=B0=D0=B7=D1=80=D0=B5?= =?UTF-8?q?=D1=88=D0=B0=D0=B5=D0=BC=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20?= =?UTF-8?q?=D0=B1=D0=B8=D1=82=D1=8C=D1=81=D1=8F=20=D0=BF=D0=BE=20=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=BB=D0=B1=D1=86=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- refal/MathMode.ref | 1 + 1 file changed, 1 insertion(+) diff --git a/refal/MathMode.ref b/refal/MathMode.ref index abd6dfcb..d558c513 100644 --- a/refal/MathMode.ref +++ b/refal/MathMode.ref @@ -82,6 +82,7 @@ SeparateModes { } WrapInRegexpstr { + e.x' & 'e.y = ' & '; e.x'\\\\'e.y = '\\regexpstr{'e.x' }\\\\'; = ; e.y = '\\regexpstr{'e.y' }';