From c7d896b567fc49931753f9596ffbe743fb06963d Mon Sep 17 00:00:00 2001 From: zodiac Date: Mon, 30 Mar 2009 09:21:34 +0000 Subject: [PATCH] Allow blank lines git-svn-id: https://shellinabox.googlecode.com/svn/trunk@99 0da03de8-d603-11dd-86c2-0f8696b7b6f9 --- demo/demo.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 8f2a89f..bb91c8a 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -218,31 +218,34 @@ Demo.prototype.doCommand = function() { this.gotoState(2 /* STATE_PROMPT */); var tokens = new Tokens(this.line); this.line = ''; - var cmd = tokens.nextToken().toUpperCase(); - if (cmd.match(/^[0-9]+$/)) { - tokens.removeLineNumber(); - var lineNumber = parseInt(cmd); - var index = this.findLine(lineNumber); - if (tokens.nextToken() == undefined) { - if (index > 0) { - // Delete line from program - this.program.splice(index, 1); + var cmd = tokens.nextToken(); + if (cmd != undefined) { + cmd = cmd.toUpperCase(); + if (cmd.match(/^[0-9]+$/)) { + tokens.removeLineNumber(); + var lineNumber = parseInt(cmd); + var index = this.findLine(lineNumber); + if (tokens.nextToken() == undefined) { + if (index > 0) { + // Delete line from program + this.program.splice(index, 1); + } + } else { + if (index >= 0) { + // Replace line in program + this.program[index].setTokens(tokens); + } else { + // Add new line to program + this.program.splice(-index - 1, 0, new Line(lineNumber, tokens)); + } } } else { - if (index >= 0) { - // Replace line in program - this.program[index].setTokens(tokens); - } else { - // Add new line to program - this.program.splice(-index - 1, 0, new Line(lineNumber, tokens)); - } + this.currentLineIndex = -1; + this.tokens = tokens; + this.gotoState(5 /* STATE_EVAL */); } - } else { - this.currentLineIndex = -1; - this.tokens = tokens; - this.gotoState(5 /* STATE_EVAL */); + tokens.reset(); } - tokens.reset(); }; Demo.prototype.doEval = function() {