Diff
Not logged in

Differences From Artifact [701f5b1b899607f2]:

To Artifact [1bc945d1d318d417]:


17 { 17 { 18 immutable string filename; /// name of the source file 18 immutable string filename; /// name of the source file 19 immutable int lineno; /// 1-origin 19 immutable int lineno; /// 1-origin 20 immutable int column; /// 1-origin 20 immutable int column; /// 1-origin 21 21 22 mixin SimpleClass; 22 mixin SimpleClass; 23 override string toString() const 23 override string toString() const 24 { < 25 return sprintf!("%s:%d:%d")(filename, lineno, column); | 24 { return sprintf!("%s:%d:%d")(filename, lineno, column); } 26 } < 27 < 28 static LexPosition dummy; 25 static LexPosition dummy; 29 static this(){ dummy = new LexPosition("<unnamed>",0,0); } 26 static this(){ dummy = new LexPosition("<unnamed>",0,0); } 30 } 27 } 31 28 32 unittest 29 unittest 33 { 30 { 34 auto p = new LexPosition("hello.cpp", 123, 45); 31 auto p = new LexPosition("hello.cpp", 123, 45); ................................................................................................................................................................................ 50 47 51 /*mixin*/ 48 /*mixin*/ 52 template ExceptionWithPosition() 49 template ExceptionWithPosition() 53 { 50 { 54 LexPosition pos; 51 LexPosition pos; 55 this( LexPosition pos, string msg, string file=null, size_t line=0, Thro 52 this( LexPosition pos, string msg, string file=null, size_t line=0, Thro 56 { 53 { 57 if(pos is null) | 54 string fullmsg = pos is null ? sprintf!("\n[??] %s")(msg) 58 super(sprintf!("[??] %s")(msg), file, line, next); | 55 : sprintf!("\n[%s] %s")(pos, msg); 59 else | 56 for(int i=0; i<callstack_pos.length || i<callstack_msg.length; + > 57 { > 58 LexPosition p = (i<callstack_pos.length ? callstack_pos[ > 59 string m = (i<callstack_msg.length ? callstack_msg[ > 60 fullmsg ~= p is null ? sprintf!("\n[??] %s")(m) > 61 : sprintf!("\n[%s] %s")(p, m); > 62 } 60 super(sprintf!("[%s] %s")(pos, msg), file, line, next); | 63 super(fullmsg, file, line, next); 61 this.pos = pos; 64 this.pos = pos; > 65 } > 66 this( string msg, string file=null, size_t line=0, Throwable next=null ) > 67 { > 68 this(null, msg, file, line, next); 62 } 69 } 63 } 70 } 64 71 65 class UnexpectedEOF : Exception { mixin ExceptionWithPosition; } /// EOF during | 72 class UnexpectedEOF : Exception { mixin ExceptionWithPosition; } /// EOF duri 66 class LexException : Exception { mixin ExceptionWithPosition; } /// Lexer errors | 73 class LexException : Exception { mixin ExceptionWithPosition; } /// Lexer er 67 class ParseException : Exception { mixin ExceptionWithPosition; } /// Parser err | 74 class ParseException : Exception { mixin ExceptionWithPosition; } /// Parser e 68 class RuntimeException : Exception { mixin ExceptionWithPosition; } /// Evaluato 75 class RuntimeException : Exception { mixin ExceptionWithPosition; } /// Evaluato > 76 > 77 /// Per-thread call stack management. > 78 /// This scoped class's ctor&dtor maintain the callstack. > 79 /// TODO: make it "per-evaluator" !!!!!!!!!!! > 80 > 81 scope class PushCallStack > 82 { > 83 this(LexPosition pos, string msg) { callstackEnterFunction(pos,msg); } > 84 ~this() { callstackLeaveFunction(); } > 85 } > 86 > 87 LexPosition[] callstack_pos; > 88 string[] callstack_msg; > 89 > 90 private void callstackEnterFunction(LexPosition pos, string msg) > 91 { > 92 callstack_pos ~= pos; > 93 callstack_msg ~= msg; > 94 } > 95 > 96 private void callstackLeaveFunction() > 97 { > 98 callstack_pos.length -= 1; > 99 callstack_msg.length -= 1; > 100 }