diff --git a/libs/AutomatonToImage/src/AutomatonToImage.cpp b/libs/AutomatonToImage/src/AutomatonToImage.cpp index 9e731e58..1d2d99bd 100644 --- a/libs/AutomatonToImage/src/AutomatonToImage.cpp +++ b/libs/AutomatonToImage/src/AutomatonToImage.cpp @@ -1,17 +1,42 @@ #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::vector; AutomatonToImage::AutomatonToImage() {} AutomatonToImage::~AutomatonToImage() {} +string replace_before_dot2tex(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 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; @@ -32,13 +57,13 @@ 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; + 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 > " "error_Postprocess.raux " "2>&1"); @@ -67,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 720d12f6..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]; @@ -245,16 +244,11 @@ 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"; + table += row + "\\\\\n"; } table += "\\end{array}$\n"; return table; 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..d558c513 100644 --- a/refal/MathMode.ref +++ b/refal/MathMode.ref @@ -14,8 +14,11 @@ $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 (']')(']')) - (NOREGEX ('LANG')('\\Lang'))(OK ('\\&')('\\memref'))(NOREGEX ('\\textasciicircum')('\\mathbf{\\textasciicircum}\\hspace{-0.2ex}')) + (OK ('UNION')('\\cup'))(OK ('\\{')('\\{'))(OK ('\\}')('\\}'))(OK ('{')('\\{'))(OK ('}')('\\}'))(OK ('[[')('{'))(OK (']]')('}')) + (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,14 @@ 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 = ' & '; + e.x'\\\\'e.y = '\\regexpstr{'e.x' }\\\\'; + = ; + e.y = '\\regexpstr{'e.y' }'; } AdjustSpaceBeforeStar { @@ -250,7 +260,7 @@ $ENTRY NonASCII { } $ENTRY ASCIIStandard { - = '$%&*()-_=+`~!@#;:\'\"<>,./?[]{}\\|^ \t\n'; + = '$%&*()-_=+`~!@#;:\'\"<>,./?[]{}\\|^ \t\n\r'; } $ENTRY Nempty {