Token
- Moved to own module Exceptions (Lexer) - Moved to own module Misc - Fixed up imports for new `tokens` and `exceptions` (lexer) modulesremove_typequeue
parent
73c70fbb71
commit
712f049306
@ -0,0 +1,30 @@
|
||||
module compiler.lexer.exceptions;
|
||||
|
||||
import misc.exceptions : TError;
|
||||
import compiler.lexer.core : Lexer;
|
||||
import std.conv : to;
|
||||
|
||||
public enum LexerError
|
||||
{
|
||||
EXHAUSTED_CHARACTERS,
|
||||
OTHER
|
||||
}
|
||||
|
||||
public final class LexerException : TError
|
||||
{
|
||||
public const Lexer offendingInstance;
|
||||
public const LexerError errType;
|
||||
|
||||
this(Lexer offendingInstance, LexerError errType = LexerError.OTHER, string msg = "")
|
||||
{
|
||||
string positionString = "("~to!(string)(offendingInstance.getLine())~", "~to!(string)(offendingInstance.getColumn())~")";
|
||||
super("LexerException("~to!(string)(errType)~")"~(msg.length ? ": "~msg : "")~" at "~positionString);
|
||||
this.offendingInstance = offendingInstance;
|
||||
this.errType = errType;
|
||||
}
|
||||
|
||||
this(Lexer offendingInstance, string msg)
|
||||
{
|
||||
this(offendingInstance, LexerError.OTHER, msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
module compiler.lexer.tokens;
|
||||
|
||||
import std.string : cmp;
|
||||
import std.conv : to;
|
||||
|
||||
public final class Token
|
||||
{
|
||||
/* The token */
|
||||
private string token;
|
||||
|
||||
/* Line number information */
|
||||
private ulong line, column;
|
||||
|
||||
this(string token, ulong line, ulong column)
|
||||
{
|
||||
this.token = token;
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
override bool opEquals(Object other)
|
||||
{
|
||||
return cmp(token, (cast(Token)other).getToken()) == 0;
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
/* TODO (Column number): Don't adjust here, do it maybe in the lexer itself */
|
||||
return token~" at ("~to!(string)(line)~", "~to!(string)(column-token.length)~")";
|
||||
}
|
||||
|
||||
public string getToken()
|
||||
{
|
||||
return token;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue