Author: gotcha
Date: Tue Dec 25 16:40:44 2007
New Revision: 50095
Removed:
kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
Modified:
kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
Log:
unindent and initialize
Deleted: /kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
==============================================================================
--- /kukit/kukit.js/branch/finish-closures/kukit/TODO.txt Tue Dec 25
16:40:44 2007
+++ (empty file)
@@ -1,3 +0,0 @@
-files where indentation has to be undone and initialize needs to be done
-
-tokenizer.js
Modified: kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js Tue Dec 25
16:40:44 2007
@@ -29,23 +29,24 @@
*/
tk._TokenBase = function() {
- this.emitError = function(msg) {
- // Use the start position of the token for the error report.
-;;; var marker = this.cursor.makeMarker(this.startpos);
-;;; throw kukit.err.parsingError(msg, marker);
- throw new Error(kukit.E);
- };
+this.emitError = function(msg) {
+ // Use the start position of the token for the error report.
+;;; var marker = this.cursor.makeMarker(this.startpos);
+;;; throw kukit.err.parsingError(msg, marker);
+ throw new Error(kukit.E);
+};
- this.updateFinished = function() {
- if (! this.finished && this.cursor.text.length == this.cursor.pos) {
- if (this.isTopLevelParser) {
- this.finished = true;
- } else {
-;;; kukit.E = 'Unexpected EOF.';
- this.emitError(kukit.E);
- }
+this.updateFinished = function() {
+ if (! this.finished && this.cursor.text.length == this.cursor.pos) {
+ if (this.isTopLevelParser) {
+ this.finished = true;
+ } else {
+;;; kukit.E = 'Unexpected EOF.';
+ this.emitError(kukit.E);
}
- };
+ }
+};
+
};
@@ -54,136 +55,136 @@
*/
tk._ParserBase = function() {
- this.emitAndReturn = function(token) {
- // handle return to the next level
- this.finished = true;
- return token;
- };
+this.emitAndReturn = function(token) {
+ // handle return to the next level
+ this.finished = true;
+ return token;
+};
- this.nextStep = function() {
- var table = this.table
- var cursor = this.cursor;
- // Search for symbol according to table.
- var best_pos = cursor.text.length;
- var best_symbol = null;
- for (var symbol in table) {
- var pos = cursor.text.indexOf(symbol, cursor.pos);
- if (pos != -1 && pos < best_pos) {
- best_pos = pos;
- best_symbol = symbol;
+this.nextStep = function() {
+ var table = this.table
+ var cursor = this.cursor;
+ // Search for symbol according to table.
+ var best_pos = cursor.text.length;
+ var best_symbol = null;
+ for (var symbol in table) {
+ var pos = cursor.text.indexOf(symbol, cursor.pos);
+ if (pos != -1 && pos < best_pos) {
+ best_pos = pos;
+ best_symbol = symbol;
+ }
+ }
+ // eat up till the symbol found (of EOF)
+ if (best_pos > cursor.pos) {
+ this.result.push(new tk.Fraction(cursor, best_pos));
+ cursor.pos = best_pos;
+ }
+ if (best_symbol) {
+ // found a symbol, handle that
+ // make the token and push it
+ var tokens = eval(table[best_symbol]);
+ if (typeof(tokens) != 'undefined') {
+ if (typeof(tokens.length) == 'undefined') {
+ tokens = [tokens];
}
- }
- // eat up till the symbol found (of EOF)
- if (best_pos > cursor.pos) {
- this.result.push(new tk.Fraction(cursor, best_pos));
- cursor.pos = best_pos;
- }
- if (best_symbol) {
- // found a symbol, handle that
- // make the token and push it
- var tokens = eval(table[best_symbol]);
- if (typeof(tokens) != 'undefined') {
- if (typeof(tokens.length) == 'undefined') {
- tokens = [tokens];
- }
- for (var i=0; i<tokens.length; i++) {
- this.result.push(tokens[i]);
- }
+ for (var i=0; i<tokens.length; i++) {
+ this.result.push(tokens[i]);
}
}
- };
+ }
+};
- /* token postprocess support */
+/* token postprocess support */
- this.process = function() {
- // default process after tokenization
- this.txt = '';
- for (var i=0; i<this.result.length; i++) {
- this.txt += this.result[i].txt;
- }
- };
+this.process = function() {
+ // default process after tokenization
+ this.txt = '';
+ for (var i=0; i<this.result.length; i++) {
+ this.txt += this.result[i].txt;
+ }
+};
- this.expectToken = function(context, token) {
- var i = context.nextTokenIndex;
- if (token) {
- var symbol = token.prototype.symbol;
- if (i >= this.result.length) {
-;;; kukit.E = 'Missing token : [' + symbol + '].';
- this.emitError(kukit.E);
- } else if (this.result[i].symbol != symbol) {
-;;; kukit.E = 'Unexpected token : [' + this.result[i].symbol;
-;;; kukit.E += '] found, [' + symbol + '] was expected.';
- this.emitError(kukit.E);
- }
- } else {
- if (i >= this.result.length) {
-;;; kukit.E = 'Missing token.';
- this.emitError(kukit.E);
- }
+this.expectToken = function(context, token) {
+ var i = context.nextTokenIndex;
+ if (token) {
+ var symbol = token.prototype.symbol;
+ if (i >= this.result.length) {
+;;; kukit.E = 'Missing token : [' + symbol + '].';
+ this.emitError(kukit.E);
+ } else if (this.result[i].symbol != symbol) {
+;;; kukit.E = 'Unexpected token : [' + this.result[i].symbol;
+;;; kukit.E += '] found, [' + symbol + '] was expected.';
+ this.emitError(kukit.E);
}
- context.token = this.result[i];
- context.nextTokenIndex += 1;
- };
+ } else {
+ if (i >= this.result.length) {
+;;; kukit.E = 'Missing token.';
+ this.emitError(kukit.E);
+ }
+ }
+ context.token = this.result[i];
+ context.nextTokenIndex += 1;
+};
- this.resultIsNullOrNotToken =
- function(token, currentValue) {
- return (!token || currentValue.symbol != token.prototype.symbol);
- };
+this.resultIsNullOrNotToken =
+ function(token, currentValue) {
+ return (!token || currentValue.symbol != token.prototype.symbol);
+};
- this.notInTokens =
- function(context, token1, token2, token3, token4) {
- var i = context.nextTokenIndex;
- var currentValue = this.result[i];
- return !(
- (i >= this.result.length) ||
- (this.resultIsNullOrNotToken(token1, currentValue) &&
- this.resultIsNullOrNotToken(token2, currentValue) &&
- this.resultIsNullOrNotToken(token3, currentValue) &&
- this.resultIsNullOrNotToken(token4, currentValue))
- );
- };
+this.notInTokens =
+ function(context, token1, token2, token3, token4) {
+ var i = context.nextTokenIndex;
+ var currentValue = this.result[i];
+ return !(
+ (i >= this.result.length) ||
+ (this.resultIsNullOrNotToken(token1, currentValue) &&
+ this.resultIsNullOrNotToken(token2, currentValue) &&
+ this.resultIsNullOrNotToken(token3, currentValue) &&
+ this.resultIsNullOrNotToken(token4, currentValue))
+ );
+};
- this.digestTxt =
- function(context, token1, token2, token3, token4) {
- // digests the txt from the tokens, ignores given token
- // plus whitespace removal
- this.digestExactTxt(context, token1, token2, token3, token4);
- context.txt = this.removeWhitespacesAndTrim(context.txt);
- };
+this.digestTxt =
+ function(context, token1, token2, token3, token4) {
+ // digests the txt from the tokens, ignores given token
+ // plus whitespace removal
+ this.digestExactTxt(context, token1, token2, token3, token4);
+ context.txt = this.removeWhitespacesAndTrim(context.txt);
+};
- this.digestExactTxt =
- function(context, token1, token2, token3, token4) {
- // digests the txt from the tokens, ignores given token
- // exact value: no whitespace removal
- var result = '';
- while (this.notInTokens(context, token1, token2, token3, token4)) {
- result += this.result[context.nextTokenIndex].txt;
- context.nextTokenIndex ++;
- }
- context.txt = result;
- };
+this.digestExactTxt =
+ function(context, token1, token2, token3, token4) {
+ // digests the txt from the tokens, ignores given token
+ // exact value: no whitespace removal
+ var result = '';
+ while (this.notInTokens(context, token1, token2, token3, token4)) {
+ result += this.result[context.nextTokenIndex].txt;
+ context.nextTokenIndex ++;
+ }
+ context.txt = result;
+};
+this.removeWhitespaces = function(txt) {
+ // removes ws but leaves leading and trailing one
+ if (txt != ' ') { //speedup only
+ txt = txt.replace(/[\r\n\t ]+/g, ' ');
+ }
+ return txt;
+};
+
+this.removeWhitespacesAndTrim = function(txt) {
+ txt = this.removeWhitespaces(txt);
+ // XXX Strange thing is: following replace works from
+ // tests and the original demo, but with kukitportlet demo
+ // it breaks. Someone stinks!
+ //txt = txt.replace(/^ /, '');
+ if (txt && txt.charAt(0) == ' ') {
+ txt = txt.substr(1);
+ }
+ txt = txt.replace(/ $/, '');
+ return txt;
+};
- this.removeWhitespaces = function(txt) {
- // removes ws but leaves leading and trailing one
- if (txt != ' ') { //speedup only
- txt = txt.replace(/[\r\n\t ]+/g, ' ');
- }
- return txt;
- };
-
- this.removeWhitespacesAndTrim = function(txt) {
- txt = this.removeWhitespaces(txt);
- // XXX Strange thing is: following replace works from
- // tests and the original demo, but with kukitportlet demo
- // it breaks. Someone stinks!
- //txt = txt.replace(/^ /, '');
- if (txt && txt.charAt(0) == ' ') {
- txt = txt.substr(1);
- }
- txt = txt.replace(/ $/, '');
- return txt;
- };
};
tk._ParserBase.prototype = new tk._TokenBase();
@@ -191,12 +192,16 @@
/*
* class Fraction
*/
-tk.Fraction = function(cursor, endpos) {
+tk.Fraction = function() {
+
+this.initialize = function(cursor, endpos) {
this.txt = cursor.text.substring(cursor.pos, endpos);
this.startpos = cursor.pos;
this.endpos = cursor.pos;
this.finished = true;
};
+this.initialize.apply(this, arguments);
+};
tk.Fraction.prototype.symbol = 'fraction';
@@ -258,46 +263,50 @@
/*
* class Cursor
*/
-tk.Cursor = function(txt) {
+tk.Cursor = function() {
+
+this.initialize = function(txt) {
this.text = txt;
this.pos = 0;
+};
- this.makeMarker = function(pos) {
- // create a cursor to mark this position
- var cursor = new tk.Cursor();
- cursor.text = this.text;
- cursor.pos = pos;
- // Calculate the row and column information on the cursor
- cursor.calcRowCol();
- return cursor;
- };
+this.makeMarker = function(pos) {
+ // create a cursor to mark this position
+ var cursor = new tk.Cursor();
+ cursor.text = this.text;
+ cursor.pos = pos;
+ // Calculate the row and column information on the cursor
+ cursor.calcRowCol();
+ return cursor;
+};
- this.getRowCol = function(pos) {
- // Gets the row, col information for the position.
- if (typeof(pos) == 'undefined') {
- pos = this.pos;
- }
- var index = 0;
- var row = 1;
- var next = 0;
- while (true) {
- next = this.text.indexOf('\n', index);
- if (next == -1 || next >= pos) {
- break;
- }
- index = next + 1;
- row += 1;
- }
- var col = pos - index + 1;
- return {'row': row, 'col': col};
- };
+this.getRowCol = function(pos) {
+ // Gets the row, col information for the position.
+ if (typeof(pos) == 'undefined') {
+ pos = this.pos;
+ }
+ var index = 0;
+ var row = 1;
+ var next = 0;
+ while (true) {
+ next = this.text.indexOf('\n', index);
+ if (next == -1 || next >= pos) {
+ break;
+ }
+ index = next + 1;
+ row += 1;
+ }
+ var col = pos - index + 1;
+ return {'row': row, 'col': col};
+};
- this.calcRowCol = function(pos) {
- // Calculates row and column information on the cursor.
- var rowcol = this.getRowCol();
- this.row = rowcol.row;
- this.col = rowcol.col;
- };
+this.calcRowCol = function(pos) {
+ // Calculates row and column information on the cursor.
+ var rowcol = this.getRowCol();
+ this.row = rowcol.row;
+ this.col = rowcol.col;
+};
+this.initialize.apply(this, arguments);
};
}(); /// MODULE END
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins