4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo
9
#include "simodo/engine/utility/common_functions.h"
10
#include "simodo/inout/convert/functions.h"
11
#include "simodo/inout/reporter/Reporter_abstract.h"
16
namespace simodo::engine
18
std::string getMnemonic(const inout::Lexeme &lex, bool abstract_lexeme)
24
case inout::LexemeType::Empty:
27
case inout::LexemeType::Compound:
28
mnemonic = inout::toU8(lex.lexeme());
30
case inout::LexemeType::Punctuation:
31
mnemonic = "'" + inout::toU8(lex.lexeme()) + "'";
33
case inout::LexemeType::Id:
34
mnemonic = abstract_lexeme ? "ID" : inout::toU8(lex.lexeme());
36
case inout::LexemeType::Annotation:
37
mnemonic = abstract_lexeme ? "ANNOTATION" : ("\"" + inout::toU8(lex.lexeme()) + "\"");
39
case inout::LexemeType::Number:
40
mnemonic = abstract_lexeme ? "NUMBER" : inout::toU8(lex.lexeme());
42
case inout::LexemeType::Comment:
45
case inout::LexemeType::Error:
58
void shiftString(int level, int shift, std::string str)
60
for(int i=0; i < shift; ++i)
63
for(int i=0; i < level; ++i)
67
std::cout << str << std::endl;
71
void printSemanticTree(const ast::Node & ast, const inout::uri_set_t & files, int level, int shift)
73
shiftString(level, shift, "{");
75
for(const ast::Node & n : ast.branches())
77
shiftString(level, shift, "");
80
<< n.operation() << " \""
81
<< inout::toU8(n.token().lexeme()) << "\"";
83
std::cout << "\t// " << getLocationString(n.bound().makeLocation(files),true) << std::endl;
85
if (!n.branches().empty())
86
printSemanticTree(n,files, level+1,shift);
89
shiftString(level, shift, "}");
92
void replaceAll(std::string &str, const std::string &from, const std::string &to)
98
while((start_pos = str.find(from, start_pos)) != std::string::npos)
100
str.replace(start_pos, from.length(), to);
101
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
105
std::string toHtml(std::string text)
107
replaceAll(text, "&", "&");
108
replaceAll(text, "<", "<");
109
replaceAll(text, ">", ">");