Diff
Not logged in

Differences From Artifact [ceae1b272549ae1a]:

To Artifact [594acaf3ac60594c]:


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