From 962663d3d98b437a9648d28612c6854b685ce5d3 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 17 Feb 2004 08:43:48 +0000 Subject: [PATCH] t.scanOperand should be true by default, eliminating scanForOperand bloat. --- js/narcissus/jsparse.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/js/narcissus/jsparse.js b/js/narcissus/jsparse.js index 85c0bb7aa9de..0c8eaa279c71 100644 --- a/js/narcissus/jsparse.js +++ b/js/narcissus/jsparse.js @@ -60,7 +60,8 @@ function Tokenizer(s, f, l) { this.tokens = []; this.tokenIndex = 0; this.lookahead = 0; - this.scanNewlines = this.scanOperand = false; + this.scanNewlines = false; + this.scanOperand = true; this.filename = f || ""; this.lineno = l || 1; } @@ -106,13 +107,6 @@ Tokenizer.prototype = { return tt; }, - scanForOperand: function (method) { - this.scanOperand = true; - var tt = this[method](); - this.scanOperand = false; - return tt; - }, - get: function () { var token; while (this.lookahead) { @@ -507,7 +501,7 @@ function Statement(t, x) { if (!x.inFunction) throw t.newSyntaxError("Invalid return"); n = new Node(t); - tt = t.scanForOperand('peekOnSameLine'); + tt = t.peekOnSameLine(); if (tt != END && tt != NEWLINE && tt != SEMICOLON && tt != RIGHT_CURLY) n.value = Expression(t, x); break; @@ -712,7 +706,6 @@ function Expression(t, x, stop) { return n; } - t.scanOperand = true; loop: while ((tt = t.get()) != END) { if (tt == stop && @@ -961,13 +954,13 @@ loop: } } - if (t.scanOperand) { - t.scanOperand = false; - throw t.newSyntaxError("Missing operand"); - } if (x.hookLevel != hl) throw t.newSyntaxError("Missing : after ?"); + if (t.scanOperand) + throw t.newSyntaxError("Missing operand"); + // Resume default mode, scanning for operands, not operators. + t.scanOperand = true; t.unget(); while (operators.length) reduce();