1 module dud.sdlang.tokenmodule; 2 3 import dud.sdlang.visitor; 4 import dud.sdlang.value; 5 6 enum TokenType { 7 undefined, 8 lcurly, 9 rcurly, 10 ident, 11 colon, 12 backslash, 13 semicolon, 14 assign, 15 eol, 16 eof, 17 value 18 } 19 20 struct Token { 21 @safe pure: 22 size_t line; 23 size_t column; 24 Value value; 25 string valueStr; 26 27 TokenType type; 28 29 this(TokenType type) { 30 this.type = type; 31 } 32 33 this(TokenType type, size_t line, size_t column) { 34 this.type = type; 35 this.line = line; 36 this.column = column; 37 } 38 39 this(TokenType type, Value value, string valueStr) { 40 this(type); 41 this.value = value; 42 this.valueStr = valueStr; 43 } 44 45 this(TokenType type, Value value, string valueStr, size_t line, 46 size_t column) 47 { 48 this(type, line, column); 49 this.valueStr = valueStr; 50 this.value = value; 51 } 52 53 void visit(ConstVisitor vis) { 54 } 55 56 void visit(ConstVisitor vis) const { 57 } 58 59 void visit(Visitor vis) { 60 } 61 62 void visit(Visitor vis) const { 63 } 64 65 string toString() const { 66 import std.format : format; 67 return format!"Token(%s,%s,%s,%s)"(this.line, this.column, this.type, 68 this.valueStr); 69 } 70 }