Index: build.bat ================================================================== --- build.bat +++ build.bat @@ -1,6 +1,6 @@ @setlocal ENABLEDELAYEDEXPANSION @set ARGS= @for %%I in (main.d polemy\*.d tricks\*.d) do @set ARGS=!ARGS! %%I @if not exist bin mkdir bin -@echo dmd -ofbin\polemy.exe -O -release -inline %ARGS% -@dmd -ofbin\polemy.exe -O -release -inline %ARGS% +@echo dmd -ofbin\polemy.exe -O -release %ARGS% +@dmd -ofbin\polemy.exe -O -release %ARGS% Index: main.d ================================================================== --- main.d +++ main.d @@ -33,12 +33,14 @@ lastVal = eval(a, ctx); } catch( LexException ) { // always EOF exception, so wait next return false; } catch( ParseException e ) { - if( find(e.msg, "EOF") ) // ultra ad-hoc + if( find(e.msg, "EOF")!="" ) // ultra ad-hoc return false; + buf = ""; + lineno = nextlineno; throw e; } return true; } @@ -55,13 +57,20 @@ writeln(e); } return true; } } + +version(unittest) { + bool success = false; + static ~this(){ if(!success){writeln("(press enter to exit)"); readln();} } +} void main( string[] args ) { + version(unittest) success=true; + if( args.length <= 1 ) { writeln("Welcome to Polemy 0.1.0"); for(auto r = new REPL; r.singleInteraction();) {} } Index: polemy/lex.d ================================================================== --- polemy/lex.d +++ polemy/lex.d @@ -13,11 +13,11 @@ class LexException : Exception { const LexPosition pos; - this( const LexPosition pos, string msg, string file="", int line=0, Throwable next=null ) + 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; } }; /// Represents a position in a source code Index: polemy/parse.d ================================================================== --- polemy/parse.d +++ polemy/parse.d @@ -13,11 +13,11 @@ class ParseException : Exception { const LexPosition pos; - this( const LexPosition pos, string msg, string file="", int line=0, Throwable next=null ) + 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; } } private auto createException(Lexer)(Lexer lex, string msg) { return new ParseException(lex.empty?null:lex.front.pos, msg); } @@ -26,11 +26,11 @@ auto parseString(S, T...)(S str, T fn_ln_cn) { return parserFromString(str, fn_ln_cn).parse(); } auto parseFile(S, T...)(S filename, T ln_cn) - { return parserFromString(filename, ln_cn).parse(); } + { return parserFromFile(filename, ln_cn).parse(); } /// Named Constructor of Parser private auto parserFromLexer(Lexer)(Lexer lex) { return new Parser!Lexer(lex); } Index: tricks/test.d ================================================================== --- tricks/test.d +++ tricks/test.d @@ -8,11 +8,11 @@ import std.conv : to; import core.exception; /// Unittest helper that asserts an expression must throw something -void assert_throw(ExceptionType, T, string fn=__FILE__, int ln=__LINE__)(lazy T t, string msg="") +void assert_throw(ExceptionType, T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="") { try { t(); } catch(ExceptionType) { return; } @@ -21,11 +21,11 @@ onAssertErrorMsg(fn, ln, msg.length ? msg : "no execption"); } /// Unittest helper that asserts an expression must not throw anything -auto assert_nothrow(T, string fn=__FILE__, int ln=__LINE__)(lazy T t, string msg="") +auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="") { try { return t(); } catch(Throwable e) { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.toString()~"]"); } @@ -50,11 +50,11 @@ /// Unittest helpers asserting two values are in some relation ==, !=, <, <=, >, >= template assertOp(string op) { - void assertOp(A, B, string fn=__FILE__, int ln=__LINE__)(A a, B b, string msg="") + void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, string msg="") { try { if( mixin("a"~op~"b") ) return; } catch(Throwable e) { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.toString()~"]"); }