]> andersk Git - test.git/commitdiff
Improved error handling.
authorMarkus Gutschke <markus@shellinabox.com>
Wed, 1 Apr 2009 19:51:14 +0000 (19:51 +0000)
committerMarkus Gutschke <markus@shellinabox.com>
Wed, 1 Apr 2009 19:51:14 +0000 (19:51 +0000)
demo/demo.js
demo/demo.jspp

index 65e87d923762a65caafb3e8fb5f49bdd982097ec..d96d1dfdc071b533d9a83f2e8658a3c15fb86fec 100644 (file)
@@ -173,10 +173,11 @@ Demo.prototype.error = function(msg) {
   }
   this.vt100((this.cursorX != 0 ? '\r\n' : '') + '\u0007? ' + msg +
              (this.currentLineIndex >= 0 ?
-              ' in line ' + this.program[this.currentLineIndex].lineNumber() :
+              ' in line ' + this.program[this.evalLineIndex].lineNumber() :
               '') + '\r\n');
   this.gotoState(2 /* STATE_PROMPT */);
   this.currentLineIndex = -1;
+  this.evalLineIndex    = -1;
   return undefined;
 };
 
@@ -203,6 +204,7 @@ Demo.prototype.doPrompt = function() {
   this.keys             = '';
   this.line             = '';
   this.currentLineIndex = -1;
+  this.evalLineIndex    = -1;
   this.vt100((this.cursorX != 0 ? '\r\n' : '') + '> ');
   this.gotoState(3 /* STATE_READLINE */);
   return false;
@@ -272,6 +274,7 @@ Demo.prototype.doCommand = function() {
       }
     } else {
       this.currentLineIndex = -1;
+      this.evalLineIndex    = -1;
       this.tokens           = tokens;
       this.gotoState(5 /* STATE_EVAL */);
     }
@@ -420,7 +423,8 @@ Demo.prototype.doPrint = function() {
 };
 
 Demo.prototype.doExec = function() {
-  this.tokens = this.program[this.currentLineIndex++].tokens();
+  this.evalLineIndex = this.currentLineIndex++;
+  this.tokens        = this.program[this.evalLineIndex].tokens();
   this.tokens.reset();
   this.doEval();
   if (this.currentLineIndex < 0) {
@@ -547,7 +551,7 @@ Demo.prototype.term = function() {
 Demo.prototype.factor = function() {
   var token  = this.tokens.nextToken();
   if (!token) {
-    return token;
+    return this.error();
   }
 
   var value  = undefined;
index 60d4fd6cc642cae36f1339b16a9b0b4774bd7208..da46ae50f7085f0009f2e2beb5919132f963e1fc 100644 (file)
@@ -173,10 +173,11 @@ Demo.prototype.error = function(msg) {
   }
   this.vt100((this.cursorX != 0 ? '\r\n' : '') + '\u0007? ' + msg +
              (this.currentLineIndex >= 0 ?
-              ' in line ' + this.program[this.currentLineIndex].lineNumber() :
+              ' in line ' + this.program[this.evalLineIndex].lineNumber() :
               '') + '\r\n');
   this.gotoState(STATE_PROMPT);
   this.currentLineIndex = -1;
+  this.evalLineIndex    = -1;
   return undefined;
 };
 
@@ -203,6 +204,7 @@ Demo.prototype.doPrompt = function() {
   this.keys             = '';
   this.line             = '';
   this.currentLineIndex = -1;
+  this.evalLineIndex    = -1;
   this.vt100((this.cursorX != 0 ? '\r\n' : '') + '> ');
   this.gotoState(STATE_READLINE);
   return false;
@@ -272,6 +274,7 @@ Demo.prototype.doCommand = function() {
       }
     } else {
       this.currentLineIndex = -1;
+      this.evalLineIndex    = -1;
       this.tokens           = tokens;
       this.gotoState(STATE_EVAL);
     }
@@ -420,7 +423,8 @@ Demo.prototype.doPrint = function() {
 };
 
 Demo.prototype.doExec = function() {
-  this.tokens = this.program[this.currentLineIndex++].tokens();
+  this.evalLineIndex = this.currentLineIndex++;
+  this.tokens        = this.program[this.evalLineIndex].tokens();
   this.tokens.reset();
   this.doEval();
   if (this.currentLineIndex < 0) {
@@ -547,7 +551,7 @@ Demo.prototype.term = function() {
 Demo.prototype.factor = function() {
   var token  = this.tokens.nextToken();
   if (!token) {
-    return token;
+    return this.error();
   }
 
   var value  = undefined;
This page took 0.034044 seconds and 5 git commands to generate.