@@ -10,14 +10,24 @@ import std.ctype : isspace, isalnum; /// Exception from this module -class LexException : Exception +/*mixin*/ +template ExceptionWithPosition() { const LexPosition pos; - this( const LexPosition pos, string msg, string file=null, size_t line=0, Throwable next=null ) { super(sprintf!"[%s] %s"(pos, msg), file, line, next); this.pos = pos; } +} + +class UnexpectedEOF : Exception +{ + mixin ExceptionWithPosition; +} + +class LexException : Exception +{ + mixin ExceptionWithPosition; }; /// Represents a position in a source code @@ -161,9 +171,9 @@ string readQuoted(const LexPosition pos){char[] buf; return readQuoted(pos,buf);} string readQuoted(const LexPosition pos, ref char[] buf) { if( reader.empty ) - throw genex!LexException(pos, "EOF found while lexing a quoted-string"); + throw genex!UnexpectedEOF(pos, "Quoted string not terminated"); dchar c = reader.front; reader.popFront; if( c == '"' ) return assumeUnique(buf); @@ -292,9 +302,9 @@ } unittest { - assert_throw!LexException( lexerFromString(`"`) ); + assert_throw!UnexpectedEOF( lexerFromString(`"`) ); } unittest {