elna/source/elna/lexer.d

56 lines
1.2 KiB
D

module elna.lexer;
import core.stdc.string;
import elna.result;
extern(C++, "elna")
struct Token
{
enum Type : ushort
{
number = 0,
operator = 1,
let = 2,
identifier = 3,
equals = 4,
var = 5,
semicolon = 6,
leftParen = 7,
rightParen = 8,
bang = 9,
dot = 10,
comma = 11,
}
union Value
{
int number;
const(char)* identifier;
}
private Type type;
private Value value_;
private Position position_;
@disable this();
this(Type type, Position position) @nogc nothrow pure @safe;
this(Type type, int value, Position position) @nogc nothrow pure @trusted;
this(Type type, const(char)* value, Position position) @nogc nothrow;
/**
* Returns: Expected token type.
*/
Type of() const @nogc nothrow pure @safe;
const(char)* identifier() const @nogc nothrow pure;
int number() const @nogc nothrow pure;
/**
* Returns: The token position in the source text.
*/
@property const(Position) position() const @nogc nothrow pure @safe;
}
extern(C++, "elna")
Token* lex(const(char)* buffer, CompileError* compileError, size_t* length) @nogc;