Diff
Not logged in

Differences From Artifact [ceae1b272549ae1a]:

To Artifact [594acaf3ac60594c]:


5 5 * Error Information for Polemy Programming Language 6 6 */ 7 7 module polemy.failure; 8 8 import polemy._common; 9 9 10 10 /// Represents a position in source codes 11 11 12 -class LexPosition 12 +class LexPosition_t 13 13 { 14 14 immutable string filename; /// name of the source file 15 15 immutable int lineno; /// 1-origin 16 16 immutable int column; /// 1-origin 17 17 18 18 mixin SimpleClass; 19 19 override string toString() const 20 20 { 21 21 return sprintf!("%s:%d:%d")(filename, lineno, column); 22 22 } 23 23 24 - static immutable LexPosition dummy; 25 - static this(){ dummy = new immutable(LexPosition)("<unnamed>",0,0); } 24 + static LexPosition dummy; 25 + static this(){ dummy = new LexPosition("<unnamed>",0,0); } 26 26 } 27 27 28 +/// Represents a position in source codes 29 + 30 +alias immutable(LexPosition_t) LexPosition; 31 + 28 32 unittest 29 33 { 30 34 auto p = new LexPosition("hello.cpp", 123, 45); 31 35 32 36 assert_eq( p.filename, "hello.cpp" ); 33 37 assert_eq( p.lineno, 123 ); 34 38 assert_eq( p.column, 45 ); ................................................................................ 43 47 assert_lt( p, q ); 44 48 assert_ne( p, q ); 45 49 } 46 50 47 51 /*mixin*/ 48 52 template ExceptionWithPosition() 49 53 { 50 - const LexPosition pos; 51 - this( const LexPosition pos, string msg, string file=null, size_t line=0, Throwable next=null ) 54 + LexPosition pos; 55 + this( LexPosition pos, string msg, string file=null, size_t line=0, Throwable next=null ) 52 56 { 53 57 if(pos is null) 54 - super(sprintf!("[???????] %s")(msg), file, line, next); 58 + super(sprintf!("[??] %s")(msg), file, line, next); 55 59 else 56 60 super(sprintf!("[%s] %s")(pos, msg), file, line, next); 57 61 this.pos = pos; 58 62 } 59 63 } 60 64 61 65 class UnexpectedEOF : Exception { mixin ExceptionWithPosition; } /// EOF during lexing/parsing 62 66 class LexException : Exception { mixin ExceptionWithPosition; } /// Lexer errors 63 67 class ParseException : Exception { mixin ExceptionWithPosition; } /// Parser errors 64 68 class RuntimeException : Exception { mixin ExceptionWithPosition; } /// Evaluator errors