picceler
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1#pragma once
2
3#include <expected>
4#include <string>
5#include <format>
6
7namespace picceler {
9
10 CompileError() : _message("Empty message! If this isn't a test, debug this."), _line(0), _column(0) {}
11 explicit CompileError(std::string &&string, size_t line = 0, size_t column = 0)
12 : _message(std::move(string)), _line(line), _column(column) {}
13 explicit CompileError(const std::string &string, size_t line = 0, size_t column = 0)
14 : _message(string), _line(line), _column(column) {}
15
16 CompileError(const CompileError &) = default;
18
19 CompileError &operator=(const CompileError &) = default;
21
22 std::string _message;
23 size_t _line;
24 size_t _column;
25
26 const std::string &message() const { return _message; }
27 size_t line() const { return _line; }
28 size_t column() const { return _column; }
29
30 std::string format() const { return std::format("[line {}:{}] CompilerError: {}", _line, _column, _message); }
31};
32
33template <typename T> using Result = std::expected<T, CompileError>;
34
35} // namespace picceler
Definition ast.h:11
std::expected< T, CompileError > Result
Definition error.h:33
size_t _column
Definition error.h:24
CompileError & operator=(CompileError &&)=default
std::string _message
Definition error.h:22
CompileError & operator=(const CompileError &)=default
size_t column() const
Definition error.h:28
size_t line() const
Definition error.h:27
CompileError()
Definition error.h:10
CompileError(std::string &&string, size_t line=0, size_t column=0)
Definition error.h:11
size_t _line
Definition error.h:23
std::string format() const
Definition error.h:30
const std::string & message() const
Definition error.h:26
CompileError(const std::string &string, size_t line=0, size_t column=0)
Definition error.h:13
CompileError(CompileError &&)=default
CompileError(const CompileError &)=default