You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
774 B
D
36 lines
774 B
D
module tlang.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;
|
|
}
|
|
} |