[KSS-checkins] r49931 - kukit/kukit.js/branch/finish-closures/kukit
gotcha at codespeak.net
gotcha at codespeak.net
Wed Dec 19 14:13:14 CET 2007
Author: gotcha
Date: Wed Dec 19 14:13:14 2007
New Revision: 49931
Modified:
kukit/kukit.js/branch/finish-closures/kukit/kssparser.js
kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
Log:
class closures -- step 5
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 Wed Dec 19 14:13:14 2007
@@ -74,7 +74,7 @@
};
};
-kssp.Document = kukit.tk.mkParserBis('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)'
},
@@ -90,7 +90,7 @@
this.txt = ' ';
};
};
-kssp.Comment = kukit.tk.mkParserBis('comment', {
+kssp.Comment = kukit.tk.mkParser('comment', {
// it's not 100% good, but will do
"\*\/": 'this.emitAndReturn(new kukit.kssp.closeComment(this.cursor))'
},
@@ -372,7 +372,7 @@
}
};
};
-kssp.Block = kukit.tk.mkParserBis('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))'
@@ -439,7 +439,7 @@
};
};
-kssp.PropValue = kukit.tk.mkParserBis('propValue', {
+kssp.PropValue = kukit.tk.mkParser('propValue', {
";": 'this.emitAndReturn()',
"}": 'this.emitAndReturn()',
")": 'this.emitAndReturn()',
@@ -465,7 +465,7 @@
};
};
_PropValueInMethod.prototype = new _PropValue();
-kssp.PropValueInMethod = kukit.tk.mkParserBis('propValue', {
+kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
";": 'this.emitAndReturn()',
"}": 'this.emitAndReturn()',
")": 'this.emitAndReturn()',
@@ -540,7 +540,7 @@
this.value = new kukit.rd.KssEventValue(txt, null);
};
};
-kssp.EventValue = kukit.tk.mkParserBis('propValue', {
+kssp.EventValue = kukit.tk.mkParser('propValue', {
"{": 'this.emitAndReturn()',
" ": 'this.emitAndReturn()',
"\t": 'this.emitAndReturn()',
@@ -566,7 +566,7 @@
}
};
};
-kssp.String = kukit.tk.mkParserBis('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)'
},
@@ -576,7 +576,7 @@
/*
* class String2
*/
-kssp.String2 = kukit.tk.mkParserBis('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)'
},
@@ -595,7 +595,7 @@
}
};
};
-kssp.StringInSelector = kukit.tk.mkParserBis('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)'
},
@@ -605,7 +605,7 @@
/*
* class String2InSelector
*/
-kssp.String2InSelector = kukit.tk.mkParserBis('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)'
},
@@ -633,7 +633,7 @@
this.txt = this.result[1].txt;
};
};
-kssp.Backslashed = kukit.tk.mkParserBis('backslashed', {
+kssp.Backslashed = kukit.tk.mkParser('backslashed', {
},
_Backslashed
);
@@ -643,6 +643,51 @@
*
* methodargs are (a, b, c) lists.
*/
+var _MethodArgs = function() {
+ this.process = function() {
+ this.args = [];
+ // Parse all tokens (except first and last)
+ var context = {'nextTokenIndex': 1};
+ while (context.nextTokenIndex < this.result.length-1) {
+ this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ var value = context.txt;
+ if (! value) {
+ // allow to bail out after widow ,
+ if (context.nextTokenIndex == this.result.length-1) break;
+ // here be a string then.
+ this.expectToken(context, kukit.kssp.String);
+ value = context.token.txt;
+ } else {
+ // Just a value, must be one word then.
+ if (value.indexOf(' ') != -1) {
+;;; kukit.E = 'Wrong method argument [' + value;
+;;; kukit.E += '] : value cannot have spaces (if needed,';
+;;; kukit.E += ' quote it as a string).';
+ this.emitError(kukit.E);
+ }
+ }
+ var valueClass;
+ var args;
+ var providedValue;
+ if (this.notInTokens(context, kukit.kssp.MethodArgs)){
+ this.expectToken(context, kukit.kssp.MethodArgs);
+ valueClass = kukit.rd.KssMethodValue;
+ args = context.token.args;
+ providedValue = new valueClass(value, args);
+ } else {
+ // XXX This should be wrapped too !
+ //valueClass = kukit.rd.KssTextValue;
+ //providedValue = new valueClass(value);
+ providedValue = value;
+ }
+ this.args.push(providedValue);
+ if (context.nextTokenIndex == this.result.length-1) break;
+ this.expectToken(context, kukit.kssp.comma);
+ }
+ this.result = [];
+ this.txt = '';
+ };
+};
kssp.MethodArgs = kukit.tk.mkParser('methodargs', {
"'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
'"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
@@ -650,50 +695,10 @@
")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))',
"(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)',
"\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
- });
-kssp.MethodArgs.prototype.process = function() {
- this.args = [];
- // Parse all tokens (except first and last)
- var context = {'nextTokenIndex': 1};
- while (context.nextTokenIndex < this.result.length-1) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
- var value = context.txt;
- if (! value) {
- // allow to bail out after widow ,
- if (context.nextTokenIndex == this.result.length-1) break;
- // here be a string then.
- this.expectToken(context, kukit.kssp.String);
- value = context.token.txt;
- } else {
- // Just a value, must be one word then.
- if (value.indexOf(' ') != -1) {
-;;; kukit.E = 'Wrong method argument [' + value;
-;;; kukit.E += '] : value cannot have spaces (if needed,';
-;;; kukit.E += ' quote it as a string).';
- this.emitError(kukit.E);
- }
- }
- var valueClass;
- var args;
- var providedValue;
- if (this.notInTokens(context, kukit.kssp.MethodArgs)){
- this.expectToken(context, kukit.kssp.MethodArgs);
- valueClass = kukit.rd.KssMethodValue;
- args = context.token.args;
- providedValue = new valueClass(value, args);
- } else {
- // XXX This should be wrapped too !
- //valueClass = kukit.rd.KssTextValue;
- //providedValue = new valueClass(value);
- providedValue = value;
- }
- this.args.push(providedValue);
- if (context.nextTokenIndex == this.result.length-1) break;
- this.expectToken(context, kukit.kssp.comma);
- }
- this.result = [];
- this.txt = '';
-};
+ },
+ _MethodArgs
+ );
+
/*
* class KssSelectors
@@ -704,33 +709,38 @@
* KSS method selector: (has no spaces in it)
* document:name(id) or behaviour:name(id)
*/
+var _KssSelectors = function() {
+ this.process = function() {
+ this.selectors = [];
+ // Parse all tokens (including first and last)
+ var context = {'nextTokenIndex': 0};
+ while (context.nextTokenIndex < this.result.length) {
+ this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment,
+ kukit.kssp.String, kukit.kssp.String2);
+ var cursor = new kukit.tk.Cursor(context.txt + ' ')
+ var parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.selectors.push(parser.kssSelector);
+ if (context.nextTokenIndex == this.result.length) break;
+ this.expectToken(context, kukit.kssp.comma);
+ if (context.nextTokenIndex == this.result.length) {
+;;; kukit.E = 'Wrong event selector : trailing comma';
+ this.emitError(kukit.E);
+ }
+ };
+ this.result = [];
+ this.txt = '';
+ };
+};
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)'
- });
-kssp.KssSelectors.prototype.process = function() {
- this.selectors = [];
- // Parse all tokens (including first and last)
- var context = {'nextTokenIndex': 0};
- while (context.nextTokenIndex < this.result.length) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment,
- kukit.kssp.String, kukit.kssp.String2);
- var cursor = new kukit.tk.Cursor(context.txt + ' ')
- var parser = new kukit.kssp.KssSelector(cursor, null, true);
- this.selectors.push(parser.kssSelector);
- if (context.nextTokenIndex == this.result.length) break;
- this.expectToken(context, kukit.kssp.comma);
- if (context.nextTokenIndex == this.result.length) {
-;;; kukit.E = 'Wrong event selector : trailing comma';
- this.emitError(kukit.E);
- }
- };
- this.result = [];
- this.txt = '';
-};
+ },
+ _KssSelectors
+ );
+
/*
* class KssSelector
@@ -743,123 +753,127 @@
* document:name(id) or behaviour:name(id)
* document:name(pprov(id)) or behaviour:name(pprov(id))
*/
+var _KssSelector = function() {
+ this.process = function() {
+ var name;
+ var namespace = null;
+ var id = null;
+ var tokenIndex = this.result.length - 1;
+ // Find the method parms and calculate the end of css parms. (RL)
+ var cycle = true;
+ while (cycle && tokenIndex >= 0) {
+ var token = this.result[tokenIndex];
+ switch (token.symbol) {
+ case kukit.tk.Fraction.prototype.symbol: {
+ // if all spaces, go to previous one
+ if (token.txt.match(/^[\r\n\t ]*$/) != null) {
+ tokenIndex -= 1;
+ } else {
+;;; kukit.E = 'Wrong event selector : missing event ';
+;;; kukit.E += 'qualifier :<EVENTNAME> ';
+;;; kukit.E += 'or :<EVENTNAME>(<ID>).';
+ this.emitError(kukit.E);
+ }
+ } break;
+ case kukit.kssp.Comment.prototype.symbol: {
+ tokenIndex -= 1;
+ } break;
+ default: {
+ cycle = false;
+ } break;
+ }
+ }
+ // Now we found the token that must be <fraction> <colon> <propValue>.
+ tokenIndex -= 2;
+ if (tokenIndex < 0
+ || (this.result[tokenIndex+2].symbol !=
+ kukit.kssp.EventValue.prototype.symbol)
+ || (this.result[tokenIndex+1].symbol !=
+ kukit.kssp.colon.prototype.symbol)
+ || (this.result[tokenIndex].symbol !=
+ kukit.tk.Fraction.prototype.symbol)) {
+;;; kukit.E = 'Wrong event selector : missing event qualifier ';
+;;; kukit.E += ':<EVENTNAME> or :<EVENTNAME>(<ID>).';
+ this.emitError(kukit.E);
+ }
+ // See that the last fraction does not end with space.
+ var lasttoken = this.result[tokenIndex];
+ var commatoken = this.result[tokenIndex+1];
+ var pseudotoken = this.result[tokenIndex+2];
+ var txt = lasttoken.txt;
+ if (txt.match(/[\r\n\t ]$/) != null) {
+;;; kukit.E = 'Wrong event selector :';
+;;; kukit.E += ' space before the colon.';
+ this.emitError(kukit.E);
+ }
+ if (! pseudotoken.value.methodName) {
+;;; kukit.E = 'Wrong event selector :';
+;;; kukit.E += ' event name cannot have spaces.';
+ this.emitError(kukit.E);
+ }
+ css = this.cursor.text.substring(this.startpos, commatoken.startpos);
+ // Decide if we have an event or a method selector.
+ // We have a method selector if a single word "document" or "behaviour".
+ var singleword = css.replace(/[\r\n\t ]/g, ' ');
+ if (singleword && singleword.charAt(0) == ' ') {
+ singleword = singleword.substring(1);
+ }
+ var isEvent = (singleword != 'document' && singleword != 'behaviour');
+ if (! isEvent) {
+ // just store the single word, in case of event selectors
+ css = singleword;
+ }
+ // create the selector.
+ var id = null;
+ var ppid = null;
+ if (pseudotoken.value.arg) {
+ // We have something in the parentheses after the event name.
+ if (pseudotoken.value.arg.isMethod) {
+ // we have a param provider here. Just store.
+ ppid = pseudotoken.value.arg;
+ // Check its syntax too.
+ ppid.check(kukit.pprovidersGlobalRegistry);
+ } else {
+ // just an id. Express in txt.
+ id = pseudotoken.value.arg.txt;
+ }
+ }
+ var name = pseudotoken.value.methodName;
+ var splitname = name.split('-');
+ var namespace = null;
+ if (splitname.length > 2) {
+;;; kukit.E = 'Wrong event selector [' + name + '] : ';
+;;; kukit.E += 'qualifier should be :<EVENTNAME> or ';
+;;; kukit.E += ':<NAMESPACE>-<EVENTNAME>.';
+ this.emitError(kukit.E);
+ } else if (splitname.length == 2) {
+ name = splitname[1];
+ namespace = splitname[0];
+ }
+ // Protect the error for better logging
+;;; try {
+ this.kssSelector = new kukit.rd.KssSelector(isEvent, css, name,
+ namespace, id, ppid);
+;;; } catch(e) {
+;;; if (e.name == 'KssSelectorError') {
+;;; // Log the message
+;;; this.emitError(e.toString());
+;;; } else {
+;;; throw e;
+;;; }
+;;; }
+ this.txt = '';
+ this.result = [];
+ };
+};
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)'
- });
-kssp.KssSelector.prototype.process = function() {
- var name;
- var namespace = null;
- var id = null;
- var tokenIndex = this.result.length - 1;
- // Find the method parms and calculate the end of css parms. (RL)
- var cycle = true;
- while (cycle && tokenIndex >= 0) {
- var token = this.result[tokenIndex];
- switch (token.symbol) {
- case kukit.tk.Fraction.prototype.symbol: {
- // if all spaces, go to previous one
- if (token.txt.match(/^[\r\n\t ]*$/) != null) {
- tokenIndex -= 1;
- } else {
-;;; kukit.E = 'Wrong event selector : missing event ';
-;;; kukit.E += 'qualifier :<EVENTNAME> ';
-;;; kukit.E += 'or :<EVENTNAME>(<ID>).';
- this.emitError(kukit.E);
- }
- } break;
- case kukit.kssp.Comment.prototype.symbol: {
- tokenIndex -= 1;
- } break;
- default: {
- cycle = false;
- } break;
- }
- }
- // Now we found the token that must be <fraction> <colon> <propValue>.
- tokenIndex -= 2;
- if (tokenIndex < 0
- || (this.result[tokenIndex+2].symbol !=
- kukit.kssp.EventValue.prototype.symbol)
- || (this.result[tokenIndex+1].symbol !=
- kukit.kssp.colon.prototype.symbol)
- || (this.result[tokenIndex].symbol !=
- kukit.tk.Fraction.prototype.symbol)) {
-;;; kukit.E = 'Wrong event selector : missing event qualifier ';
-;;; kukit.E += ':<EVENTNAME> or :<EVENTNAME>(<ID>).';
- this.emitError(kukit.E);
- }
- // See that the last fraction does not end with space.
- var lasttoken = this.result[tokenIndex];
- var commatoken = this.result[tokenIndex+1];
- var pseudotoken = this.result[tokenIndex+2];
- var txt = lasttoken.txt;
- if (txt.match(/[\r\n\t ]$/) != null) {
-;;; kukit.E = 'Wrong event selector :';
-;;; kukit.E += ' space before the colon.';
- this.emitError(kukit.E);
- }
- if (! pseudotoken.value.methodName) {
-;;; kukit.E = 'Wrong event selector :';
-;;; kukit.E += ' event name cannot have spaces.';
- this.emitError(kukit.E);
- }
- css = this.cursor.text.substring(this.startpos, commatoken.startpos);
- // Decide if we have an event or a method selector.
- // We have a method selector if a single word "document" or "behaviour".
- var singleword = css.replace(/[\r\n\t ]/g, ' ');
- if (singleword && singleword.charAt(0) == ' ') {
- singleword = singleword.substring(1);
- }
- var isEvent = (singleword != 'document' && singleword != 'behaviour');
- if (! isEvent) {
- // just store the single word, in case of event selectors
- css = singleword;
- }
- // create the selector.
- var id = null;
- var ppid = null;
- if (pseudotoken.value.arg) {
- // We have something in the parentheses after the event name.
- if (pseudotoken.value.arg.isMethod) {
- // we have a param provider here. Just store.
- ppid = pseudotoken.value.arg;
- // Check its syntax too.
- ppid.check(kukit.pprovidersGlobalRegistry);
- } else {
- // just an id. Express in txt.
- id = pseudotoken.value.arg.txt;
- }
- }
- var name = pseudotoken.value.methodName;
- var splitname = name.split('-');
- var namespace = null;
- if (splitname.length > 2) {
-;;; kukit.E = 'Wrong event selector [' + name + '] : ';
-;;; kukit.E += 'qualifier should be :<EVENTNAME> or ';
-;;; kukit.E += ':<NAMESPACE>-<EVENTNAME>.';
- this.emitError(kukit.E);
- } else if (splitname.length == 2) {
- name = splitname[1];
- namespace = splitname[0];
- }
- // Protect the error for better logging
-;;; try {
- this.kssSelector = new kukit.rd.KssSelector(isEvent, css, name,
- namespace, id, ppid);
-;;; } catch(e) {
-;;; if (e.name == 'KssSelectorError') {
-;;; // Log the message
-;;; this.emitError(e.toString());
-;;; } else {
-;;; throw e;
-;;; }
-;;; }
- this.txt = '';
- this.result = [];
-};
+ },
+ _KssSelector
+ );
/*
* class KssRuleProcessor
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 Wed Dec 19 14:13:14 2007
@@ -225,36 +225,7 @@
return f;
};
-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;
- this.isTopLevelParser = isTopLevelParser;
- this.result = [];
- if (tokenClass) {
- // Reentry with starting token propagated.
- this.result.push(new tokenClass(this.cursor));
- }
- this.updateFinished();
- while (!this.finished) {
- this.nextStep();
- this.updateFinished();
- }
- this.endpos = cursor.pos;
- // post processing
- this.process();
-
- //this.cursor = null;
- };
- f.prototype = new tk._ParserBase();
- f.prototype.symbol = symbol;
- return f;
-};
-
-tk.mkParserBis = function(symbol, table, _class) {
+tk.mkParser = function(symbol, table, _class) {
// Poor man's subclassing.
f = function(cursor, tokenClass, isTopLevelParser) {
this.table = table
More information about the Kukit-checkins
mailing list