Diff
Not logged in

Differences From Artifact [cc80329bc2ab2034]:

To Artifact [df057f5d35e6bc8a]:


11 11 12 /// Exception from this module 12 /// Exception from this module 13 13 14 class LexException : Exception 14 class LexException : Exception 15 { 15 { 16 const LexPosition pos; 16 const LexPosition pos; 17 17 18 private this( const LexPosition pos, string msg ) | 18 this( const LexPosition pos, string msg, string file="", int line=0 ) 19 { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } | 19 { super(sprintf!"[%s] %s"(pos, msg), file, line); this.pos = pos 20 }; 20 }; 21 21 22 /// Represents a position in a source code 22 /// Represents a position in a source code 23 23 24 class LexPosition 24 class LexPosition 25 { 25 { 26 immutable string filename; /// name of the source file 26 immutable string filename; /// name of the source file 27 immutable int lineno; /// 1-origin 27 immutable int lineno; /// 1-origin 28 immutable int column; /// 1-origin 28 immutable int column; /// 1-origin 29 29 > 30 mixin SimpleClass; 30 override string toString() const 31 override string toString() const 31 { return sprintf!"%s:%d:%d"(filename, lineno, column); } 32 { return sprintf!"%s:%d:%d"(filename, lineno, column); } 32 33 33 mixin SimpleConstructor; < 34 mixin SimpleCompare; < 35 < 36 static immutable LexPosition dummy; 34 static immutable LexPosition dummy; 37 static this(){ dummy = new immutable(LexPosition)("<unnamed>",0,0); } 35 static this(){ dummy = new immutable(LexPosition)("<unnamed>",0,0); } 38 } 36 } 39 37 40 unittest 38 unittest 41 { 39 { 42 auto p = new LexPosition("hello.cpp", 123, 45); 40 auto p = new LexPosition("hello.cpp", 123, 45); ................................................................................................................................................................................ 59 57 60 class Token 58 class Token 61 { 59 { 62 immutable LexPosition pos; /// Position where the token occurred in t 60 immutable LexPosition pos; /// Position where the token occurred in t 63 immutable string str; /// The token string itself 61 immutable string str; /// The token string itself 64 immutable bool quoted; /// Was it a "quoted" token or unquoted? 62 immutable bool quoted; /// Was it a "quoted" token or unquoted? 65 63 66 mixin SimpleConstructor; < 67 mixin SimpleCompare; | 64 mixin SimpleClass; 68 mixin SimpleToString; < 69 } 65 } 70 66 71 unittest 67 unittest 72 { 68 { 73 auto p = new immutable(LexPosition)("hello.cpp", 123, 45); 69 auto p = new immutable(LexPosition)("hello.cpp", 123, 45); 74 auto t = new Token(p, "class", false); 70 auto t = new Token(p, "class", false); 75 auto u = new Token(p, "class", true); 71 auto u = new Token(p, "class", true);