[KSS-checkins] r49855 - kukit/kukit.js/branch/finish-closures/kukit
gotcha at codespeak.net
gotcha at codespeak.net
Sun Dec 16 20:54:08 CET 2007
Author: gotcha
Date: Sun Dec 16 20:54:07 2007
New Revision: 49855
Modified:
kukit/kukit.js/branch/finish-closures/kukit/kssparser.js
kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
Log:
module and class closures -- step 1
Modified: kukit/kukit.js/branch/finish-closures/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/kssparser.js (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/kssparser.js Sun Dec 16 20:54:07 2007
@@ -19,36 +19,38 @@
/* Tokens of the KSS parser */
-kukit.kssp = {};
+kukit.kssp = new function() { /// MODULE START
+
+var kssp = this;
/* Tokens */
-kukit.kssp.openComment = kukit.tk.mkToken('openComment', "\/\*");
-kukit.kssp.closeComment = kukit.tk.mkToken('closeComment', "\*\/");
-kukit.kssp.openBrace = kukit.tk.mkToken('openBrace', "{");
-kukit.kssp.closeBrace = kukit.tk.mkToken('closeBrace', "}");
-kukit.kssp.openBracket = kukit.tk.mkToken('openBracket', "[");
-kukit.kssp.closeBracket = kukit.tk.mkToken('closeBracket', "]");
-kukit.kssp.openParent = kukit.tk.mkToken('openParent', "(");
-kukit.kssp.closeParent = kukit.tk.mkToken('closeParent', ")");
-kukit.kssp.semicolon = kukit.tk.mkToken('semicolon', ";");
-kukit.kssp.colon = kukit.tk.mkToken('colon', ":");
-kukit.kssp.quote = kukit.tk.mkToken('quote', "'");
-kukit.kssp.dquote = kukit.tk.mkToken('dquote', '"');
-kukit.kssp.backslash = kukit.tk.mkToken('backslash', '\x5c');
-kukit.kssp.comma = kukit.tk.mkToken('comma', ",");
-kukit.kssp.equals = kukit.tk.mkToken('equals', "=");
+kssp.openComment = kukit.tk.mkToken('openComment', "\/\*");
+kssp.closeComment = kukit.tk.mkToken('closeComment', "\*\/");
+kssp.openBrace = kukit.tk.mkToken('openBrace', "{");
+kssp.closeBrace = kukit.tk.mkToken('closeBrace', "}");
+kssp.openBracket = kukit.tk.mkToken('openBracket', "[");
+kssp.closeBracket = kukit.tk.mkToken('closeBracket', "]");
+kssp.openParent = kukit.tk.mkToken('openParent', "(");
+kssp.closeParent = kukit.tk.mkToken('closeParent', ")");
+kssp.semicolon = kukit.tk.mkToken('semicolon', ";");
+kssp.colon = kukit.tk.mkToken('colon', ":");
+kssp.quote = kukit.tk.mkToken('quote', "'");
+kssp.dquote = kukit.tk.mkToken('dquote', '"');
+kssp.backslash = kukit.tk.mkToken('backslash', '\x5c');
+kssp.comma = kukit.tk.mkToken('comma', ",");
+kssp.equals = kukit.tk.mkToken('equals', "=");
/* Parsers */
/*
* class Document
*/
-kukit.kssp.Document = kukit.tk.mkParser('document', {
+kssp.Document = kukit.tk.mkParser('document', {
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
"{": 'new kukit.kssp.Block(this.cursor, kukit.kssp.openBrace)'
});
-kukit.kssp.Document.prototype.process = function() {
+kssp.Document.prototype.process = function() {
this.eventRules = [];
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
@@ -67,7 +69,7 @@
this.txt = '';
};
-kukit.kssp.Document.prototype.addRules = function(rules) {
+kssp.Document.prototype.addRules = function(rules) {
// Create the event rules.
for(var i=0; i<rules.length; i++) {
this.eventRules.push(rules[i]);
@@ -77,11 +79,11 @@
/*
* class Comment
*/
-kukit.kssp.Comment = kukit.tk.mkParser('comment', {
+kssp.Comment = kukit.tk.mkParser('comment', {
// it's not 100% good, but will do
"\*\/": 'this.emitAndReturn(new kukit.kssp.closeComment(this.cursor))'
});
-kukit.kssp.Comment.prototype.process = function() {
+kssp.Comment.prototype.process = function() {
this.result = [];
this.txt = ' ';
};
@@ -89,12 +91,12 @@
/*
* class Block
*/
-kukit.kssp.Block = kukit.tk.mkParser('block', {
+kssp.Block = kukit.tk.mkParser('block', {
";": 'new kukit.kssp.semicolon(this.cursor)',
":": '[new kukit.kssp.colon(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
"}": 'this.emitAndReturn(new kukit.kssp.closeBrace(this.cursor))'
});
-kukit.kssp.Block.prototype.process = function() {
+kssp.Block.prototype.process = function() {
//this.parms = {};
this.eventFullNames = {};
this.actions = new kukit.rd.ActionSet();
@@ -117,7 +119,7 @@
this.txt = '';
};
-kukit.kssp.Block.prototype.parseSelectors = function(key) {
+kssp.Block.prototype.parseSelectors = function(key) {
// Parse the part in an embedded parser
var cursor = new kukit.tk.Cursor(key + ' ');
var parser = new kukit.kssp.KssSelectors(cursor, null, true);
@@ -165,7 +167,7 @@
return results;
}
-kukit.kssp.Block.prototype.addEventDeclaration = function(key, splitkey, value) {
+kssp.Block.prototype.addEventDeclaration = function(key, splitkey, value) {
// evt-<EVTNAME>-<PARAMETER>: <VALUE>
// evt-<NAMESPACE>-<EVTNAME>-<PARAMETER>: <VALUE>
@@ -208,7 +210,7 @@
eventParameters[eventKey] = value.txt;
}
-kukit.kssp.Block.prototype.addActionDeclaration = function(key, splitkey, value) {
+kssp.Block.prototype.addActionDeclaration = function(key, splitkey, value) {
// action-server: <ACTIONNAME>
// action-client: <ACTIONNAME>
// action-client: <NAMESPACE>-<ACTIONNAME>
@@ -250,7 +252,7 @@
}
}
-kukit.kssp.Block.prototype.addActionError = function(action, key, value) {
+kssp.Block.prototype.addActionError = function(action, key, value) {
// <ACTIONNAME>-error: <VALUE>
// default-error: <VALUE>
;;; if (value.isMethod == true) {
@@ -265,7 +267,7 @@
err_action.setType('E');
}
-kukit.kssp.Block.prototype.addActionParameter = function(action, key, value) {
+kssp.Block.prototype.addActionParameter = function(action, key, value) {
var ppRegistries = {
'': kukit.pprovidersGlobalRegistry,
'kssSelector': kukit.sr.pproviderSelRegistry,
@@ -299,7 +301,7 @@
action.parms[key] = value;
}
-kukit.kssp.Block.prototype.addDeclaration = function(key, value) {
+kssp.Block.prototype.addDeclaration = function(key, value) {
// p.s. value is here a KssXxParm. In most cases we check and unwrap it.
// the keys look like this:
//
@@ -368,7 +370,7 @@
/*
* class PropValue
*/
-kukit.kssp.PropValue = kukit.tk.mkParser('propValue', {
+kssp.PropValue = kukit.tk.mkParser('propValue', {
";": 'this.emitAndReturn()',
"}": 'this.emitAndReturn()',
")": 'this.emitAndReturn()',
@@ -378,7 +380,7 @@
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
"(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)'
});
-kukit.kssp.PropValue.prototype.process = function() {
+kssp.PropValue.prototype.process = function() {
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
@@ -424,9 +426,9 @@
}
this.result = [];
};
-kukit.kssp.PropValue.prototype.multiword_allowed = true;
-kukit.kssp.PropValue.prototype.valueClass = kukit.rd.KssMethodValue;
-kukit.kssp.PropValue.prototype.produceTxt = function(txt) {
+kssp.PropValue.prototype.multiword_allowed = true;
+kssp.PropValue.prototype.valueClass = kukit.rd.KssMethodValue;
+kssp.PropValue.prototype.produceTxt = function(txt) {
// txt parms are returned embedded
this.value = new kukit.rd.KssTextValue(txt);
};
@@ -436,7 +438,7 @@
*
* PropValue in method cannot have method-style vars.
*/
-kukit.kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
+kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
";": 'this.emitAndReturn()',
"}": 'this.emitAndReturn()',
")": 'this.emitAndReturn()',
@@ -446,10 +448,10 @@
'"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
});
-kukit.kssp.PropValueInMethod.prototype.multiword_allowed = false;
-kukit.kssp.PropValueInMethod.prototype.process =
- kukit.kssp.PropValue.prototype.process;
-kukit.kssp.PropValueInMethod.prototype.produceTxt = function(txt) {
+kssp.PropValueInMethod.prototype.multiword_allowed = false;
+kssp.PropValueInMethod.prototype.process =
+ kssp.PropValue.prototype.process;
+kssp.PropValueInMethod.prototype.produceTxt = function(txt) {
// txt parms are returned unwrapped
this.txt = txt;
};
@@ -459,7 +461,7 @@
*
* PropValue in pseudo must be single word with no spaces around.
*/
-kukit.kssp.EventValue = kukit.tk.mkParser('propValue', {
+kssp.EventValue = kukit.tk.mkParser('propValue', {
"{": 'this.emitAndReturn()',
" ": 'this.emitAndReturn()',
"\t": 'this.emitAndReturn()',
@@ -470,8 +472,8 @@
"(": '[new kukit.kssp.openParent(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))'
});
-kukit.kssp.EventValue.prototype.multiword_allowed = false;
-kukit.kssp.EventValue.prototype.process = function() {
+kssp.EventValue.prototype.multiword_allowed = false;
+kssp.EventValue.prototype.process = function() {
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
@@ -522,7 +524,7 @@
this.result = [];
};
-kukit.kssp.EventValue.prototype.produceTxt = function(txt) {
+kssp.EventValue.prototype.produceTxt = function(txt) {
// txt parms are returned embedded
this.value = new kukit.rd.KssEventValue(txt, null);
};
@@ -530,11 +532,11 @@
/*
* class String
*/
-kukit.kssp.String = kukit.tk.mkParser('string', {
+kssp.String = kukit.tk.mkParser('string', {
"'": 'this.emitAndReturn(new kukit.kssp.quote(this.cursor))',
'\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
});
-kukit.kssp.String.prototype.process = function() {
+kssp.String.prototype.process = function() {
// collect up the value of the string, omitting the quotes
this.txt = '';
for (var i=1; i<this.result.length-1; i++) {
@@ -545,20 +547,20 @@
/*
* class String2
*/
-kukit.kssp.String2 = kukit.tk.mkParser('string', {
+kssp.String2 = kukit.tk.mkParser('string', {
'"': 'this.emitAndReturn(new kukit.kssp.dquote(this.cursor))',
'\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
});
-kukit.kssp.String2.prototype.process = kukit.kssp.String.prototype.process;
+kssp.String2.prototype.process = kssp.String.prototype.process;
/*
* class StringInSelector
*/
-kukit.kssp.StringInSelector = kukit.tk.mkParser('string', {
+kssp.StringInSelector = kukit.tk.mkParser('string', {
"'": 'this.emitAndReturn(new kukit.kssp.quote(this.cursor))',
'\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
});
-kukit.kssp.StringInSelector.prototype.process = function() {
+kssp.StringInSelector.prototype.process = function() {
// collect up the value of the string, including the quotes
this.txt = '';
for (var i=0; i<this.result.length; i++) {
@@ -569,17 +571,17 @@
/*
* class String2InSelector
*/
-kukit.kssp.String2InSelector = kukit.tk.mkParser('string', {
+kssp.String2InSelector = kukit.tk.mkParser('string', {
'"': 'this.emitAndReturn(new kukit.kssp.dquote(this.cursor))',
'\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
});
-kukit.kssp.String2InSelector.prototype.process = kukit.kssp.StringInSelector.prototype.process;
+kssp.String2InSelector.prototype.process = kssp.StringInSelector.prototype.process;
/*
* class Backslashed
*/
-kukit.kssp.Backslashed = kukit.tk.mkParser('backslashed', {});
-kukit.kssp.Backslashed.prototype.nextStep = function(table) {
+kssp.Backslashed = kukit.tk.mkParser('backslashed', {});
+kssp.Backslashed.prototype.nextStep = function(table) {
// digest the next character and store it as txt
var cursor = this.cursor;
var length = cursor.text.length;
@@ -592,7 +594,7 @@
this.finished = true;
}
};
-kukit.kssp.Backslashed.prototype.process = function() {
+kssp.Backslashed.prototype.process = function() {
this.txt = this.result[1].txt;
};
@@ -601,7 +603,7 @@
*
* methodargs are (a, b, c) lists.
*/
-kukit.kssp.MethodArgs = kukit.tk.mkParser('methodargs', {
+kssp.MethodArgs = kukit.tk.mkParser('methodargs', {
"'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
'"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
",": 'new kukit.kssp.comma(this.cursor)',
@@ -609,7 +611,7 @@
"(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)',
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
});
-kukit.kssp.MethodArgs.prototype.process = function() {
+kssp.MethodArgs.prototype.process = function() {
this.args = [];
// Parse all tokens (except first and last)
var context = {'nextTokenIndex': 1};
@@ -662,14 +664,14 @@
* KSS method selector: (has no spaces in it)
* document:name(id) or behaviour:name(id)
*/
-kukit.kssp.KssSelectors = kukit.tk.mkParser('kssselectors', {
+kssp.KssSelectors = kukit.tk.mkParser('kssselectors', {
"'": 'new kukit.kssp.StringInSelector(this.cursor, kukit.kssp.quote)',
'"': 'new kukit.kssp.String2InSelector(this.cursor, kukit.kssp.dquote)',
",": 'new kukit.kssp.comma(this.cursor)',
"{": 'this.emitAndReturn()',
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
});
-kukit.kssp.KssSelectors.prototype.process = function() {
+kssp.KssSelectors.prototype.process = function() {
this.selectors = [];
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
@@ -701,13 +703,13 @@
* document:name(id) or behaviour:name(id)
* document:name(pprov(id)) or behaviour:name(pprov(id))
*/
-kukit.kssp.KssSelector = kukit.tk.mkParser('kssselector', {
+kssp.KssSelector = kukit.tk.mkParser('kssselector', {
":": '[new kukit.kssp.colon(this.cursor), new ' +
'kukit.kssp.EventValue(this.cursor)]',
"{": 'this.emitAndReturn()',
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
});
-kukit.kssp.KssSelector.prototype.process = function() {
+kssp.KssSelector.prototype.process = function() {
var name;
var namespace = null;
var id = null;
@@ -824,39 +826,40 @@
*
* Rule processor that interfaces with kukit core
*/
-kukit.kssp.KssRuleProcessor = function(href) {
+kssp.KssRuleProcessor = function(href) {
this.href = href;
this.loaded = false;
this.rules = [];
-};
-
-kukit.kssp.KssRuleProcessor.prototype.load = function() {
- // Opera does not support getDomDocument.load, so we use XMLHttpRequest
- var domDoc = new XMLHttpRequest();
- domDoc.open("GET", this.href, false);
- domDoc.send(null);
- this.txt = domDoc.responseText;
- this.loaded = true;
-};
+
+ this.load = function() {
+ // Opera does not support getDomDocument.load, so we use XMLHttpRequest
+ var domDoc = new XMLHttpRequest();
+ domDoc.open("GET", this.href, false);
+ domDoc.send(null);
+ this.txt = domDoc.responseText;
+ this.loaded = true;
+ };
-kukit.kssp.KssRuleProcessor.prototype.parse = function() {
-;;; try {
- //Build a parser and parse the text into it
- var cursor = new kukit.tk.Cursor(this.txt);
- var parser = new kukit.kssp.Document(cursor, null, true);
- // Store event rules in the common list
- for (var i=0; i<parser.eventRules.length; i++) {
- var rule = parser.eventRules[i];
- rule.kssSelector.prepareId();
- this.rules.push(rule);
- }
-;;; } catch(e) {
-;;; // ParsingError are logged.
-;;; if (e.name == 'ParsingError' || e.name == 'UndefinedEventError') {
-;;; throw kukit.err.kssParsingError(e, this.href);
-;;; } else {
-;;; throw e;
-;;; }
-;;; }
+ this.parse = function() {
+;;; try {
+ //Build a parser and parse the text into it
+ var cursor = new kukit.tk.Cursor(this.txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ // Store event rules in the common list
+ for (var i=0; i<parser.eventRules.length; i++) {
+ var rule = parser.eventRules[i];
+ rule.kssSelector.prepareId();
+ this.rules.push(rule);
+ }
+;;; } catch(e) {
+;;; // ParsingError are logged.
+;;; if (e.name == 'ParsingError' || e.name == 'UndefinedEventError') {
+;;; throw kukit.err.kssParsingError(e, this.href);
+;;; } else {
+;;; throw e;
+;;; }
+;;; }
+ };
};
+}(); /// MODULE END
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 Sun Dec 16 20:54:07 2007
@@ -19,186 +19,190 @@
/* Simple but effective tokenizing parser engine */
-kukit.tk = {};
+
+kukit.tk = new function() { /// MODULE START
+
+var tk = this;
/*
* class _TokenBase
*/
-kukit.tk._TokenBase = function() {
-};
+tk._TokenBase = function() {
-kukit.tk._TokenBase.prototype.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);
+ };
-kukit.tk._TokenBase.prototype.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);
+ }
}
- }
+ };
};
/*
* class _ParserBase
*/
-kukit.tk._ParserBase = function() {
-};
-
-kukit.tk._ParserBase.prototype = new kukit.tk._TokenBase;
+tk._ParserBase = function() {
-kukit.tk._ParserBase.prototype.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;
+ };
-kukit.tk._ParserBase.prototype.nextStep = function(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 kukit.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];
+ 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;
}
- for (var i=0; i<tokens.length; i++) {
- this.result.push(tokens[i]);
+ }
+ // 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]);
+ }
}
}
- }
-};
-
-/* token postprocess support */
+ };
-kukit.tk._ParserBase.prototype.process = function() {
- // default process after tokenization
- this.txt = '';
- for (var i=0; i<this.result.length; i++) {
- this.txt += this.result[i].txt;
- }
-};
+ /* token postprocess support */
-kukit.tk._ParserBase.prototype.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);
+ this.process = function() {
+ // default process after tokenization
+ this.txt = '';
+ for (var i=0; i<this.result.length; i++) {
+ this.txt += this.result[i].txt;
}
- } 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);
+ }
+ } else {
+ if (i >= this.result.length) {
+;;; kukit.E = 'Missing token.';
+ this.emitError(kukit.E);
+ }
}
- }
- context.token = this.result[i];
- context.nextTokenIndex += 1;
-};
+ context.token = this.result[i];
+ context.nextTokenIndex += 1;
+ };
-kukit.tk._ParserBase.prototype.resultIsNullOrNotToken =
- function(token, currentValue) {
- return (!token || currentValue.symbol != token.prototype.symbol);
-};
+ this.resultIsNullOrNotToken =
+ function(token, currentValue) {
+ return (!token || currentValue.symbol != token.prototype.symbol);
+ };
-kukit.tk._ParserBase.prototype.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))
+ );
+ };
-kukit.tk._ParserBase.prototype.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);
+ };
-kukit.tk._ParserBase.prototype.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;
+ };
-kukit.tk._ParserBase.prototype.removeWhitespaces = function(txt) {
- // removes ws but leaves leading and trailing one
- if (txt != ' ') { //speedup only
- txt = txt.replace(/[\r\n\t ]+/g, ' ');
- }
- return txt;
-};
-
-kukit.tk._ParserBase.prototype.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();
+
/*
* class Fraction
*/
-kukit.tk.Fraction = function(cursor, endpos) {
+tk.Fraction = function(cursor, endpos) {
this.txt = cursor.text.substring(cursor.pos, endpos);
this.startpos = cursor.pos;
this.endpos = cursor.pos;
this.finished = true;
};
-kukit.tk.Fraction.prototype.symbol = 'fraction';
+tk.Fraction.prototype.symbol = 'fraction';
/* Factories to make tokens and parsers */
-kukit.tk.mkToken = function(symbol, txt) {
+tk.mkToken = function(symbol, txt) {
// Poor man's subclassing.
f = function(cursor) {
this.cursor = cursor;
@@ -215,15 +219,16 @@
this.endpos = cursor.pos;
//this.cursor = null;
};
- f.prototype = new kukit.tk._TokenBase;
+ f.prototype = new tk._TokenBase();
f.prototype.symbol = symbol;
f.prototype.txt = txt;
return f;
};
-kukit.tk.mkParser = function(symbol, table) {
+tk.mkParser = function(symbol, table) {
// Poor man's subclassing.
f = function(cursor, tokenClass, isTopLevelParser) {
+ this.table = table
this.cursor = cursor;
this.startpos = cursor.pos;
this.finished = false;
@@ -235,7 +240,7 @@
}
this.updateFinished();
while (!this.finished) {
- this.nextStep(table);
+ this.nextStep();
this.updateFinished();
}
this.endpos = cursor.pos;
@@ -244,7 +249,7 @@
//this.cursor = null;
};
- f.prototype = new kukit.tk._ParserBase;
+ f.prototype = new tk._ParserBase();
f.prototype.symbol = symbol;
return f;
};
@@ -252,44 +257,46 @@
/*
* class Cursor
*/
-kukit.tk.Cursor = function(txt) {
+tk.Cursor = function(txt) {
this.text = txt;
this.pos = 0;
-};
-kukit.tk.Cursor.prototype.makeMarker = function(pos) {
- // create a cursor to mark this position
- var cursor = new kukit.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;
+ };
-kukit.tk.Cursor.prototype.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};
+ };
-kukit.tk.Cursor.prototype.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;
+ };
};
+
+}(); /// MODULE END
More information about the Kukit-checkins
mailing list