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 {
8
13
14 CompileError() : _message("Empty message! If this isn't a test, debug this."), _line(0), _column(0) {}
15 explicit CompileError(std::string &&string, size_t line = 0, size_t column = 0)
16 : _message(std::move(string)), _line(line), _column(column) {}
17 explicit CompileError(const std::string &string, size_t line = 0, size_t column = 0)
18 : _message(string), _line(line), _column(column) {}
19
20 CompileError(const CompileError &) = default;
22
23 CompileError &operator=(const CompileError &) = default;
25
26 std::string _message;
27 size_t _line;
28 size_t _column;
29
30 // const std::string &message() const { return _message; }
31 size_t line() const { return _line; }
32 size_t column() const { return _column; }
33
34 std::string message() const { return std::format("[line {}:{}] CompilerError: {}", _line, _column, _message); }
35};
36
41template <typename T> using Result = std::expected<T, CompileError>;
42
43} // namespace picceler
Definition ast.h:11
std::expected< T, CompileError > Result
A type alias for the result of a compilation operation.
Definition error.h:41
size_t _column
Definition error.h:28
CompileError & operator=(CompileError &&)=default
std::string _message
Definition error.h:26
CompileError & operator=(const CompileError &)=default
size_t column() const
Definition error.h:32
size_t line() const
Definition error.h:31
CompileError()
Definition error.h:14
CompileError(std::string &&string, size_t line=0, size_t column=0)
Definition error.h:15
size_t _line
Definition error.h:27
CompileError(const std::string &string, size_t line=0, size_t column=0)
Definition error.h:17
std::string message() const
Definition error.h:34
CompileError(CompileError &&)=default
CompileError(const CompileError &)=default