loom
1/*
2MIT License
3
4Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
5
6https://bmstu.codes/lsx/simodo
7*/
8
9#include "simodo/inout/reporter/Reporter_abstract.h"
10#include "simodo/inout/convert/functions.h"
11
12namespace simodo::inout
13{
14void Reporter_abstract::reportWithPosition(const SeverityLevel level, const Location &location, const std::string &briefly, const std::string &atlarge) const
15{
16report( level,
17location,
18briefly,
19atlarge.empty() ? ("Позиция разбора: " + getLocationString(location)) : atlarge);
20}
21
22const char * getSeverityLevelName(const SeverityLevel level)
23{
24switch(level)
25{
26case SeverityLevel::Information:
27return "";
28case SeverityLevel::Warning:
29return "Предупреждение: ";
30case SeverityLevel::Error:
31return "Ошибка: ";
32case SeverityLevel::Fatal:
33return "Сбой! ";
34}
35return "";
36}
37
38std::string getLocationString(const Location &location, bool in_detail)
39{
40/// \todo Нужно убрать лишнее преобразование кодировок
41std::string str = location.uri()
42+ ":" + std::to_string(static_cast<unsigned>(location.range().start().line()+1))
43+ ":" + std::to_string(static_cast<unsigned>(location.range().start().character()+1));
44
45if (in_detail)
46str += "[" + std::to_string(location.range().end().line()+1)
47+ "," + std::to_string(location.range().end().character()+1)
48+ "]";
49
50return str;
51}
52
53}