99 lines
1.6 KiB
D
99 lines
1.6 KiB
D
module elna.result;
|
|
|
|
import std.typecons;
|
|
import tanya.container.array;
|
|
import tanya.container.string;
|
|
|
|
/**
|
|
* Position in the source text.
|
|
*/
|
|
extern(C++, "elna")
|
|
struct Position
|
|
{
|
|
/// Line.
|
|
size_t line = 1;
|
|
|
|
/// Column.
|
|
size_t column = 1;
|
|
}
|
|
|
|
extern(C++, "elna")
|
|
struct CompileError
|
|
{
|
|
private const(char)* message_;
|
|
|
|
private Position position_;
|
|
|
|
@disable this();
|
|
|
|
/**
|
|
* Params:
|
|
* message = Error text.
|
|
* position = Error position in the source text.
|
|
*/
|
|
this(const(char)* message, const Position position) @nogc nothrow pure @safe;
|
|
|
|
/// Error text.
|
|
@property const(char)* what() const @nogc nothrow pure @safe;
|
|
|
|
/// Error line in the source text.
|
|
@property size_t line() const @nogc nothrow pure @safe;
|
|
|
|
/// Error column in the source text.
|
|
@property size_t column() const @nogc nothrow pure @safe;
|
|
}
|
|
|
|
struct Result(T)
|
|
{
|
|
Nullable!CompileError error;
|
|
T result;
|
|
|
|
this(T result)
|
|
{
|
|
this.result = result;
|
|
this.error = typeof(this.error).init;
|
|
}
|
|
|
|
this(const(char)* message, Position position)
|
|
{
|
|
this.result = T.init;
|
|
this.error = CompileError(message, position);
|
|
}
|
|
|
|
this(CompileError compileError)
|
|
{
|
|
this.result = null;
|
|
this.error = compileError;
|
|
}
|
|
|
|
@disable this();
|
|
|
|
@property bool valid() const
|
|
{
|
|
return error.isNull;
|
|
}
|
|
}
|
|
|
|
extern(C++, "elna")
|
|
enum Target
|
|
{
|
|
text,
|
|
high20,
|
|
lower12i
|
|
}
|
|
|
|
extern(C++, "elna")
|
|
struct Reference
|
|
{
|
|
const(char)* name;
|
|
size_t offset;
|
|
Target target;
|
|
}
|
|
|
|
struct Symbol
|
|
{
|
|
String name;
|
|
Array!ubyte text;
|
|
Array!Reference symbols;
|
|
}
|