From c1e181ec98f69600df571a6a8af8e240dfc28cbf Mon Sep 17 00:00:00 2001 From: zodiac Date: Wed, 1 Apr 2009 19:51:14 +0000 Subject: [PATCH] Improved error handling. git-svn-id: https://shellinabox.googlecode.com/svn/trunk@107 0da03de8-d603-11dd-86c2-0f8696b7b6f9 --- demo/demo.js | 10 +++++++--- demo/demo.jspp | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 65e87d9..d96d1df 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -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; diff --git a/demo/demo.jspp b/demo/demo.jspp index 60d4fd6..da46ae5 100644 --- a/demo/demo.jspp +++ b/demo/demo.jspp @@ -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;