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
11#include "simodo/inout/convert/functions.h"
12
13namespace simodo::inout
14{
15void Reporter_abstract::reportWithPosition(const SeverityLevel level, const Location &location, const std::string &briefly, const std::string &atlarge)
16{
17report( level,
18location,
19briefly,
20atlarge.empty() ? ("Позиция разбора: " + getLocationString(location)) : atlarge);
21}
22
23const char * getSeverityLevelName(const SeverityLevel level)
24{
25switch(level)
26{
27case SeverityLevel::Information:
28return "";
29case SeverityLevel::Warning:
30return "Предупреждение: ";
31case SeverityLevel::Error:
32return "Ошибка: ";
33case SeverityLevel::Fatal:
34return "Сбой! ";
35}
36return "";
37}
38
39std::string getLocationString(const Location &location, bool in_detail)
40{
41/// \todo Нужно убрать лишнее преобразование кодировок
42std::string str = location.uri()
43+ ":" + std::to_string(static_cast<unsigned>(location.range().start().line()+1))
44+ ":" + std::to_string(static_cast<unsigned>(location.range().start().character()+1));
45
46if (in_detail)
47str += "[" + std::to_string(location.range().end().line()+1)
48+ "," + std::to_string(location.range().end().character()+1)
49+ "]";
50
51return str;
52}
53
54}