Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Diagnostics::ThrowSyntaxError(const std::string& error, const std::size_t selection) const {
- std::array<std::size_t, 2> position = map(selection);
- std::cerr << "\033[1;31mSyntax error\033[0m at line " << "\033[0;32m" + std::to_string(position[0] + 1) + "\033[0m" << ", column " << "\033[0;32m" + std::to_string(position[1] + 1) + "\033[0m" << ":\n" << error << std::endl;
- constexpr std::size_t distance = 10;
- std::size_t start = selection - distance;
- std::size_t end = selection + distance;
- if (position[1] < distance) {
- start = selection - position[1];
- }
- if (position[1] + distance >= lines[position[0]]) {
- end = selection + lines[position[0]] - position[1];
- }
- std::string peekCode = "";
- for (std::size_t index = start; index < end + 1; index += 1) {
- peekCode += (*code)[index];
- }
- std::cout << "\"" << peekCode << "\"" << std::endl;
- for (std::size_t index = 0; index < selection - start; index += 1) {
- std::cout << " ";
- }
- std::cout << "\033[1;32m~~~\033[0m" << std::endl;
- Fail();
- }
- void Diagnostics::Fail() const {
- End(-1.0);
- exit(1);
- }
- void Diagnostics::End(const double time) const {
- int exitCode = 1;
- if (time >= 0.0) {
- std::cout << "\nTranspile time: \033[0;32m" + std::to_string(time) + "\033[0m seconds." << std::endl;
- exitCode = 0;
- }
- std::cout << "\nExited with exit code: \033[1;31m" + std::to_string(exitCode) + "\033[0m." << std::endl;
- enclose();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement