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     20    Value  lastVal;
    21     21    int lineno = 1;
    22     22    int nextlineno = 1;
    23     23    this() { ctx = createGlobalContext(); }
    24     24   
    25     25    bool tryRun( string s )
    26     26    {
    27         -  nextlineno ++;
           27  +  scope(failure)
           28  +   { buf = ""; lineno = nextlineno; }
           29  +
    28     30     buf ~= s;
    29         -  try {
    30         -   AST a = parseString(buf, "<REPL>", lineno);
    31         -   buf = "";
    32         -   lineno = nextlineno;
    33         -   lastVal = eval(a, ctx);
    34         -  } catch( LexException ) {
    35         -   // always EOF exception, so wait next
    36         -   return false;
    37         -  } catch( ParseException e ) {
    38         -   if( find(e.msg, "EOF")!="" ) // ultra ad-hoc
    39         -    return false;
    40         -   buf = "";
    41         -   lineno = nextlineno;
    42         -   throw e;
    43         -  }
           31  +  nextlineno ++;
           32  +  try
           33  +   { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx); }
           34  +  catch( UnexpectedEOF )
           35  +   { return false; } // wait
           36  +  buf = "";
           37  +  lineno = nextlineno;
    44     38     return true;
    45     39    }
    46     40   
    47     41    bool singleInteraction()
    48     42    {
    49     43     writef(">> ", lineno);
    50     44     string line = readln();