[KSS-checkins] r50396 - in kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes: . kukit tests
reebalazs at codespeak.net
reebalazs at codespeak.net
Sun Jan 6 17:19:29 CET 2008
Author: reebalazs
Date: Sun Jan 6 17:19:29 2008
New Revision: 50396
Modified:
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/ (props changed)
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js
Log:
Refactor PropValue, add MultiPropValue
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js Sun Jan 6 17:19:29 2008
@@ -393,58 +393,120 @@
"(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)'
});
kukit.kssp.PropValue.prototype.process = function() {
+ // For multivalue only
+ this.values = []
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
this.txt = '';
- var txt = context.txt;
- if (this.notInTokens(context, kukit.kssp.String)) {
- // The previous txt must be all whitespace.
- if (txt) {
-;;; kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
-;;; kukit.E += ' before a string.';
- this.emitError(kukit.E);
- }
- // the next one must be a string.
- this.expectToken(context, kukit.kssp.String);
- this.produceTxt(context.token.txt);
- } else if (this.notInTokens(context, 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 ';
-;;; kukit.E += 'have spaces.';
- this.emitError(kukit.E);
- }
- // the next one must be the rules
- this.expectToken(context, kukit.kssp.MethodArgs);
- this.value = new this.valueClass(txt, context.token.args);
- } else {
- // not a string or method: check if we allowed multiword.
- if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
-;;; kukit.E = 'Wrong value : [' + txt + '] cannot have spaces.';
- this.emitError(kukit.E);
+ // Iterate for multiple values (in case allowed.)
+ // txtCarry holds the part of text that we need to consider
+ // as a possible method name, in case method args follow.
+ var txtCarry = '';
+ while (context.nextTokenIndex < this.result.length) {
+ if (this.notInTokens(context, kukit.kssp.String)) {
+ // A string token follows:
+ if (txtCarry) {
+ // If we have a txt carry left, it needs to be
+ // produced first, separately.
+ this.produceTxt(txtCarry);
+ txtCarry = '';
+ }
+ // the next one must be a string.
+ this.expectToken(context, kukit.kssp.String);
+ this.produceTxt(context.token.txt);
+ } else if (this.notInTokens(context, kukit.kssp.MethodArgs)) {
+ // A MethodArgs token follows:
+ // see if not empty
+ if (! txtCarry) {
+;;; // Be a little more intelligent with this error.
+;;; // If we are single value, and there is a value,
+;;; // the following raises a smarter error message, complaining
+;;; // about the () as excess.
+;;; this.addValue(null, '(');
+;;; // otherwise, just do the next error message:
+;;; kukit.E = 'Wrong value : empty method name.';
+ this.emitError(kukit.E);
+ }
+ // the next one must be the (a1, a2, ...an) method args.
+ this.expectToken(context, kukit.kssp.MethodArgs);
+ // The txtCarry will be used as the name of the method.
+ this.addValue(new kukit.rd.KssMethodValue(txtCarry, context.token.args),
+ txtCarry);
+ txtCarry = '';
+ } else {
+ // Try to digest another fraction.
+ this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ //
+ // Split the fraction to words. We may have a word
+ // and we may have a MethodArg after:
+ // wordone ... wordlast(...) ...
+ // ^^^^^^^^^^^^^^^^^^^^ - these are in the Fraction
+ // ^^^^^ - these are the MethodArgs
+ // So we produce all strings except the last one, and
+ // continue the cycle with the last one (worlast) as txt.
+ // This enables it to be produced with the MethodArgs.
+ //
+ var words = context.txt.split(' ');
+ // Emit the original txtCarry - if there is one.
+ if (txtCarry) {
+ this.produceTxt(txtCarry);
+ txtCarry = '';
+ }
+ // If we have input, process it.
+ if (words.length > 0) {
+ // Produce all strings except the last one
+ for (var i=0; i<words.length - 1; i++) {
+ this.produceTxt(words[i]);
+ }
+ // Carry the last one to the next iteration.
+ txtCarry = words[words.length - 1];
+ }
}
- this.produceTxt(txt);
}
- // see what's after
- if (context.nextTokenIndex < this.result.length) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
- // we have to be at the end and have no text after
- if (context.nextTokenIndex < this.result.length || context.txt) {
-;;; kukit.E = 'Wrong value : unallowed characters after ';
-;;; kukit.E += 'the property.';
- this.emitError(kukit.E);
- }
+ if (txtCarry) {
+ // If we have a txt carry, it needs to be produced finally.
+ this.produceTxt(txtCarry);
}
this.result = [];
};
-kukit.kssp.PropValue.prototype.multiword_allowed = true;
-kukit.kssp.PropValue.prototype.valueClass = kukit.rd.KssMethodValue;
kukit.kssp.PropValue.prototype.produceTxt = function(txt) {
// txt parms are returned embedded
- this.value = new kukit.rd.KssTextValue(txt);
+ this.addValue(new kukit.rd.KssTextValue(txt), txt);
+};
+kukit.kssp.PropValue.prototype.addValue = function(value, errInfo) {
+ // Do not allow a second value
+ if (this.value) {
+;;; kukit.E = 'Wrong value : unallowed characters [';
+;;; kukit.E += errInfo + '] after ';
+;;; kukit.E += 'the argument.';
+ this.emitError(kukit.E);
+ }
+ this.value = value;
+};
+
+
+/*
+* class MultiPropValue
+*
+* A list of PropValue-s (arguments), separated by whitespace
+*/
+kukit.kssp.MultiPropValue = kukit.tk.mkParser('multiPropValue', {
+ ";": 'this.emitAndReturn()',
+ "}": 'this.emitAndReturn()',
+ ")": 'this.emitAndReturn()',
+ ",": 'this.emitAndReturn()',
+ "'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
+ '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
+ "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
+ "(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)'
+ });
+kukit.kssp.MultiPropValue.prototype.process = kukit.kssp.PropValue.prototype.process;
+kukit.kssp.MultiPropValue.prototype.produceTxt = kukit.kssp.PropValue.prototype.produceTxt;
+kukit.kssp.MultiPropValue.prototype.addValue = function(value, errInfo) {
+ this.values.push(value);
};
+
/*
* class EventValue
*
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js Sun Jan 6 17:19:29 2008
@@ -79,28 +79,27 @@
this.assertEquals(parser.value.isMethod, false);
this.assertEquals(parser.value.txt, 'b');
- // multiword ok
+ // XXX multiword in PropValue was supported by the token
+ // previously, but it really was never used.
+
+ // multiword is not allowed.
txt= "b c";
cursor = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValue(cursor, null, true);
- this.assertEquals(parser.finished, true);
- this.assertEquals(parser.value.isMethod, false);
- this.assertEquals(parser.value.txt, 'b c');
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [c] after the argument.')
+ // multiword is not allowed.
txt= " apples and oranges ;";
cursor = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValue(cursor, null, true);
- this.assertEquals(parser.finished, true);
- this.assertEquals(parser.value.isMethod, false);
- this.assertEquals(parser.value.txt, 'apples and oranges');
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [and] after the argument.')
+ // multiword is not allowed.
txt= " /* comments; */ apples and /* more comments and*/ oranges ;";
cursor = new kukit.tk.Cursor(txt);
- parser = new kukit.kssp.PropValue(cursor, null, true);
- this.assertEquals(parser.finished, true);
- this.assertEquals(parser.value.isMethod, false);
- this.assertEquals(parser.value.txt, 'apples and oranges');
-
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [and] after the argument.')
+
// params ok
txt= "formVar(x, y) ";
cursor = new kukit.tk.Cursor(txt);
@@ -131,17 +130,168 @@
txt= " a formVar(x, y)";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
- 'Wrong value : method name [a formVar] cannot have spaces.', 16);
+ 'Wrong value : unallowed characters [formVar] after the argument.')
txt= " 'formVar'(x, y)";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
- 'Wrong value : unallowed characters after the property', 16);
+ 'Wrong value : unallowed characters [(] after the argument.')
txt= "formVar(x, y) xxx";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
- 'Wrong value : unallowed characters after the property', 17);
+ 'Wrong value : unallowed characters [xxx] after the argument.')
+ };
+
+ this.testPropValueNoParam = function() {
+ // no parameters ok in a provider.
+ var txt= "formVar()";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.PropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.isMethod, true);
+ this.assertEquals(parser.value.methodName, 'formVar');
+ this.assertListEquals(parser.value.args, []);
+ };
+
+ this.testPropValueNoMethodName = function() {
+ var txt= " (x, y)";
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : empty method name.');
+ };
+
+ this.testMultiPropValueSingleWord = function() {
+ // Multi prop value with single word
+ var txt= "b";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 1);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'b');
+ };
+
+ this.testMultiPropValueMultiWord = function() {
+ // Multi prop value with multi word.
+ var txt= "b c";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 2);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'b');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'c');
+ };
+
+ this.testMultiPropValueMultiWord2 = function() {
+ // Multi prop value with multi word.
+ var txt= " apples and oranges ;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueMultiWord2 = function() {
+ // Multi prop value with multi word and comments.
+ var txt= " /* comments; */ apples and /* more comments and*/ oranges ;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+
+ this.testMultiPropValueStringAndWord = function() {
+ // Multi prop value with string and word.
+ var txt= "'apples' and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueWordAndString = function() {
+ // Multi prop value with string and word.
+ var txt= "'apples' and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueWordAndProvider = function() {
+ // Multi prop value with word and provider and word.
+ var txt= "apples formVar(x, y) oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, true);
+ this.assertEquals(parser.values[1].methodName, 'formVar');
+ this.assertListEquals(parser.values[1].args, ['x', 'y']);
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueProviderAndWord = function() {
+ // Multi prop value with provider and word.
+ var txt= "formVar(x, y) and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, true);
+ this.assertEquals(parser.values[0].methodName, 'formVar');
+ this.assertListEquals(parser.values[0].args, ['x', 'y']);
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueMethodArgsWithSpace = function() {
+ // Multi prop value with space after the provider name.
+ var txt= "formVar (x, y) and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, true);
+ this.assertEquals(parser.values[0].methodName, 'formVar');
+ this.assertListEquals(parser.values[0].args, ['x', 'y']);
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
};
this.testEventValueSimple = function() {
@@ -270,6 +420,15 @@
};
+ this.testMethodArgsNoParam = function() {
+ // Parsing method args with no parameters
+ txt= "()";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, []);
+ };
+
this.testMethodArgsRecursive = function() {
var txt= "(a, b(c, d))";
var cursor = new kukit.tk.Cursor(txt);
@@ -739,6 +898,9 @@
// We do not check the actual evaluation here, as we
// have no DOM at hand.
//
+ // We also check how these providers can be combined
+ // on one line.
+ //
// This testcase is added in DEVELOPMENT MODE ONLY.
this.testNormalProviderAcceptsString = function() {
@@ -964,6 +1126,23 @@
'Expected string or a formquery result and got [selection] in the kss action parameter [kssSubmitForm]., at row 1, column 11');
};
+ this.testCombinedClientAction = function() {
+ // Client action accepts a list of combined providers.
+ // (it will evaluate as form(xxx), but we can't check that without a dom)
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "nodeAttr('id')";
+ var txt= "#id:click {\n"
+ + " action-client: htmlid(id) doIt;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+
};
kukit.KssParserValueProvidersCheckTestCase.prototype = new kukit.KssParserTestCaseBase;
More information about the Kukit-checkins
mailing list