@@ -14,25 +14,23 @@ class LexException : Exception { const LexPosition pos; - private this( const LexPosition pos, string msg ) - { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } -}; - + this( const LexPosition pos, string msg, string file="", int line=0 ) + { super(sprintf!"[%s] %s"(pos, msg), file, line); this.pos = pos; } +}; + /// Represents a position in a source code class LexPosition { immutable string filename; /// name of the source file immutable int lineno; /// 1-origin immutable int column; /// 1-origin - + + mixin SimpleClass; override string toString() const { return sprintf!"%s:%d:%d"(filename, lineno, column); } - - mixin SimpleConstructor; - mixin SimpleCompare; static immutable LexPosition dummy; static this(){ dummy = new immutable(LexPosition)("",0,0); } } @@ -62,11 +60,9 @@ immutable LexPosition pos; /// Position where the token occurred in the source immutable string str; /// The token string itself immutable bool quoted; /// Was it a "quoted" token or unquoted? - mixin SimpleConstructor; - mixin SimpleCompare; - mixin SimpleToString; + mixin SimpleClass; } unittest {