[KSS-checkins] r46020 - in kukit/kukit.js/trunk: kukit tests
gotcha at codespeak.net
gotcha at codespeak.net
Mon Aug 27 14:50:44 CEST 2007
Author: gotcha
Date: Mon Aug 27 14:50:42 2007
New Revision: 46020
Modified:
kukit/kukit.js/trunk/kukit/kssparser.js
kukit/kukit.js/trunk/kukit/tokenizer.js
kukit/kukit.js/trunk/tests/test_kssparser.js
Log:
Renamed PropValueInPseudo to EventValue ; cleaned up isToken
Modified: kukit/kukit.js/trunk/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kssparser.js (original)
+++ kukit/kukit.js/trunk/kukit/kssparser.js Mon Aug 27 14:50:42 2007
@@ -351,7 +351,7 @@
this.digestTxt(cursor, kukit.tk.Fraction, kukit.kssp.Comment);
this.txt = '';
var txt = cursor.txt;
- if (this.ifToken(cursor, kukit.kssp.String)) {
+ if (this.isToken(cursor, kukit.kssp.String)) {
// The previous txt must be all whitespace.
if (txt) {
;;; kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
@@ -361,7 +361,7 @@
// the next one must be a string.
this.expectToken(cursor, kukit.kssp.String);
this.produceTxt(cursor.token.txt);
- } else if (this.ifToken(cursor, kukit.kssp.MethodArgs)) {
+ } else if (this.isToken(cursor, kukit.kssp.MethodArgs)) {
// see if not empty and has no spaces in it
if (! txt || txt.indexOf(' ') != -1) {
;;; kukit.E = 'Wrong value : method name [' + txt + '] cannot ';
@@ -422,11 +422,11 @@
};
/*
-* class PropValueInPseudo
+* class EventValue
*
* PropValue in pseudo must ba single word with no spaces around.
*/
-kukit.kssp.PropValueInPseudo = kukit.tk.mkParser('propvalue', {
+kukit.kssp.EventValue = kukit.tk.mkParser('propvalue', {
"{": 'this.emitAndReturn()',
" ": 'this.emitAndReturn()',
"\t": 'this.emitAndReturn()',
@@ -437,11 +437,11 @@
"(": 'this.emitAndReturn(new kukit.kssp.MethodArgs(this.src,' +
'kukit.kssp.openparent))'
});
-kukit.kssp.PropValueInPseudo.prototype.multiword_allowed = false;
-kukit.kssp.PropValueInPseudo.prototype.process =
+kukit.kssp.EventValue.prototype.multiword_allowed = false;
+kukit.kssp.EventValue.prototype.process =
kukit.kssp.PropValue.prototype.process;
-kukit.kssp.PropValueInPseudo.prototype.valueClass = kukit.rd.KssPseudoValue;
-kukit.kssp.PropValueInPseudo.prototype.produceTxt = function(txt) {
+kukit.kssp.EventValue.prototype.valueClass = kukit.rd.KssPseudoValue;
+kukit.kssp.EventValue.prototype.produceTxt = function(txt) {
// txt parms are returned embedded
this.value = new kukit.rd.KssPseudoValue(txt, []);
};
@@ -544,7 +544,7 @@
*/
kukit.kssp.KssSelector = kukit.tk.mkParser('kssselector', {
":": '[new kukit.kssp.colon(this.src), new ' +
- 'kukit.kssp.PropValueInPseudo(this.src)]',
+ 'kukit.kssp.EventValue(this.src)]',
"{": 'this.emitAndReturn()',
"\/\*": 'new kukit.kssp.Comment(this.src, kukit.kssp.commentbegin)'
});
@@ -581,7 +581,7 @@
tokenindex -= 2;
if (tokenindex < 0
|| (this.result[tokenindex+2].symbol !=
- kukit.kssp.PropValueInPseudo.prototype.symbol)
+ kukit.kssp.EventValue.prototype.symbol)
|| (this.result[tokenindex+1].symbol !=
kukit.kssp.colon.prototype.symbol)
|| (this.result[tokenindex].symbol !=
Modified: kukit/kukit.js/trunk/kukit/tokenizer.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/tokenizer.js (original)
+++ kukit/kukit.js/trunk/kukit/tokenizer.js Mon Aug 27 14:50:42 2007
@@ -125,14 +125,22 @@
cursor.next += 1;
};
-kukit.tk._ParserBase.prototype.ifToken =
+kukit.tk._ParserBase.prototype.resultIsNullOrNotToken =
+ function(token, currentValue) {
+ return (!token || currentValue.symbol != token.prototype.symbol);
+};
+
+kukit.tk._ParserBase.prototype.isToken =
function(cursor, token1, token2, token3, token4) {
var i = cursor.next;
- return (! (i >= this.result.length ||
- this.result[i].symbol != token1.prototype.symbol
- && (!token2 || this.result[i].symbol != token2.prototype.symbol
- && (!token3 || this.result[i].symbol != token3.prototype.symbol
- && (!token4 || this.result[i].symbol != token4.prototype.symbol)))));
+ 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 =
@@ -148,7 +156,7 @@
// digests the txt from the tokens, ignores given token
// exact value: no whitespace removal
var result = '';
- while (this.ifToken(cursor, token1, token2, token3, token4)) {
+ while (this.isToken(cursor, token1, token2, token3, token4)) {
result += this.result[cursor.next].txt;
cursor.next ++;
}
Modified: kukit/kukit.js/trunk/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/tests/test_kssparser.js (original)
+++ kukit/kukit.js/trunk/tests/test_kssparser.js Mon Aug 27 14:50:42 2007
@@ -218,19 +218,19 @@
'Wrong value : unallowed characters after the property', 17);
};
- this.testPropValueInPseudo = function() {
+ this.testEventValue = function() {
// Parsing prop values in pseudo (no methods allowed)
var txt= "b";
var src = new kukit.tk.Cursor(txt);
- var parser = new kukit.kssp.PropValueInPseudo(src, null, true);
+ var parser = new kukit.kssp.EventValue(src, null, true);
this.assertEquals(parser.finished, true);
this.assertEquals(parser.value.methodName, 'b');
// multiword ok but does not finish
txt= "b c";
src = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValueInPseudo(src, null, true);
+ parser = new kukit.kssp.EventValue(src, null, true);
this.assertEquals(parser.finished, true);
this.assertEquals(src.pos, 1);
this.assertEquals(parser.value.methodName, 'b');
@@ -238,7 +238,7 @@
// space ok but does not finish
txt= " b";
src = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValueInPseudo(src, null, true);
+ parser = new kukit.kssp.EventValue(src, null, true);
this.assertEquals(parser.finished, true);
this.assertEquals(src.pos, 0);
this.assertEquals(parser.value.methodName, '');
@@ -246,7 +246,7 @@
// ok, does not finish
txt= "apples/* more comments and*/";
src = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValueInPseudo(src, null, true);
+ parser = new kukit.kssp.EventValue(src, null, true);
this.assertEquals(parser.finished, true);
this.assertEquals(src.pos, 6);
this.assertEquals(parser.value.methodName, 'apples');
@@ -254,7 +254,7 @@
// params ok
txt= "click(x)";
src = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValueInPseudo(src, null, true);
+ parser = new kukit.kssp.EventValue(src, null, true);
this.assertEquals(parser.finished, true);
this.assertEquals(parser.value.methodName, 'click');
this.assertListEquals(parser.value.args, ['x']);
@@ -266,7 +266,7 @@
// not ok but we don't parse an error
//txt= "'drag'(x)";
//src = new kukit.tk.Cursor(txt);
- //this.assertParsingError(kukit.kssp.PropValueInPseudo, src, null, true,
+ //this.assertParsingError(kukit.kssp.EventValue, src, null, true,
// 'Excess characters after the property value', 16);
};
More information about the Kukit-checkins
mailing list