Differences From Artifact [81cf3e2a44d63239]:
- File
main.d
- 2010-11-09 06:19:11 - part of checkin [d78d700f7a] on branch trunk - tenuki REPL bug-fix (now we can continue using REPL after a syntax error) and file interpreter mode. (user: kinaba) [annotate]
To Artifact [b29be17d733aa309]:
- File
main.d
- 2010-11-09 14:24:09 - part of checkin [2459e9a821] on branch trunk - refactored eof-driven REPL (user: kinaba) [annotate]
20 Value lastVal; 20 Value lastVal;
21 int lineno = 1; 21 int lineno = 1;
22 int nextlineno = 1; 22 int nextlineno = 1;
23 this() { ctx = createGlobalContext(); } 23 this() { ctx = createGlobalContext(); }
24 24
25 bool tryRun( string s ) 25 bool tryRun( string s )
26 { 26 {
> 27 scope(failure)
27 nextlineno ++; | 28 { buf = ""; lineno = nextlineno; }
> 29
28 buf ~= s; 30 buf ~= s;
> 31 nextlineno ++;
29 try { | 32 try
30 AST a = parseString(buf, "<REPL>", lineno); | 33 { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx
31 buf = ""; <
32 lineno = nextlineno; | 34 catch( UnexpectedEOF )
33 lastVal = eval(a, ctx); <
34 } catch( LexException ) { <
35 // always EOF exception, so wait next <
36 return false; | 35 { return false; } // wait
37 } catch( ParseException e ) { <
38 if( find(e.msg, "EOF")!="" ) // ultra ad-hoc <
39 return false; <
40 buf = ""; | 36 buf = "";
41 lineno = nextlineno; | 37 lineno = nextlineno;
42 throw e; <
43 } <
44 return true; 38 return true;
45 } 39 }
46 40
47 bool singleInteraction() 41 bool singleInteraction()
48 { 42 {
49 writef(">> ", lineno); 43 writef(">> ", lineno);
50 string line = readln(); 44 string line = readln();